assembly

How do I compile assembly routines for use with a C program (GNU assembler)?

Hello! I have a set of assembly function which I want to use in C programs by creating a header file. For instance, if I have asm_functions.s which defines the actual assembly routines and asm_functions.h which has prototypes for the functions as well as some standard #define's I needed. My goal is to use a C program, say test_asm.c to ...

How to do a call far (x86) to a given 32-bit address?

Ok, I need to perform a CALL FAR to the PCI BIOS service directory (32 bit mode) to verify that the PCI BIOS is present. NOTE: I am developing a simple disk driver for a simple operating system we are developing a college. I understand that this is very specific, but I will be doing all this from kernel code. Suppose I already found th...

Terminology: "registers" in assembly language programming

I've heard the terminologies: register, hardware register, program register,register file. What's the difference between all these? And in assebmly, what is the type of the EAX register? Program register? ...

How do I refer to a global variable in a dynamically linked library?

The environment is Solaris on 32bit SPARC, but I think this is a more general issue with dynamic linking and/or position independent code. I have an assembly program that I compile as position independent code and dynamically link to it from a C program. It works fine, except that I can't refer to any memory reserved by the assembly pro...

What's the difference between a Continuation (as in Smalltalk) and an interrupt (as in an Assembler)?

I'm struggling to understand the concept of Continuations (as used in Seaside with Smalltalk). A snippet from Wikipedia says: "... refer to first-class continuations, which are constructs that give a programming language the ability to save the execution state at any point and return to that point at a later point in the program..."...

inline assembly error

I am using inline assembly for iphone, I working for device debug mode. The instruction is as follows: __asm__("smlatb %0, %1, %2 ,%3 \n\t": "=r"(Temp): "r"(treg5) : "r"(fac5) : "r"(Temp) ); And I am getting an errors: error : expected ')' before tokedn '(' error: unknown register name 'r' in 'asm' I am using X-code 3.0 and...

Understanding empty main()'s translation into assembly

Hi, Could somebody please explain what GCC is doing for this piece of code? What is it initializing? The original code is: #include <stdio.h> int main() { } And it was translated to: .file "test1.c" .def ___main; .scl 2; .type 32; .endef .text .globl _main .def _main; .scl 2; .type 32; .endef _main: pushl %ebp ...

Storing values in HI and LO registers of MIPS

Hello, I am writing certain code in MIPS and I've come to the point where the requirement is to store the result, temporarily, in HI and LO special registers (both are 8 bytes wide). These instructions are at my disposal: divu s,t lo <-- s div t ; hi <-- s mod t multu s,t hi / lo < -- s * t ; So, divu stores result of divisi...

Bank switching in PIC assembler

I'm getting confused by bank switching in PIC assembler... This works for putting a 'Q' on the usart: bsf PORTB,1 ;Set Transmit DIR (PORTB (0x6) not mirrored in other banks) movlw 'Q' ;'Q' to work reg movwf TXREG ;work reg to TXREG (TXREG (0x19) not mirrored in other banks) clrwdt ;Clear watchdog b...

How do we shift from protected mode to real mode in Linux 2.6?

How do we shift from protected mode to real mode in Linux 2.6? ...

How to change processor stack?

Why doesn't this code print "test"? #include <stdio.h> #include <stdlib.h> void foo ( void ) { printf("test\n"); } __declspec(naked) void bar ( void ) { asm { push 0x000FFFFF call malloc pop ecx push eax add eax, 0x000EFFFF mov ecx, esp mov esp, eax push ecx call foo ...

Why do Off-the-shelf applications work on both Intel and AMD processors?

One thing I lack understanding on is how can code compiled for an Intel CPU work on an AMD CPU. My base understanding is that if you compile C code, for example, the compiler turns the source code into machine language which will have instructions for a particular processor. So, you need to compile with a compiler for whatever platform ...

How do I convert a decimal number to REAL10 in MASM assembly?

Right now I convert the string containing the decimal number to an integer (ignoring the radix point for now), load it into ST(0), and divide by the correct power of ten to account for the radix point. This seems round about, and requires I have a look up table for some of the powers of 10. Is there a better way to do this? ...

xchg example for 64 bit integer

I am using Xchg in i686 architecture for 32 bit compare and swap as follows. static int CAS(int *ptr, int oldVal, int newVal) { unsigned char ret; __asm__ __volatile__ ( " lock\n" " cmpxchgl %2,%1\n" " sete %0\n" : "=q" (ret), "=m" (*ptr) : "r" (newVal), "m" (*ptr), ...

Basic yet thorough assembly tutorial (linux)?

I want to learn some practical assembly language having just learned the basic concepts in class. Are there any decent books or tutorials (nasm, etc) that would be recommended? ...

How does c++ by-ref argument passing is compiled in assembly?

In the late years of college, I had a course on Compilers. We created a compiler for a subset of C. I have always wondered how a pass-by-ref function call is compiled into assembly in C++. For what I remember, a pass-by-val function call follows the following procedure: Store the address of the PP Push the arguments onto the stack Per...

Sources to learn more hardware centered programming

I'm looking to learn how to build/program simple hardware and later move on to simple robotics. Where should I begin? What are the best sites to buy the hardware? Any recommendations on the type of hardware/language I should use to start? ...

How can I see the Assembly code for a C++ Program ?

How can I see the Assembly code for a C++ Program ? What are the popular tools to do this ? ...

Real Mode, Interrupt vector replacement Crashing

I'm trying to learn more about how systems really work underneath all the pretty graphics on top. So I'm currently playing with memory in the 512bytes that the BIOS loads on startup, can't really call it a bootloader at the moment I guess. Anyway, I'm replacing an interrupt vector but having issues with it. After replacing interupt 09h (...

Count bits in the number.

Duplicate: Best algorithm to count the number of set bits in a 32-bit integer? Suppose you have a number. Is there any way to count the bits which equals to 1 in binary representation of that number, not using iteration? I mean, is there any way to do it in constant time using some bitwise operators and masks. I need solution whi...