Professional Documents
Culture Documents
Alan L. Cox
alc@rice.edu
int
Output a file named main.s
main(void) containing the assembly
{ code for main.c
hello(“Alan", 2, 55);
return (0);
}
Implementation
Defines how a computer does it
Sequence of steps to complete operations
Time to execute each operation
Hidden “bookkeeping” functions
ISA Implementations
Intel Core i7
x86-64 AMD FX-83XX
VIA Nano
Apple A6/A6X
ARMv7-A
Qualcomm Krait
Longevity
20-30 years of ISA
x86/x86-64 in 10th generation of implementations
(architecture families)
Retain software investment
Amortize development costs over multiple markets
PC PC
Mem Mem
Regs Regs
Data types
Operations
Before State After State
Machine state
Memory organization
Register organization
CPU
General-
Purpose ALU,
Registers FPU, Memory
…
Special-Purpose
Registers
source
%esi %si index
destination
%edi %di index
stack
%esp %sp
pointer
base
%ebp %bp
pointer
movl (%ecx),%eax
movl 8(%ebp),%edx
popl %ebx
popl %ebp Finish
ret
popl %ebx
popl %ebp Finish
ret
Special Cases
(Rb,Ri) Mem[Reg[Rb]+Reg[Ri]]
D(Rb,Ri) Mem[Reg[Rb]+Reg[Ri]+D]
(Rb,Ri,S) Mem[Reg[Rb]+S*Reg[Ri]]
New instructions:
movl ➙ movq
addl ➙ addq
sall ➙ salq
etc.
popl %ebx
popl %ebp Finish
ret
Assembly 35
64-bit code for long int swap
swap_l:
void Set
swap(long *xp, long *yp) Up
{ movq (%rdi), %rdx
long t0 = *xp; movq (%rsi), %rax
long t1 = *yp; movq %rax, (%rdi) Body
movq %rdx, (%rsi)
*xp = t1;
*yp = t0;
} ret Finish
64-bit data
Data held in registers %rax and %rdx
movq operation
• “q” stands for quad-word
Unused
0x000000000000
Caller Callee
1. Save function arguments
2. Branch to function body
3. Execute body
• May allocate memory
• May call functions
4. Save function result
5. Branch to where called
1.
4.
5.
3.
2. Use registers
%rax
ret
sub (jump
call%rsp to to
create
%rdi, procedure,
newetc.,
%rsi, stack
save
then
frame
return
stack location on stack)
Figure 3.3 is reproduced from the AMD64 ABI Draft 0.99.5 by Matz et al.
Program Linking