SlideShare a Scribd company logo
1 of 52
Download to read offline
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, efļ¬ciently, and at
reasonable cost?
ā€¢ i.e. How do we build the computer on your
desk.
2
In the beginning...
ā€¢ Physical conļ¬guration speciļ¬es 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 ļ¬rst 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 ā€œļ¬eldsā€ -- 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 ļ¬eld of the instruction can
specify
10
Is specifying the instructions sufļ¬cient?
ā€¢ 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 veriļ¬cation costs
ā€¢ More complex hardware.
ā€¢ More difļ¬cult to use -- Whatā€™s the right instruction in this context?
ā€¢ Less complexity
ā€¢ Programs will require more instructions -- poor code density
ā€¢ Programs can be more difļ¬cult for humans to understand
ā€¢ In the limit, decremement-and-branch-if-negative is sufļ¬cient
ā€¢ 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 deļ¬nes 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 ļ¬les)
Assembler
Executable
(i.e., .exe ļ¬les)
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 ļ¬‚ow 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 ļ¬‚ow 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 deļ¬ned at 0x20
used at 0x10
The value of the immediate for the branch
is 0x20-0x10 = 0x10
ā€˜topā€™ is deļ¬ned 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 deļ¬ned at 0x20
used at 0x10
The value of the immediate for the branch
is 0x20-0x10 = 0x10
ā€˜topā€™ is deļ¬ned 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 deļ¬nitions 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 ļ¬‚oating 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 ļ¬rst 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 ļ¬le
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 ļ¬le
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 ļ¬le
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 ļ¬gure 2.12 in the text.
38

More Related Content

What's hot

T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogramprincepavan
Ā 
Xtreams
XtreamsXtreams
XtreamsESUG
Ā 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overviewTAlha MAlik
Ā 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsEelco Visser
Ā 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesEelco Visser
Ā 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingEelco Visser
Ā 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and VariablesIntro C# Book
Ā 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ toolAbdullah Jan
Ā 

What's hot (10)

T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
Ā 
Xtreams
XtreamsXtreams
Xtreams
Ā 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
Ā 
c++
 c++  c++
c++
Ā 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
Ā 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type Constraints
Ā 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
Ā 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
Ā 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
Ā 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
Ā 

Viewers also liked

Vivek Raju birthday
Vivek Raju birthdayVivek Raju birthday
Vivek Raju birthdayaam_aadmi
Ā 
Seven secrets to success
Seven secrets to successSeven secrets to success
Seven secrets to successGus Ferguson
Ā 
Get started with dropbox
Get started with dropboxGet started with dropbox
Get started with dropboxArfen Tinambunan
Ā 
RAJEEV RANJAN KUMAR RESUME
RAJEEV RANJAN KUMAR RESUMERAJEEV RANJAN KUMAR RESUME
RAJEEV RANJAN KUMAR RESUMErajeev ranjan kumar
Ā 
Bill RoubalResume
Bill RoubalResumeBill RoubalResume
Bill RoubalResumeBill Roubal
Ā 
Health Disparities Project
Health Disparities Project Health Disparities Project
Health Disparities Project Shrishti Bhattarai
Ā 
The scenario of Bangladesh Minorities
The scenario of Bangladesh MinoritiesThe scenario of Bangladesh Minorities
The scenario of Bangladesh MinoritiesJhuma Halder
Ā 
Testing for slideshare
Testing for slideshareTesting for slideshare
Testing for slideshareebalan11
Ā 
ŠŸŃ€ŠµŠ·ŠµŠ½Ń‚Š°Ń†Šøя Š­Š»ŠµŠŗтрŠ¾Š½Š½Š°Ń Š±ŠøŠ±Š»ŠøŠ¾Ń‚ŠµŠŗŠ° "ŠœŠ˜Š¤"
ŠŸŃ€ŠµŠ·ŠµŠ½Ń‚Š°Ń†Šøя Š­Š»ŠµŠŗтрŠ¾Š½Š½Š°Ń Š±ŠøŠ±Š»ŠøŠ¾Ń‚ŠµŠŗŠ° "ŠœŠ˜Š¤"ŠŸŃ€ŠµŠ·ŠµŠ½Ń‚Š°Ń†Šøя Š­Š»ŠµŠŗтрŠ¾Š½Š½Š°Ń Š±ŠøŠ±Š»ŠøŠ¾Ń‚ŠµŠŗŠ° "ŠœŠ˜Š¤"
ŠŸŃ€ŠµŠ·ŠµŠ½Ń‚Š°Ń†Šøя Š­Š»ŠµŠŗтрŠ¾Š½Š½Š°Ń Š±ŠøŠ±Š»ŠøŠ¾Ń‚ŠµŠŗŠ° "ŠœŠ˜Š¤"Leila_B
Ā 
城åø‚č£”ēš„哲å­ø家
城åø‚č£”ēš„哲å­ø家城åø‚č£”ēš„哲å­ø家
城åø‚č£”ēš„哲å­ø家雅ē­‘ 劉
Ā 
Royalhighnessfellowshipbcsnet2
Royalhighnessfellowshipbcsnet2Royalhighnessfellowshipbcsnet2
Royalhighnessfellowshipbcsnet2Nkor Ioka
Ā 

Viewers also liked (14)

Vivek Raju birthday
Vivek Raju birthdayVivek Raju birthday
Vivek Raju birthday
Ā 
Seven secrets to success
Seven secrets to successSeven secrets to success
Seven secrets to success
Ā 
Get started with dropbox
Get started with dropboxGet started with dropbox
Get started with dropbox
Ā 
RAJEEV RANJAN KUMAR RESUME
RAJEEV RANJAN KUMAR RESUMERAJEEV RANJAN KUMAR RESUME
RAJEEV RANJAN KUMAR RESUME
Ā 
Bill RoubalResume
Bill RoubalResumeBill RoubalResume
Bill RoubalResume
Ā 
Health Disparities Project
Health Disparities Project Health Disparities Project
Health Disparities Project
Ā 
PATULA
PATULAPATULA
PATULA
Ā 
The scenario of Bangladesh Minorities
The scenario of Bangladesh MinoritiesThe scenario of Bangladesh Minorities
The scenario of Bangladesh Minorities
Ā 
Raja S
Raja SRaja S
Raja S
Ā 
Testing for slideshare
Testing for slideshareTesting for slideshare
Testing for slideshare
Ā 
ŠŸŃ€ŠµŠ·ŠµŠ½Ń‚Š°Ń†Šøя Š­Š»ŠµŠŗтрŠ¾Š½Š½Š°Ń Š±ŠøŠ±Š»ŠøŠ¾Ń‚ŠµŠŗŠ° "ŠœŠ˜Š¤"
ŠŸŃ€ŠµŠ·ŠµŠ½Ń‚Š°Ń†Šøя Š­Š»ŠµŠŗтрŠ¾Š½Š½Š°Ń Š±ŠøŠ±Š»ŠøŠ¾Ń‚ŠµŠŗŠ° "ŠœŠ˜Š¤"ŠŸŃ€ŠµŠ·ŠµŠ½Ń‚Š°Ń†Šøя Š­Š»ŠµŠŗтрŠ¾Š½Š½Š°Ń Š±ŠøŠ±Š»ŠøŠ¾Ń‚ŠµŠŗŠ° "ŠœŠ˜Š¤"
ŠŸŃ€ŠµŠ·ŠµŠ½Ń‚Š°Ń†Šøя Š­Š»ŠµŠŗтрŠ¾Š½Š½Š°Ń Š±ŠøŠ±Š»ŠøŠ¾Ń‚ŠµŠŗŠ° "ŠœŠ˜Š¤"
Ā 
城åø‚č£”ēš„哲å­ø家
城åø‚č£”ēš„哲å­ø家城åø‚č£”ēš„哲å­ø家
城åø‚č£”ēš„哲å­ø家
Ā 
Royalhighnessfellowshipbcsnet2
Royalhighnessfellowshipbcsnet2Royalhighnessfellowshipbcsnet2
Royalhighnessfellowshipbcsnet2
Ā 
Intensitet
IntensitetIntensitet
Intensitet
Ā 

Similar to 02 isa

MIPS_Programming.pdf
MIPS_Programming.pdfMIPS_Programming.pdf
MIPS_Programming.pdfXxUnnathxX
Ā 
Introduction to Computer Architecture
Introduction to Computer ArchitectureIntroduction to Computer Architecture
Introduction to Computer ArchitectureKSundarAPIICSE
Ā 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuEstelaJeffery653
Ā 
Tema2_ArchitectureMIPS.pptx
Tema2_ArchitectureMIPS.pptxTema2_ArchitectureMIPS.pptx
Tema2_ArchitectureMIPS.pptxgopikahari7
Ā 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Amr Alaa El Deen
Ā 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
Ā 
CE412 -advanced computer Architecture lecture 1.pdf
CE412 -advanced computer Architecture lecture 1.pdfCE412 -advanced computer Architecture lecture 1.pdf
CE412 -advanced computer Architecture lecture 1.pdfAdelAbougdera
Ā 
Basic Structure of a Computer System
Basic Structure of a Computer SystemBasic Structure of a Computer System
Basic Structure of a Computer SystemAmirthavalli Senthil
Ā 
Assembly.ppt
Assembly.pptAssembly.ppt
Assembly.pptsuzanawinat3
Ā 
16 -ansi-iso_standards
16  -ansi-iso_standards16  -ansi-iso_standards
16 -ansi-iso_standardsHector Garzo
Ā 
Activity 5
Activity 5Activity 5
Activity 5Heidi Owens
Ā 
Highlevel assemly
Highlevel assemlyHighlevel assemly
Highlevel assemlykarishmamubeen
Ā 
Creating your own Abstract Processor
Creating your own Abstract ProcessorCreating your own Abstract Processor
Creating your own Abstract ProcessorAodrulez
Ā 
r2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCyr2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCyRay Song
Ā 
C Tutorials
C TutorialsC Tutorials
C TutorialsSudharsan S
Ā 
Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Davide Carboni
Ā 

Similar to 02 isa (20)

01 isa
01 isa01 isa
01 isa
Ā 
ISA.pptx
ISA.pptxISA.pptx
ISA.pptx
Ā 
MIPS_Programming.pdf
MIPS_Programming.pdfMIPS_Programming.pdf
MIPS_Programming.pdf
Ā 
Introduction to Computer Architecture
Introduction to Computer ArchitectureIntroduction to Computer Architecture
Introduction to Computer Architecture
Ā 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
Ā 
Tema2_ArchitectureMIPS.pptx
Tema2_ArchitectureMIPS.pptxTema2_ArchitectureMIPS.pptx
Tema2_ArchitectureMIPS.pptx
Ā 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
Ā 
Mips
MipsMips
Mips
Ā 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
Ā 
CE412 -advanced computer Architecture lecture 1.pdf
CE412 -advanced computer Architecture lecture 1.pdfCE412 -advanced computer Architecture lecture 1.pdf
CE412 -advanced computer Architecture lecture 1.pdf
Ā 
Basic Structure of a Computer System
Basic Structure of a Computer SystemBasic Structure of a Computer System
Basic Structure of a Computer System
Ā 
Assembly.ppt
Assembly.pptAssembly.ppt
Assembly.ppt
Ā 
22CS201 COA
22CS201 COA22CS201 COA
22CS201 COA
Ā 
16 -ansi-iso_standards
16  -ansi-iso_standards16  -ansi-iso_standards
16 -ansi-iso_standards
Ā 
Activity 5
Activity 5Activity 5
Activity 5
Ā 
Highlevel assemly
Highlevel assemlyHighlevel assemly
Highlevel assemly
Ā 
Creating your own Abstract Processor
Creating your own Abstract ProcessorCreating your own Abstract Processor
Creating your own Abstract Processor
Ā 
r2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCyr2con 2017 r2cLEMENCy
r2con 2017 r2cLEMENCy
Ā 
C Tutorials
C TutorialsC Tutorials
C Tutorials
Ā 
Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?
Ā 

More from marangburu42

Hennchthree 161102111515
Hennchthree 161102111515Hennchthree 161102111515
Hennchthree 161102111515marangburu42
Ā 
Sequential circuits
Sequential circuitsSequential circuits
Sequential circuitsmarangburu42
Ā 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuitsmarangburu42
Ā 
Hennchthree 160912095304
Hennchthree 160912095304Hennchthree 160912095304
Hennchthree 160912095304marangburu42
Ā 
Sequential circuits
Sequential circuitsSequential circuits
Sequential circuitsmarangburu42
Ā 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuitsmarangburu42
Ā 
Karnaugh mapping allaboutcircuits
Karnaugh mapping allaboutcircuitsKarnaugh mapping allaboutcircuits
Karnaugh mapping allaboutcircuitsmarangburu42
Ā 
Aac boolean formulae
Aac   boolean formulaeAac   boolean formulae
Aac boolean formulaemarangburu42
Ā 
Virtualmemoryfinal 161019175858
Virtualmemoryfinal 161019175858Virtualmemoryfinal 161019175858
Virtualmemoryfinal 161019175858marangburu42
Ā 
Io systems final
Io systems finalIo systems final
Io systems finalmarangburu42
Ā 
File system interfacefinal
File system interfacefinalFile system interfacefinal
File system interfacefinalmarangburu42
Ā 
File systemimplementationfinal
File systemimplementationfinalFile systemimplementationfinal
File systemimplementationfinalmarangburu42
Ā 
Mass storage structurefinal
Mass storage structurefinalMass storage structurefinal
Mass storage structurefinalmarangburu42
Ā 
All aboutcircuits karnaugh maps
All aboutcircuits karnaugh mapsAll aboutcircuits karnaugh maps
All aboutcircuits karnaugh mapsmarangburu42
Ā 
Virtual memoryfinal
Virtual memoryfinalVirtual memoryfinal
Virtual memoryfinalmarangburu42
Ā 
Mainmemoryfinal 161019122029
Mainmemoryfinal 161019122029Mainmemoryfinal 161019122029
Mainmemoryfinal 161019122029marangburu42
Ā 

More from marangburu42 (20)

Hol
HolHol
Hol
Ā 
Write miss
Write missWrite miss
Write miss
Ā 
Hennchthree 161102111515
Hennchthree 161102111515Hennchthree 161102111515
Hennchthree 161102111515
Ā 
Hennchthree
HennchthreeHennchthree
Hennchthree
Ā 
Hennchthree
HennchthreeHennchthree
Hennchthree
Ā 
Sequential circuits
Sequential circuitsSequential circuits
Sequential circuits
Ā 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuits
Ā 
Hennchthree 160912095304
Hennchthree 160912095304Hennchthree 160912095304
Hennchthree 160912095304
Ā 
Sequential circuits
Sequential circuitsSequential circuits
Sequential circuits
Ā 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuits
Ā 
Karnaugh mapping allaboutcircuits
Karnaugh mapping allaboutcircuitsKarnaugh mapping allaboutcircuits
Karnaugh mapping allaboutcircuits
Ā 
Aac boolean formulae
Aac   boolean formulaeAac   boolean formulae
Aac boolean formulae
Ā 
Virtualmemoryfinal 161019175858
Virtualmemoryfinal 161019175858Virtualmemoryfinal 161019175858
Virtualmemoryfinal 161019175858
Ā 
Io systems final
Io systems finalIo systems final
Io systems final
Ā 
File system interfacefinal
File system interfacefinalFile system interfacefinal
File system interfacefinal
Ā 
File systemimplementationfinal
File systemimplementationfinalFile systemimplementationfinal
File systemimplementationfinal
Ā 
Mass storage structurefinal
Mass storage structurefinalMass storage structurefinal
Mass storage structurefinal
Ā 
All aboutcircuits karnaugh maps
All aboutcircuits karnaugh mapsAll aboutcircuits karnaugh maps
All aboutcircuits karnaugh maps
Ā 
Virtual memoryfinal
Virtual memoryfinalVirtual memoryfinal
Virtual memoryfinal
Ā 
Mainmemoryfinal 161019122029
Mainmemoryfinal 161019122029Mainmemoryfinal 161019122029
Mainmemoryfinal 161019122029
Ā 

Recently uploaded

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
Ā 
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļøcall girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø9953056974 Low Rate Call Girls In Saket, Delhi NCR
Ā 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
Ā 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
Ā 
ā€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
ā€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...ā€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
ā€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
Ā 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
Ā 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
Ā 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
Ā 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
Ā 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
Ā 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
Ā 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
Ā 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
Ā 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
Ā 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
Ā 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
Ā 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
Ā 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
Ā 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
Ā 

Recently uploaded (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
Ā 
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļøcall girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
call girls in Kamla Market (DELHI) šŸ” >ą¼’9953330565šŸ” genuine Escort Service šŸ”āœ”ļøāœ”ļø
Ā 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Ā 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
Ā 
ā€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
ā€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...ā€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
ā€œOh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
Ā 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
Ā 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
Ā 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
Ā 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Ā 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
Ā 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
Ā 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Ā 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
Ā 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
Ā 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
Ā 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
Ā 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
Ā 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
Ā 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
Ā 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
Ā 

02 isa

  • 2. The Architecture Question ā€¢ How do we build computer from contemporary silicon device technology that executes general- purpose programs quickly, efļ¬ciently, and at reasonable cost? ā€¢ i.e. How do we build the computer on your desk. 2
  • 3. In the beginning... ā€¢ Physical conļ¬guration speciļ¬es 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 ļ¬rst 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 ā€œļ¬eldsā€ -- 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 ļ¬eld of the instruction can specify 10
  • 11. Is specifying the instructions sufļ¬cient? ā€¢ 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 veriļ¬cation costs ā€¢ More complex hardware. ā€¢ More difļ¬cult to use -- Whatā€™s the right instruction in this context? ā€¢ Less complexity ā€¢ Programs will require more instructions -- poor code density ā€¢ Programs can be more difļ¬cult for humans to understand ā€¢ In the limit, decremement-and-branch-if-negative is sufļ¬cient ā€¢ 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 deļ¬nes 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 ļ¬les) Assembler Executable (i.e., .exe ļ¬les) 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 ļ¬‚ow 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 ļ¬‚ow 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 deļ¬ned at 0x20 used at 0x10 The value of the immediate for the branch is 0x20-0x10 = 0x10 ā€˜topā€™ is deļ¬ned 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 deļ¬ned at 0x20 used at 0x10 The value of the immediate for the branch is 0x20-0x10 = 0x10 ā€˜topā€™ is deļ¬ned 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 deļ¬nitions 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 ļ¬‚oating 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 ļ¬rst 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 ļ¬le
  • 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 ļ¬le 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 ļ¬le 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 ļ¬gure 2.12 in the text. 38