SlideShare a Scribd company logo
Instruction Set
Architectures: Talking to
the Machine
1
The Architecture Question
• How do we build computer from contemporary
silicon device technology that executes general-
purpose programs quickly, efficiently, and at
reasonable cost?
• i.e. How do we build the computer on your
desk.
2
In the beginning...
• Physical configuration specifies the computation
3
The Difference Engine ENIAC
The Stored Program Computer
• The program is data
• i.e., it is a sequence of numbers that machine interprets
• A very elegant idea
• The same technologies can store and manipulate
programs and data
• Programs can manipulate programs.
4
The Stored Program Computer
• A very simple model
• Several questions
• How are program
represented?
• How do we get
algorithms out of our
brains and into that
representation?
• How does the the
computer interpret a
program?
5
Processor IO
Memory
Data Program
Representing Programs
• We need some basic building blocks -- call them
“instructions”
• What does “execute a program” mean?
• What instructions do we need?
• What should instructions look like?
• Is it enough to just specify the instructions?
• How complex should an instruction be?
6
Program Execution
7
Instruction
Fetch
Instruction
Decode
Operand
Fetch
Execute
Result
Store
Next
Instruction
Read instruction from program storage (mem[PC])
Determine required actions and instruction size
Locate and obtain operand data
Compute result value
Deposit results in storage for later use
Determine successor instruction (i.e. compute next PC).
Usually this mean PC = PC + <instruction size in bytes>
• This is the algorithm for a stored-program
computer
• The Program Counter (PC) is the key
Motivating Code segments
• a = b + c;
• a = b + c + d;
• a = b & c;
• a = b + 4;
• a = b - (c * (d/2) - 4);
• if (a) b = c;
• if (a == 4) b = c;
• while (a != 0) a--;
• a = 0xDEADBEEF;
• a = foo[4];
• foo[4] = a;
• a = foo.bar;
• a = a + b + c + d +... +z;
• a = foo(b); -- next class
8
What instructions do we
need?
• Basic operations are a good choice.
• Motivated by the programs people write.
• Math: Add, subtract, multiply, bit-wise operations
• Control: branches, jumps, and function calls.
• Data access: Load and store.
• The exact set of operations depends on many,
many things
• Application domain, hardware trade-offs, performance,
power, complexity requirements.
• You will see these trade-offs first hand in the ISA project
and in 141L.
9
What should instructions look like?
• They will be numbers -- i.e., strings of bits
• It is easiest if they are all the same size, say 32
bits
• We can break up these bits into “fields” -- like members
in a class or struct.
• This sets some limits
• On the number of different instructions we can have
• On the range of values any field of the instruction can
specify
10
Is specifying the instructions sufficient?
• No! We also must what the instructions operate on.
• This is called the “Architectural State” of the
machine.
• Registers -- a few named data values that instructions can
operate on
• Memory -- a much larger array of bytes that is available for
storing values.
• How big is memory? 32 bits or 64 bits of addressing.
• 64 is the standard today for desktops and larger.
• 32 for phones and PDAs
• Possibly fewer for embedded processors
• We also need to specify semantics of function calls
• The “Stack Discipline,” “Calling convention,” or “Application
binary interface (ABI)”.
11
How complex should instructions be?
• More complexity
• More different instruction types are required.
• Increased design and verification costs
• More complex hardware.
• More difficult to use -- What’s the right instruction in this context?
• Less complexity
• Programs will require more instructions -- poor code density
• Programs can be more difficult for humans to understand
• In the limit, decremement-and-branch-if-negative is sufficient
• Imagine trying to decipher programs written using just one
instruction.
• It takes many, many of these instructions to emulate simple
operations.
• Today, what matters most is the compiler
• The Machine must be able to understand program
• A program must be able to decide which instructions to use
12
Big “A” Architecture
• The Architecture is a contract between the
hardware and the software.
• The hardware defines a set of operations, their
semantics, and rules for their use.
• The software agrees to follow these rules.
• The hardware can implement those rules IN ANYWAY IT
CHOOSES!
• Directly in hardware
• Via a software layer
• Via a trained monkey with a pen and paper.
• This is a classic interface -- they are everywhere
in computer science.
• “Interface,” “Separation of concerns,” “API,” “Standard,”
• For your project you are designing an
Architecture -- not a processor.
13
From Brain to Bits
14
Your brain
Programming
Language (C, C++, Java)
Brain/
Fingers/
SWE
Compiler
Assembly language
Machine code
(i.e., .o files)
Assembler
Executable
(i.e., .exe files)
Linker
C Code
15
int i;
int sum = 0;
int j = 4;
for(i = 0; i < 10; i++) {
sum = i * j + sum;
}
In the Compiler
16
Function
decl: i decl: sum = 0 decl: j = 4 Loop
init: i = 0 test: i < 10 inc: i++ Body
statement: =
lhs: sum rhs: expr
sum *
+
j i
In the Compiler
17
sum = 0
j = 4
i = 0
t1 = i * j
sum = sum + t1
i++;
...
i < 10?
false true
Control flow graph
w/high-level
instructions
addi $s0, $zero, 0
addi $s1, $zero, 4
addi $s2, $zero, 0
mult $t0, $s1, $s2
add $s0, $t0
addi $s2, $s2, 1
...
addi $t0, $zero, 10
bge $s2, $t0
true false
Control flow graph
w/real instructions
Out of the Compiler
18
addi $s0, $zero, 0
addi $s1, $zero, 4
addi $s2, $zero, 0
top:
addi $t0, $zero, 10
bge $s2, $t0, after
body:
mult $t0, $s1, $s2
add $s0, $t0
addi $s2, $s2, 1
br top
after:
...
addi $s0, $zero, 0
addi $s1, $zero, 4
addi $s2, $zero, 0
mult $t0, $s1, $s2
add $s0, $t0
addi $s2, $s2, 1
...
addi $t0, $zero, 10
bge $s2, $t0
true false
Assembly language
Labels in the Assembler
19
addi $s0, $zero, 0
addi $s1, $zero, 4
addi $s2, $zero, 0
top:
addi $t0, $zero, 10
bge $s2, $t0, after
mult $t0, $s1, $s2
add $s0, $t0
addi $s2, $s2, 1
br top
after:
...
‘after’ is defined at 0x20
used at 0x10
The value of the immediate for the branch
is 0x20-0x10 = 0x10
‘top’ is defined at 0x0C
used at 0x1C
The value of the immediate for the branch
is 0x0C-0x1C = 0xFFFF0 (i.e., -0x10)
Labels in the Assembler
19
addi $s0, $zero, 0
addi $s1, $zero, 4
addi $s2, $zero, 0
top:
addi $t0, $zero, 10
bge $s2, $t0, after
mult $t0, $s1, $s2
add $s0, $t0
addi $s2, $s2, 1
br top
after:
...
0x00
0x04
0x08
0x0C
0x10
0x14
0x18
0x1C
0x20
‘after’ is defined at 0x20
used at 0x10
The value of the immediate for the branch
is 0x20-0x10 = 0x10
‘top’ is defined at 0x0C
used at 0x1C
The value of the immediate for the branch
is 0x0C-0x1C = 0xFFFF0 (i.e., -0x10)
Assembly Language
20
• “Text section”
• Hold assembly language instructions
• In practice, there can be many of these.
• “Data section”
• Contain definitions for static data.
• It can contain labels as well.
• The addresses in the data section have no
relation to the addresses in the data section.
• Pseudo instructions
• Convenient shorthand for longer instruction sequences.
.data and pseudo instructions
21
void foo() {
static int a = 0;
a++;
...
}
.data
foo_a:
.word 0
.text
foo:
lda $t0, foo_a
ld $s0, 0($t0)
addi $s0, $s0, 1
st $s0, 0($t0)
after:
...
.data and pseudo instructions
21
void foo() {
static int a = 0;
a++;
...
}
.data
foo_a:
.word 0
.text
foo:
lda $t0, foo_a
ld $s0, 0($t0)
addi $s0, $s0, 1
st $s0, 0($t0)
after:
...
lda $t0, foo_a
becomes these instructions (this is not assembly language!)
andi $t0, $zero, ((foo_a & 0xff00) >> 16)
sll $t0, $t0, 16
andi $t0, $t0, (foo_a & 0xff)
.data and pseudo instructions
21
void foo() {
static int a = 0;
a++;
...
}
.data
foo_a:
.word 0
.text
foo:
lda $t0, foo_a
ld $s0, 0($t0)
addi $s0, $s0, 1
st $s0, 0($t0)
after:
...
lda $t0, foo_a
becomes these instructions (this is not assembly language!)
andi $t0, $zero, ((foo_a & 0xff00) >> 16)
sll $t0, $t0, 16
andi $t0, $t0, (foo_a & 0xff)
The assembler computes and inserts these values.
.data and pseudo instructions
21
void foo() {
static int a = 0;
a++;
...
}
.data
foo_a:
.word 0
.text
foo:
lda $t0, foo_a
ld $s0, 0($t0)
addi $s0, $s0, 1
st $s0, 0($t0)
after:
...
lda $t0, foo_a
becomes these instructions (this is not assembly language!)
andi $t0, $zero, ((foo_a & 0xff00) >> 16)
sll $t0, $t0, 16
andi $t0, $t0, (foo_a & 0xff)
If foo is address 0x0,
where is after?
The assembler computes and inserts these values.
.data and pseudo instructions
21
void foo() {
static int a = 0;
a++;
...
}
.data
foo_a:
.word 0
.text
foo:
lda $t0, foo_a
ld $s0, 0($t0)
addi $s0, $s0, 1
st $s0, 0($t0)
after:
...
lda $t0, foo_a
becomes these instructions (this is not assembly language!)
andi $t0, $zero, ((foo_a & 0xff00) >> 16)
sll $t0, $t0, 16
andi $t0, $t0, (foo_a & 0xff)
If foo is address 0x0,
where is after?
0x00
0x0C
0x10
0x14
0x18
The assembler computes and inserts these values.
ISA Alternatives
• MIPS is a 3-address, RISC ISA
• add rs, rt, rd -- 3 operands
• RISC -- reduced instruction set. Relatively small number
of operation. Very regular encoding. RISC is the “right”
way to build ISAs.
• 2-address
• add r1, r2 --> r1 = r1 + r2
• + few operands, so more bits for each.
• - lots of extra copy instructions
• 1-address
• Accumulator architectures
• add r1 -> acc = acc + rI
22
Stack-based ISA
• A push-down stack holds arguments
• Some instruction manipulate the stack
• push, pop, swap, etc.
• Most instructions operate on the contents of the
stack
• Zero-operand instructions
• add --> t1 = pop; t2 = pop; push t1 + t2;
• Elegant in theory.
• Clumsy in hardware.
• How big is the stack?
• Java byte code is a stack-based ISA
• So is the x86 floating point ISA
23
24
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
X
Y
B
C
A
SP
+4
+8
+12
+16•
•
•
0x1000
Memory
Base ptr (BP)
PC
24
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
Push 8(BP)
Push 12(BP)
Mult
Push 0(BP)
Push 4(BP)
Mult
Sub
Store 16(BP)
Pop
X
Y
B
C
A
SP
+4
+8
+12
+16•
•
•
0x1000
Memory
Base ptr (BP)
PC
25
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
X
Y
B
C
A
SP
+4
+8
+12
+16
C
•
•
•
0x1000
Memory
Base ptr (BP)
PC
25
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
Push 8(BP)
Push 12(BP)
Mult
Push 0(BP)
Push 4(BP)
Mult
Sub
Store 16(BP)
Pop
X
Y
B
C
A
SP
+4
+8
+12
+16
C
•
•
•
0x1000
Memory
Base ptr (BP)
PC
26
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
X
Y
B
C
A
SP
+4
+8
+12
+16
C
B
•
•
•
0x1000
Memory
Base ptr (BP)
PC
26
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
Push 8(BP)
Push 12(BP)
Mult
Push 0(BP)
Push 4(BP)
Mult
Sub
Store 16(BP)
Pop
X
Y
B
C
A
SP
+4
+8
+12
+16
C
B
•
•
•
0x1000
Memory
Base ptr (BP)
PC
27
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
X
Y
B
C
A
SP
+4
+8
+12
+16
B*C
•
•
•
0x1000
Memory
Base ptr (BP)
PC
27
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
Push 8(BP)
Push 12(BP)
Mult
Push 0(BP)
Push 4(BP)
Mult
Sub
Store 16(BP)
Pop
X
Y
B
C
A
SP
+4
+8
+12
+16
B*C
•
•
•
0x1000
Memory
Base ptr (BP)
PC
28
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
X
Y
B
C
A
SP
+4
+8
+12
+16
B*C
Y
•
•
•
0x1000
Memory
Base ptr (BP)
PC
28
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
Push 8(BP)
Push 12(BP)
Mult
Push 0(BP)
Push 4(BP)
Mult
Sub
Store 16(BP)
Pop
X
Y
B
C
A
SP
+4
+8
+12
+16
B*C
Y
•
•
•
0x1000
Memory
Base ptr (BP)
PC
29
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
X
Y
B
C
A
SP
+4
+8
+12
+16
X
B*C
Y
•
•
•
0x1000
Memory
Base ptr (BP)
PC
29
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
Push 8(BP)
Push 12(BP)
Mult
Push 0(BP)
Push 4(BP)
Mult
Sub
Store 16(BP)
Pop
X
Y
B
C
A
SP
+4
+8
+12
+16
X
B*C
Y
•
•
•
0x1000
Memory
Base ptr (BP)
PC
30
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
- Store -- Store the top of the stack
X
Y
B
C
A
SP
+4
+8
+12
+16
B*C
X*Y
•
•
•
0x1000
Memory
Base ptr (BP)
PC
30
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
- Store -- Store the top of the stack
Push 8(BP)
Push 12(BP)
Mult
Push 0(BP)
Push 4(BP)
Mult
Sub
Store 16(BP)
Pop
X
Y
B
C
A
SP
+4
+8
+12
+16
B*C
X*Y
•
•
•
0x1000
Memory
Base ptr (BP)
PC
31
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
X
Y
B
C
A
SP
+4
+8
+12
+16
X*Y-B*C
•
•
•
0x1000
Memory
Base ptr (BP)
PC
31
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
Push 8(BP)
Push 12(BP)
Mult
Push 0(BP)
Push 4(BP)
Mult
Sub
Store 16(BP)
Pop
X
Y
B
C
A
SP
+4
+8
+12
+16
X*Y-B*C
•
•
•
0x1000
Memory
Base ptr (BP)
PC
32
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
- Store -- Store the top of the stack
X
Y
B
C
A
SP
+4
+8
+12
+16
X*Y-B*C
•
•
•
0x1000
Memory
Base ptr (BP)
PC
32
compute A = X *Y - B * C
• Stack-based ISA
- Processor state: PC, “operand stack”, “Base ptr”
- Push -- Put something from memory onto the stack
- Pop -- take something off the top of the stack
- +, -, *,… -- Replace top two values with the result
- Store -- Store the top of the stack
Push 8(BP)
Push 12(BP)
Mult
Push 0(BP)
Push 4(BP)
Mult
Sub
Store 16(BP)
Pop
X
Y
B
C
A
SP
+4
+8
+12
+16
X*Y-B*C
•
•
•
0x1000
Memory
Base ptr (BP)
PC
• Functions are an essential feature of modern
languages
• What does a function need?
• Arguments.
• Storage for local variables.
• To return control to the the caller.
• To execute regardless of who called it.
• To call other functions (that call other functions...that
call other functions)
• There are not instructions for this
• It is a contract about how the function behaves
• In particular, how it treats the resources that are shared
between functions -- the registers and memory
33
Supporting Function Calls
Register Discipline
• All registers are the
same, but we assign
them different uses.
34
Name number use saved?
$zero 0 zero n/a
$v0-$v1 2-3 return value no
$a0-$a3 4-7 arguments no
$t0-$t7 8-15 temporaries no
$s0-$7 26-23 saved yes
$t8-$t9 24-25 temporaries no
$gp 26 global ptr yes
$sp 29 stack ptr yes
$fp 30 frame ptr yes
$ra 31 return address yes
Arguments
• How many arguments can
function have?
• unbounded.
• But most functions have just a
few.
• Make the common case fast
• Put the first 4 argument in
registers ($a0-$a3).
• Put the rest on the “stack”
35
int Foo(int a, int b, int c, int d, int e) {
...
}
a$a0
b$a1
c$a2
d$a3
0x1DEA$sp
e0x1DEA
Stack (in memory)Register file
Storage for LocalVariables
• Local variables
go on the stack
too.
36
int Foo(int a, int b, int c, int d, int e) {
int bar[4];
...
}
a$a0
b$a1
c$a2
d$a3
0 x1D EA
$sp
e0 x1D EA
Stack (in memory)Register file
bar[3 ]
0 x1D EA + 16
$fp
bar[2 ]
bar[1]
bar[0 ]
Returning Control
37
int Foo(int a, ...) {
int bar[4];
...
return bar[0];
}
...
move $a0, $t1
move $a1, $s4
move $a2, $s3
move $a3, $s3
sw $t2, 0($sp)
subi $sp, $sp, 4
jal Foo0xBAD0:
Caller
Callee
...
subi $sp, $sp, 16 // Allocate bar
...
lw $v0, 0($sp)
addi $sp, $sp, 16 // deallocate bar
jr $ra // return
a$a0
b$a1
c$a2
d$a3
0x1DEA
$sp
e0x1DEA
Stack (in memory)
Register file
bar[3]
0x1DEA + 16
$fp
bar[2]
bar[1]
bar[0]
bar[0]$v0
0xBAD4$ra
Saving Registers
• Some registers are preserved across function calls
• If a function needs a value after the call, it uses one of these
• But it must also preserve the previous contents (so it can
honor its obligation to its caller)
• Push these registers onto the stack.
• See figure 2.12 in the text.
38

More Related Content

PPTX
Arrays and Lists in C#, Java, Python and JavaScript
PDF
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
PPTX
Cs1123 11 pointers
PPTX
Learn c++ Programming Language
PPTX
45 Days C++ Programming Language Training in Ambala
PPTX
C++ Programming Language Training in Ambala ! Batra Computer Centre
PPTX
Bitwise Operations in Programming
PPTX
C# overview part 1
Arrays and Lists in C#, Java, Python and JavaScript
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
Cs1123 11 pointers
Learn c++ Programming Language
45 Days C++ Programming Language Training in Ambala
C++ Programming Language Training in Ambala ! Batra Computer Centre
Bitwise Operations in Programming
C# overview part 1

What's hot (10)

PPS
T02 a firstcprogram
PDF
Xtreams
PPTX
Cs1123 3 c++ overview
PPTX
PPTX
C++ AND CATEGORIES OF SOFTWARE
PDF
Compiler Construction | Lecture 8 | Type Constraints
PDF
CS4200 2019 | Lecture 4 | Syntactic Services
PDF
CS4200 2019 | Lecture 3 | Parsing
PPTX
02. Primitive Data Types and Variables
PPTX
Programming using c++ tool
T02 a firstcprogram
Xtreams
Cs1123 3 c++ overview
C++ AND CATEGORIES OF SOFTWARE
Compiler Construction | Lecture 8 | Type Constraints
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 3 | Parsing
02. Primitive Data Types and Variables
Programming using c++ tool
Ad

Viewers also liked (14)

PPTX
Vivek Raju birthday
PDF
Seven secrets to success
PDF
Get started with dropbox
DOCX
RAJEEV RANJAN KUMAR RESUME
DOCX
Bill RoubalResume
DOC
Health Disparities Project
PPTX
DOC
The scenario of Bangladesh Minorities
DOCX
Raja S
PDF
Testing for slideshare
PDF
Презентация Электронная библиотека "МИФ"
PPT
城市裡的哲學家
PDF
Royalhighnessfellowshipbcsnet2
PDF
Intensitet
Vivek Raju birthday
Seven secrets to success
Get started with dropbox
RAJEEV RANJAN KUMAR RESUME
Bill RoubalResume
Health Disparities Project
The scenario of Bangladesh Minorities
Raja S
Testing for slideshare
Презентация Электронная библиотека "МИФ"
城市裡的哲學家
Royalhighnessfellowshipbcsnet2
Intensitet
Ad

Similar to 02 isa (20)

PDF
01 isa
PPT
IS 139 Lecture 6
PPTX
Introduction to Processor Design and ARM Processor
PPT
MIPS instruction set microprocessor lecture notes
PPTX
ITEC582-Chapter 12.pptx
PPT
ch 3_The CPU_modified.ppt of central processing unit
PPTX
Instruction Set Architecture
PPT
CO_Chapter2.ppt
PPT
Introduction to C programing for problem
PPTX
UNIT 3 - General Purpose Processors
PPT
Instruction Set Architecture
PPTX
digital principles and computer organization
PPTX
Unit 1 computer architecture (1)
PDF
Introduction to nand2 tetris
PPT
MCA-I-COA- overview of register transfer, micro operations and basic computer...
PPT
isa architecture
PDF
Unit 3 - Computer Organization .pdf
PPT
Org-&-Arch-2.ppt
PDF
System software 5th unit
PPTX
Introduction to Assembly Language
01 isa
IS 139 Lecture 6
Introduction to Processor Design and ARM Processor
MIPS instruction set microprocessor lecture notes
ITEC582-Chapter 12.pptx
ch 3_The CPU_modified.ppt of central processing unit
Instruction Set Architecture
CO_Chapter2.ppt
Introduction to C programing for problem
UNIT 3 - General Purpose Processors
Instruction Set Architecture
digital principles and computer organization
Unit 1 computer architecture (1)
Introduction to nand2 tetris
MCA-I-COA- overview of register transfer, micro operations and basic computer...
isa architecture
Unit 3 - Computer Organization .pdf
Org-&-Arch-2.ppt
System software 5th unit
Introduction to Assembly Language

More from marangburu42 (20)

DOCX
PDF
Write miss
DOCX
Hennchthree 161102111515
DOCX
Hennchthree
DOCX
Hennchthree
DOCX
Sequential circuits
DOCX
Combinational circuits
DOCX
Hennchthree 160912095304
DOCX
Sequential circuits
DOCX
Combinational circuits
DOCX
Karnaugh mapping allaboutcircuits
DOCX
Aac boolean formulae
DOCX
Virtualmemoryfinal 161019175858
DOCX
Io systems final
DOCX
File system interfacefinal
DOCX
File systemimplementationfinal
DOCX
Mass storage structurefinal
DOCX
All aboutcircuits karnaugh maps
DOCX
Virtual memoryfinal
DOCX
Mainmemoryfinal 161019122029
Write miss
Hennchthree 161102111515
Hennchthree
Hennchthree
Sequential circuits
Combinational circuits
Hennchthree 160912095304
Sequential circuits
Combinational circuits
Karnaugh mapping allaboutcircuits
Aac boolean formulae
Virtualmemoryfinal 161019175858
Io systems final
File system interfacefinal
File systemimplementationfinal
Mass storage structurefinal
All aboutcircuits karnaugh maps
Virtual memoryfinal
Mainmemoryfinal 161019122029

Recently uploaded (20)

PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Cell Structure & Organelles in detailed.
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
TR - Agricultural Crops Production NC III.pdf
Basic Mud Logging Guide for educational purpose
102 student loan defaulters named and shamed – Is someone you know on the list?
Open Quiz Monsoon Mind Game Final Set.pptx
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Anesthesia in Laparoscopic Surgery in India
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
O7-L3 Supply Chain Operations - ICLT Program
2.FourierTransform-ShortQuestionswithAnswers.pdf
01-Introduction-to-Information-Management.pdf
Cardiovascular Pharmacology for pharmacy students.pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Abdominal Access Techniques with Prof. Dr. R K Mishra
Cell Structure & Organelles in detailed.

02 isa

  • 2. The Architecture Question • How do we build computer from contemporary silicon device technology that executes general- purpose programs quickly, efficiently, and at reasonable cost? • i.e. How do we build the computer on your desk. 2
  • 3. In the beginning... • Physical configuration specifies the computation 3 The Difference Engine ENIAC
  • 4. The Stored Program Computer • The program is data • i.e., it is a sequence of numbers that machine interprets • A very elegant idea • The same technologies can store and manipulate programs and data • Programs can manipulate programs. 4
  • 5. The Stored Program Computer • A very simple model • Several questions • How are program represented? • How do we get algorithms out of our brains and into that representation? • How does the the computer interpret a program? 5 Processor IO Memory Data Program
  • 6. Representing Programs • We need some basic building blocks -- call them “instructions” • What does “execute a program” mean? • What instructions do we need? • What should instructions look like? • Is it enough to just specify the instructions? • How complex should an instruction be? 6
  • 7. Program Execution 7 Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction Read instruction from program storage (mem[PC]) Determine required actions and instruction size Locate and obtain operand data Compute result value Deposit results in storage for later use Determine successor instruction (i.e. compute next PC). Usually this mean PC = PC + <instruction size in bytes> • This is the algorithm for a stored-program computer • The Program Counter (PC) is the key
  • 8. Motivating Code segments • a = b + c; • a = b + c + d; • a = b & c; • a = b + 4; • a = b - (c * (d/2) - 4); • if (a) b = c; • if (a == 4) b = c; • while (a != 0) a--; • a = 0xDEADBEEF; • a = foo[4]; • foo[4] = a; • a = foo.bar; • a = a + b + c + d +... +z; • a = foo(b); -- next class 8
  • 9. What instructions do we need? • Basic operations are a good choice. • Motivated by the programs people write. • Math: Add, subtract, multiply, bit-wise operations • Control: branches, jumps, and function calls. • Data access: Load and store. • The exact set of operations depends on many, many things • Application domain, hardware trade-offs, performance, power, complexity requirements. • You will see these trade-offs first hand in the ISA project and in 141L. 9
  • 10. What should instructions look like? • They will be numbers -- i.e., strings of bits • It is easiest if they are all the same size, say 32 bits • We can break up these bits into “fields” -- like members in a class or struct. • This sets some limits • On the number of different instructions we can have • On the range of values any field of the instruction can specify 10
  • 11. Is specifying the instructions sufficient? • No! We also must what the instructions operate on. • This is called the “Architectural State” of the machine. • Registers -- a few named data values that instructions can operate on • Memory -- a much larger array of bytes that is available for storing values. • How big is memory? 32 bits or 64 bits of addressing. • 64 is the standard today for desktops and larger. • 32 for phones and PDAs • Possibly fewer for embedded processors • We also need to specify semantics of function calls • The “Stack Discipline,” “Calling convention,” or “Application binary interface (ABI)”. 11
  • 12. How complex should instructions be? • More complexity • More different instruction types are required. • Increased design and verification costs • More complex hardware. • More difficult to use -- What’s the right instruction in this context? • Less complexity • Programs will require more instructions -- poor code density • Programs can be more difficult for humans to understand • In the limit, decremement-and-branch-if-negative is sufficient • Imagine trying to decipher programs written using just one instruction. • It takes many, many of these instructions to emulate simple operations. • Today, what matters most is the compiler • The Machine must be able to understand program • A program must be able to decide which instructions to use 12
  • 13. Big “A” Architecture • The Architecture is a contract between the hardware and the software. • The hardware defines a set of operations, their semantics, and rules for their use. • The software agrees to follow these rules. • The hardware can implement those rules IN ANYWAY IT CHOOSES! • Directly in hardware • Via a software layer • Via a trained monkey with a pen and paper. • This is a classic interface -- they are everywhere in computer science. • “Interface,” “Separation of concerns,” “API,” “Standard,” • For your project you are designing an Architecture -- not a processor. 13
  • 14. From Brain to Bits 14 Your brain Programming Language (C, C++, Java) Brain/ Fingers/ SWE Compiler Assembly language Machine code (i.e., .o files) Assembler Executable (i.e., .exe files) Linker
  • 15. C Code 15 int i; int sum = 0; int j = 4; for(i = 0; i < 10; i++) { sum = i * j + sum; }
  • 16. In the Compiler 16 Function decl: i decl: sum = 0 decl: j = 4 Loop init: i = 0 test: i < 10 inc: i++ Body statement: = lhs: sum rhs: expr sum * + j i
  • 17. In the Compiler 17 sum = 0 j = 4 i = 0 t1 = i * j sum = sum + t1 i++; ... i < 10? false true Control flow graph w/high-level instructions addi $s0, $zero, 0 addi $s1, $zero, 4 addi $s2, $zero, 0 mult $t0, $s1, $s2 add $s0, $t0 addi $s2, $s2, 1 ... addi $t0, $zero, 10 bge $s2, $t0 true false Control flow graph w/real instructions
  • 18. Out of the Compiler 18 addi $s0, $zero, 0 addi $s1, $zero, 4 addi $s2, $zero, 0 top: addi $t0, $zero, 10 bge $s2, $t0, after body: mult $t0, $s1, $s2 add $s0, $t0 addi $s2, $s2, 1 br top after: ... addi $s0, $zero, 0 addi $s1, $zero, 4 addi $s2, $zero, 0 mult $t0, $s1, $s2 add $s0, $t0 addi $s2, $s2, 1 ... addi $t0, $zero, 10 bge $s2, $t0 true false Assembly language
  • 19. Labels in the Assembler 19 addi $s0, $zero, 0 addi $s1, $zero, 4 addi $s2, $zero, 0 top: addi $t0, $zero, 10 bge $s2, $t0, after mult $t0, $s1, $s2 add $s0, $t0 addi $s2, $s2, 1 br top after: ... ‘after’ is defined at 0x20 used at 0x10 The value of the immediate for the branch is 0x20-0x10 = 0x10 ‘top’ is defined at 0x0C used at 0x1C The value of the immediate for the branch is 0x0C-0x1C = 0xFFFF0 (i.e., -0x10)
  • 20. Labels in the Assembler 19 addi $s0, $zero, 0 addi $s1, $zero, 4 addi $s2, $zero, 0 top: addi $t0, $zero, 10 bge $s2, $t0, after mult $t0, $s1, $s2 add $s0, $t0 addi $s2, $s2, 1 br top after: ... 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C 0x20 ‘after’ is defined at 0x20 used at 0x10 The value of the immediate for the branch is 0x20-0x10 = 0x10 ‘top’ is defined at 0x0C used at 0x1C The value of the immediate for the branch is 0x0C-0x1C = 0xFFFF0 (i.e., -0x10)
  • 21. Assembly Language 20 • “Text section” • Hold assembly language instructions • In practice, there can be many of these. • “Data section” • Contain definitions for static data. • It can contain labels as well. • The addresses in the data section have no relation to the addresses in the data section. • Pseudo instructions • Convenient shorthand for longer instruction sequences.
  • 22. .data and pseudo instructions 21 void foo() { static int a = 0; a++; ... } .data foo_a: .word 0 .text foo: lda $t0, foo_a ld $s0, 0($t0) addi $s0, $s0, 1 st $s0, 0($t0) after: ...
  • 23. .data and pseudo instructions 21 void foo() { static int a = 0; a++; ... } .data foo_a: .word 0 .text foo: lda $t0, foo_a ld $s0, 0($t0) addi $s0, $s0, 1 st $s0, 0($t0) after: ... lda $t0, foo_a becomes these instructions (this is not assembly language!) andi $t0, $zero, ((foo_a & 0xff00) >> 16) sll $t0, $t0, 16 andi $t0, $t0, (foo_a & 0xff)
  • 24. .data and pseudo instructions 21 void foo() { static int a = 0; a++; ... } .data foo_a: .word 0 .text foo: lda $t0, foo_a ld $s0, 0($t0) addi $s0, $s0, 1 st $s0, 0($t0) after: ... lda $t0, foo_a becomes these instructions (this is not assembly language!) andi $t0, $zero, ((foo_a & 0xff00) >> 16) sll $t0, $t0, 16 andi $t0, $t0, (foo_a & 0xff) The assembler computes and inserts these values.
  • 25. .data and pseudo instructions 21 void foo() { static int a = 0; a++; ... } .data foo_a: .word 0 .text foo: lda $t0, foo_a ld $s0, 0($t0) addi $s0, $s0, 1 st $s0, 0($t0) after: ... lda $t0, foo_a becomes these instructions (this is not assembly language!) andi $t0, $zero, ((foo_a & 0xff00) >> 16) sll $t0, $t0, 16 andi $t0, $t0, (foo_a & 0xff) If foo is address 0x0, where is after? The assembler computes and inserts these values.
  • 26. .data and pseudo instructions 21 void foo() { static int a = 0; a++; ... } .data foo_a: .word 0 .text foo: lda $t0, foo_a ld $s0, 0($t0) addi $s0, $s0, 1 st $s0, 0($t0) after: ... lda $t0, foo_a becomes these instructions (this is not assembly language!) andi $t0, $zero, ((foo_a & 0xff00) >> 16) sll $t0, $t0, 16 andi $t0, $t0, (foo_a & 0xff) If foo is address 0x0, where is after? 0x00 0x0C 0x10 0x14 0x18 The assembler computes and inserts these values.
  • 27. ISA Alternatives • MIPS is a 3-address, RISC ISA • add rs, rt, rd -- 3 operands • RISC -- reduced instruction set. Relatively small number of operation. Very regular encoding. RISC is the “right” way to build ISAs. • 2-address • add r1, r2 --> r1 = r1 + r2 • + few operands, so more bits for each. • - lots of extra copy instructions • 1-address • Accumulator architectures • add r1 -> acc = acc + rI 22
  • 28. Stack-based ISA • A push-down stack holds arguments • Some instruction manipulate the stack • push, pop, swap, etc. • Most instructions operate on the contents of the stack • Zero-operand instructions • add --> t1 = pop; t2 = pop; push t1 + t2; • Elegant in theory. • Clumsy in hardware. • How big is the stack? • Java byte code is a stack-based ISA • So is the x86 floating point ISA 23
  • 29. 24 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result X Y B C A SP +4 +8 +12 +16• • • 0x1000 Memory Base ptr (BP) PC
  • 30. 24 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result Push 8(BP) Push 12(BP) Mult Push 0(BP) Push 4(BP) Mult Sub Store 16(BP) Pop X Y B C A SP +4 +8 +12 +16• • • 0x1000 Memory Base ptr (BP) PC
  • 31. 25 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result X Y B C A SP +4 +8 +12 +16 C • • • 0x1000 Memory Base ptr (BP) PC
  • 32. 25 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result Push 8(BP) Push 12(BP) Mult Push 0(BP) Push 4(BP) Mult Sub Store 16(BP) Pop X Y B C A SP +4 +8 +12 +16 C • • • 0x1000 Memory Base ptr (BP) PC
  • 33. 26 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result X Y B C A SP +4 +8 +12 +16 C B • • • 0x1000 Memory Base ptr (BP) PC
  • 34. 26 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result Push 8(BP) Push 12(BP) Mult Push 0(BP) Push 4(BP) Mult Sub Store 16(BP) Pop X Y B C A SP +4 +8 +12 +16 C B • • • 0x1000 Memory Base ptr (BP) PC
  • 35. 27 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result X Y B C A SP +4 +8 +12 +16 B*C • • • 0x1000 Memory Base ptr (BP) PC
  • 36. 27 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result Push 8(BP) Push 12(BP) Mult Push 0(BP) Push 4(BP) Mult Sub Store 16(BP) Pop X Y B C A SP +4 +8 +12 +16 B*C • • • 0x1000 Memory Base ptr (BP) PC
  • 37. 28 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result X Y B C A SP +4 +8 +12 +16 B*C Y • • • 0x1000 Memory Base ptr (BP) PC
  • 38. 28 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result Push 8(BP) Push 12(BP) Mult Push 0(BP) Push 4(BP) Mult Sub Store 16(BP) Pop X Y B C A SP +4 +8 +12 +16 B*C Y • • • 0x1000 Memory Base ptr (BP) PC
  • 39. 29 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result X Y B C A SP +4 +8 +12 +16 X B*C Y • • • 0x1000 Memory Base ptr (BP) PC
  • 40. 29 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result Push 8(BP) Push 12(BP) Mult Push 0(BP) Push 4(BP) Mult Sub Store 16(BP) Pop X Y B C A SP +4 +8 +12 +16 X B*C Y • • • 0x1000 Memory Base ptr (BP) PC
  • 41. 30 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result - Store -- Store the top of the stack X Y B C A SP +4 +8 +12 +16 B*C X*Y • • • 0x1000 Memory Base ptr (BP) PC
  • 42. 30 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result - Store -- Store the top of the stack Push 8(BP) Push 12(BP) Mult Push 0(BP) Push 4(BP) Mult Sub Store 16(BP) Pop X Y B C A SP +4 +8 +12 +16 B*C X*Y • • • 0x1000 Memory Base ptr (BP) PC
  • 43. 31 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result X Y B C A SP +4 +8 +12 +16 X*Y-B*C • • • 0x1000 Memory Base ptr (BP) PC
  • 44. 31 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result Push 8(BP) Push 12(BP) Mult Push 0(BP) Push 4(BP) Mult Sub Store 16(BP) Pop X Y B C A SP +4 +8 +12 +16 X*Y-B*C • • • 0x1000 Memory Base ptr (BP) PC
  • 45. 32 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result - Store -- Store the top of the stack X Y B C A SP +4 +8 +12 +16 X*Y-B*C • • • 0x1000 Memory Base ptr (BP) PC
  • 46. 32 compute A = X *Y - B * C • Stack-based ISA - Processor state: PC, “operand stack”, “Base ptr” - Push -- Put something from memory onto the stack - Pop -- take something off the top of the stack - +, -, *,… -- Replace top two values with the result - Store -- Store the top of the stack Push 8(BP) Push 12(BP) Mult Push 0(BP) Push 4(BP) Mult Sub Store 16(BP) Pop X Y B C A SP +4 +8 +12 +16 X*Y-B*C • • • 0x1000 Memory Base ptr (BP) PC
  • 47. • Functions are an essential feature of modern languages • What does a function need? • Arguments. • Storage for local variables. • To return control to the the caller. • To execute regardless of who called it. • To call other functions (that call other functions...that call other functions) • There are not instructions for this • It is a contract about how the function behaves • In particular, how it treats the resources that are shared between functions -- the registers and memory 33 Supporting Function Calls
  • 48. Register Discipline • All registers are the same, but we assign them different uses. 34 Name number use saved? $zero 0 zero n/a $v0-$v1 2-3 return value no $a0-$a3 4-7 arguments no $t0-$t7 8-15 temporaries no $s0-$7 26-23 saved yes $t8-$t9 24-25 temporaries no $gp 26 global ptr yes $sp 29 stack ptr yes $fp 30 frame ptr yes $ra 31 return address yes
  • 49. Arguments • How many arguments can function have? • unbounded. • But most functions have just a few. • Make the common case fast • Put the first 4 argument in registers ($a0-$a3). • Put the rest on the “stack” 35 int Foo(int a, int b, int c, int d, int e) { ... } a$a0 b$a1 c$a2 d$a3 0x1DEA$sp e0x1DEA Stack (in memory)Register file
  • 50. Storage for LocalVariables • Local variables go on the stack too. 36 int Foo(int a, int b, int c, int d, int e) { int bar[4]; ... } a$a0 b$a1 c$a2 d$a3 0 x1D EA $sp e0 x1D EA Stack (in memory)Register file bar[3 ] 0 x1D EA + 16 $fp bar[2 ] bar[1] bar[0 ]
  • 51. Returning Control 37 int Foo(int a, ...) { int bar[4]; ... return bar[0]; } ... move $a0, $t1 move $a1, $s4 move $a2, $s3 move $a3, $s3 sw $t2, 0($sp) subi $sp, $sp, 4 jal Foo0xBAD0: Caller Callee ... subi $sp, $sp, 16 // Allocate bar ... lw $v0, 0($sp) addi $sp, $sp, 16 // deallocate bar jr $ra // return a$a0 b$a1 c$a2 d$a3 0x1DEA $sp e0x1DEA Stack (in memory) Register file bar[3] 0x1DEA + 16 $fp bar[2] bar[1] bar[0] bar[0]$v0 0xBAD4$ra
  • 52. Saving Registers • Some registers are preserved across function calls • If a function needs a value after the call, it uses one of these • But it must also preserve the previous contents (so it can honor its obligation to its caller) • Push these registers onto the stack. • See figure 2.12 in the text. 38