(SDU Logo) Institut for Matematik og Datalogi
Syddansk Universitet Institut for Matematik og Datalogi

DM506

Project groups: click me

IJVM

Assembly Coding in Linux

Compilation can be done using gcc. If the given file has .s as extension it will taken as assembly code by gcc.
An executable file can be created by typing:
gcc hello_world.s
If successful, the command produces the executable file a.out. It may be usefull to have the program called something else, which can be achieved with the option -o:
gcc -o test_program hello_world.s
Now the executable is called test_program instead.
To compile a C program to assembly code you can use the option S:
gcc -S -o assembly_code.s hello_world.c

SPARC (p. 341ff)

The SPARC machine we have available is bach.imada.sdu.dk, so all programs must be assembled and executed on that. (use ssh bach.imada.sdu.dk to connect to it).

Links

SPARC Assembly Language Reference Manual

Intel Pentium (App. C)

All of the computers in the computer room in IMADA are Intel Pentium machines.
The assembly code must be written with AT&T syntax.

Function calls and registers

The registers ecx and edx (and in some way eax) is allowed to be manipulated by a called function (they are sometimes called "caller save registers"). This means that before you call any function, you must save the content of those registers yourself (pushing them to the stack before the arguments to the function is a easy solution). Remember to restore the resigers after the call. The register eax is also in this category, except that it is also the return value register. If you call a function with no return value of interest you have to save eax too.
The registers ebx, esi, edi and ebp (don't use ebp (or esp) for custom data, or you will most likely get crashes) are treated the other way around. If the called function wants to use them for it's own data, it must save the content (the registers are sometimes called "calee save registers"). So if you create a function yourself, and wants to use any of these registers, you have to save them at the start of the function, and restore them right before returning.
The examples i have made always saves and restores all registers, following the above "rules". To make programs run fast, this can be optimized.

Links

Example programs (update (30/1): terminology errors in the comments should be fixed)
Intel and AT&T Syntax
Intel Pentium Instruction Set Reference (Basic Architecture Overview)