Digital Design and Computer Architecture, 2: Edition
Digital Design and Computer Architecture, 2: Edition
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
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
David Money Harris and Sarah L. Harris, Digital Design and Computer Architecture, Second Edition, 2012
Chapter 6 <7>