Chapter 6
Digital Design and Computer Architecture, 2nd Edition
David Money Harris and Sarah L. Harris
Chapter 6 <1>
How to Compile & Run a Program
High Level Code
Compiler
Assembly Code
Assembler
Object Files
Object File
Library Files
Linker
Executable
Loader
Memory
David Money Harris and Sarah L. Harris, Digital Design and Computer Architecture, Second Edition, 2012
Chapter 6 <2>
Example Program: MIPS Assembly
.data High Level Code
int f, g, y; // global
f:
Compiler
g:
y: Assembly Code
int main(void)
.text
{ Assembler
main:
addi $sp, $sp, -4 # stack frame Object File
Object Files
Library Files
sw $ra, 0($sp) # store $ra
f = 2; addi $a0, $0, 2 # $a0 = 2 Linker
g = 3; sw $a0, f # f = 2 Executable
addi $a1, $0, 3 # $a1 = 3
y = sum(f, g); sw $a1, g # g = 3 Loader
return y; jal sum # call sum Memory
} sw $v0, y # y = sum()
lw $ra, 0($sp) # restore $ra
int sum(int a, int b) { addi $sp, $sp, 4 # restore $sp
return (a + b); jr $ra # return to OS
} sum:
add $v0, $a0, $a1 # $v0 = a + b
jr $ra # return
David Money Harris and Sarah L. Harris, Digital Design and Computer Architecture, Second Edition, 2012
Chapter 6 <3>
Example Program: Symbol Table
High Level Code
Compiler
Assembly Code
Assembler
Object Files
Object File
Library Files
Linker
Executable
Loader
Memory
David Money Harris and Sarah L. Harris, Digital Design and Computer Architecture, Second Edition, 2012
Chapter 6 <4>
Example Program: Executable
High Level Code
Compiler
Assembly Code
Assembler
Object Files
Object File
Library Files
Linker
Executable
Loader
Memory
David Money Harris and Sarah L. Harris, Digital Design and Computer Architecture, Second Edition, 2012
Chapter 6 <5>
Example Program: In Memory
High Level Code
Compiler
Assembly Code
Assembler
Object Files
Object File
Library Files
Linker
Executable
Loader
Memory
David Money Harris and Sarah L. Harris, Digital Design and Computer Architecture, Second Edition, 2012
Chapter 6 <6>
What is Stored in Memory?
• Instructions (also called text)
• Data
– Global/static: allocated before program begins
– Dynamic: allocated within program
• How big is memory?
– At most 232 = 4 gigabytes (4 GB)
– From address 0x00000000 to 0xFFFFFFFF
David Money Harris and Sarah L. Harris, Digital Design and Computer Architecture, Second Edition, 2012
Chapter 6 <7>