Example programs
- Hello world:
hello.ic,hello.s- Fibonacci computation:
fib.ic,fib.s- Objects example:
objects.ic,objects.s
Calling conventions
- Function arguments pushed on stack in reverse order
- Return value stored in
eaxregister (not on stack)- Caller-saved registers:
eax, ecx, edx- Callee-saved registers:
ebx, esi, edi, ebp, esp
Pentium Instruction Set Architecture
- A quick description of the Pentium Instruction Set (taken from the
nasmassembler documentation; uses Intel syntax)
- Complete documentation: Intel Manuals page, which includes:
- Intel Architecture Optimizations Manual
- Intel Architecture Software Developer's Manual, Volume 1: Basic Architecture
- Intel Architecture Software Developer's Manual, Volume 2: Instruction Set Reference Manual
- Intel Architecture Software Developer's Manual, Volume 3: System Programming Guide
GNU Assembler
- 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,bmeansb = a op b
(second operand is destination)op a, bmeansa = 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,etc4, foo,etc
Assembling and linking commandsIn 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 -lkernel32The library file
libic.afor 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