
CS485G Spring 2015 11
4. The microarchitecture describes how the architecture is implemented.
It includes the sizes of caches and the frequency at which the ma-
chine operates. It is not important for programming in assembler.
5. Components of importance to the assembler programmer
(a) Program counter (PC): a register containing the address of the
next instruction. Called EIP (x86) or RIP (x86 64)
(b) Registers, used for heavily-accessed data, with names specific
to the architecture. The set of all registers is sometimes called
the register file.
(c) Condition codes store information about the most recent arith-
metic operation, such as “greater than zero”, useful for condi-
tional branch instructions.
(d) Memory, addressed by bytes, containing code (also called “text”
in Unix), data, and a stack (to support procedures).
15 Steps in converting C to object code
1. Say the code is in two files: p1.c and p2.c
2. To compile: gcc p1.c p2.c -o p, which puts the compiled pro-
gram in a file called p.
3. The gcc compiler first creates assembler files (stored in /tmp, but
we can imagine they are called p1.s and p2.s).
4. It then runs the as assembler on those files, creating p1.o and p2.o.
5. It then runs the ld linker to combine those files with libraries (pri-
marily the C library libc) to create an executable file p. Libraries
provide code for malloc, printf, and others.
6. Some libraries are dynamically linked when the program starts to ex-
ecute, saving space in the executable file and allowing the operating
system to share code among processes.
7. Sample code:
1 int sum(int x, int y)
2 {
3 int t = x+y;
4 return t;
5 }
Kommentare zu diesen Handbüchern