CS 412/413
Introduction to Compilers

Supporting Material for the Code Generation Assignment

Example programs

Calling conventions

Pentium Instruction Set Architecture

GNU Assembler

AT&T versus Intel Syntax

  AT&T Intel
Order of operands op a,b  means  b = a op b 
(second operand is destination)
op a, b   means  a = a op b
(first operand is destination)
Memory addressing disp(base, offset, scale) [base + offset*scale + disp]
Size of memory operands instruction suffixes (b,w,l)
(e.g., movb, movw, movl)
operand prefixes
(e.g., byte ptr, word ptr, dword ptr)
Registers %eax, %ebx, etc. eax, ebx, etc.
Constants $4, $foo, etc 4, foo, etc

Assembling and linking commands

In Windows under the Cygwin environment, the assembling and linking commands for an assembly file "file.s" are:

as -o file.o file.s
ld -o file.exe file.o /lib/crt0.o libic.a -lcygwin -lkernel32

The library file libic.a for Windows/Cygwin is a collection of .o files bundled together, containing the code for all of the library functions defined in the language specification, along with run-time support for garbage collection. 

The IC library is also available for Linux: libic.linux.a. The assembling and linking commands for "file.s" in Linux are:

as -o file.o file.s
ld -o file file.o /usr/lib/crt1.o /usr/lib/crti.o libic.linux.a -lc /usr/lib/crtn.o -dynamic /lib/ld-linux.so.2