Professional Documents
Culture Documents
2-Sheet 2 Part4-Student
2-Sheet 2 Part4-Student
Sheet 2_Part 4
Supporting Procedures (cont.)
Register number Preserve on
Name Usage
(decimal) call?
$zero 0 the constant value 0 n.a.
$at 1 reserved for the assembler n.a.
procedure return values and
$v0-$v1 2-3 no
expression evaluation
$a0-$a3 4-7 Caller (parameters)
procedure arguments Callee no
$t0-$t7 8-15 function
temporary registers function no
$s0-$s7 16-23 Saved/purpose
general saved registers
($t0-$t9) yes
Restored ($s0-$s7)
$t8-$t9 24-25 more temporary ($a0-$a3)
registers $gp,$fp, $sp, $ra no
registers ($v0,
$k0-$k1 26-27 reserved for the OS$v1) n.a.
$gp 28 global pointer yes
$sp 29 stack pointer yes
$fp 30 frame pointer yes
$ra 31 procedure return address yes
Q16: Consider the following C-language program. Functions main(), calculate(), evaluate(), and square() are
placed starting at locations 60010, 70010, 80010, and 90010, respectively in memory. Integer variables c, d, and i are
stored in registers $s0, $s1, and $s2, respectively. Assume that register $s0, $s1, and the stack pointer ($sp) are
initialized with the values 6, 9, and 800010, respectively. Show stack contents (in decimal) when the stack is at its
maximum size while executing the given code. Do not write register names. Write only numerical contents. Use
X for unknown values.
Q18. For each code sequence in Exercise 17, calculate the instruction bytes fetched and the memory data bytes
transferred (read or written). Use the following assumptions about all four instruction sets:
Which architecture is most efficient as measured by code size? Which architecture is most efficient as
measured by total memory bandwidth required (code + data)? If the answers are not the same, why are they
different?
Architectural Style MIPs Instructions Instruction bytes Memory data bytes
fetched transferred
add addrC 3 4
store addrA 3 4
add addrC 3 4
store addrB 3 4
neg 1 0
add addrA 3 4
store addrD 3 4
22 28
a = b + c; Opcode: 1byte
b = a + c; memory addresses: 2 bytes
d = a – b; Operands: 4 bytes Total Memory BW= 50
Architectural Style MIPs Instructions Instruction bytes Memory data bytes
fetched transferred
21 36
a = b + c; Opcode: 1byte
b = a + c; memory addresses: 2 bytes
d = a – b; Operands: 4 bytes Total Memory BW= 57
Architectural Style MIPs Instructions Instruction bytes Memory data bytes
fetched transferred
Stack push addrB 1+2=3 4
push addrC 3 4
add 1 0
dup 1 0
pop addrA 3 4
push addrC 3 4
add 1 0
dup 1 0
pop addrB 3 4
neg 1 0
push addrA 3 4
add 1 0
pop addrD 3 4
27 28
a = b + c; Opcode: 1byte
b = a + c; memory addresses: 2 bytes 55
Total Memory BW=
d = a – b; Operands: 4 bytes
Architectural Style MIPs Instructions Instruction bytes Memory data bytes
fetched transferred
lw $t1, 0(addrC) 4 4
add $t2, $t0, $t1 4 0
sw $t2, 0(addrA) 4 4
add $t0, $t2, $t1 4 0
sw $t0, 0(addrB) 4 4
sw $t3, 0(addrD) 4 4
32 20
a = b + c; Opcode: 1byte
b = a + c; memory addresses: 2 bytes
d = a – b; Operands: 4 bytes Total Memory BW= 52
Which architecture is most efficient as measured by code size? Which
architecture is most efficient as measured by total memory bandwidth
required (code + data)? If the answers are not the same, why are they
different?
push $s0
add $s0, $a0, $a1
add $v0, $s0, $0
pop $s0
jr $ra