Code Generation Material
Example Programs
- Hello world:
hello.ic
,hello.s
- Fibonacci computation:
fib.ic
,fib.s
- Objects example:
objects.ic
,objects.s
IC Calling conventions
- All function arguments pushed on stack in reverse order
- Return value stored in
%rax
register (not on stack) - Caller-saved registers:
%rax, %rcx, %rdx, %rdi, %rsi, %r8-%r11
- Callee-saved registers:
%rbx, %rbp, %rsp %r12-%r15
x86_64 Instruction Set Architecture
- Duane Bailey's summary of the x86_64 architecture
- Intel Architecture Software Developer's Manual
- Intel Architecture Optimization Manual
- x86-64 Machine-Level Programming
Other Tools
- GDB, the GNU debugger
- Documentation for the as assembler: Postscript, HTML (uses the AT&T syntax)
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,q) (e.g., movb , movw , movl , movq )
|
operand prefixes (e.g., byte ptr , word ptr , dword ptr , qword ptr )
|
Registers |
%rax , %rbx , etc.
|
rax , rbx , etc.
|
Constants |
$4 , $foo , etc.
|
4 , foo , etc.
|
Assembling and linking commands
To assemble and link the file "file.s
" on our Linux lab computers, use:
gcc -m64 -g -o file.exe file.s libic64.a
The -m64
flag turns on 64-bit mode. The -g
flag causes debugging info to be placed in the executable.
The library file libic64.a
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. You can download it here: libic64.a.gz
. You can also download the libic
source code if you are curious.