Assignment 5 - Resources

Tools

Cygwin --- "Linux-like" environment for windows
IMPORANT 1: We will test your assignment under this environment.
IMPORANT 2: Make sure that the binutils and gcc packages are included in your installation (if you download Cygwin these packages are not included by default).

MinGW --- Minimalist GNU for windows

Intel Manuals

Note that these manuals use the Intel syntax whereas we are using GAS (AT&T) syntax.
Differences between the two are listed here and also summarized below.

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

Intel® Architecture Software Developer's Manual, Volume 1: Basic Architecture (most relevant)
Intel® Architecture Software Developer's Manual, Volume 2: Instruction Set Reference Manual (also relelvant)
Intel® Architecture Software Developer's Manual, Volume 3: System Programming Guide (less relevant)
Intel Architecture Optimizations Manual (finished everything else, huh?)

Intel Instruction Summary (taken from NASM manual, Intel Syntax)

General Resources

GNU Assembler Manual

Assembler resources

Linux Assembly (useful for wintel users as well)

Programming From the Group Up Book (PDF)

Example IC programs

Note that these programs are optimized, and your generated code will look more cumbersome.

Calling conventions

Libraries

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 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

Working under Cygwin

Save this script to your disk

First, open a Cygwin console. Second, make sure that the current directory '.' is part of your working path. To check this, enter 'echo $PATH'. To add the current directory enter 'export PATH=$PATH:.'
Now you are ready to use the compile script. Just enter 'compile file' where file is the name of the .s file without the '.s' extension itself, e.g.:
compile hello
This results in hello.exe, which you can now execute by entering hello.
NOTE 1: There is a built-in program in cygwin called test so it is better to avoid writing programs with this name.
NOTE 2: In order to automate the entire compilation process itself - that is, compile, assemble, and then link, you need to remove the comments from the 'compile' script and edit the line with the export command that sets the value of the environment variable CLASSPATH (read the file itself to see an example).
If you edit this file, make sure to do it with an editor that does not use Windows newline characters (like notepad), otherwise you will have to run 'dos2unix compile' to fix it. Eclipse is one appropriate editor. Also, make sure that Eclipse stores your .class files in a separate directory from the source files. This is done by: (1) clicking on the project name in Eclipse and choosing Project > Properties, and (2) choosing Java Build Path > Source and changing the Default output folder to some folder, e.g., classes.