11 A function calls another function and also changes the va

1.1 A function calls another function and also changes the values in $t0, $t1, $s0, and $s1. How many bytes of memory need to be allocated on the stack to preserve the required registers (per the green sheet)?

1.2 Assume that a function has been called and the $ra is 0x0040400C. The PC is currently 0x00402000. What is the address of the jal instruction that called the function?

a. 0x00402000

b. 0x00404008

c. 0x00402004

d. 0x0040400C

Solution

The MIPS processor only supports two branch instructions, beq and bne, but to simplify your life the assembler provides the following other branches: blt $t0, $t1, L1 // Branch if $t0 < $t1 ble $t0, $t1, L2 // Branch if $t0 <= $t1 bgt $t0, $t1, L3 // Branch if $t0 > $t1 bge $t0, $t1, L4 // Branch if $t0 >= $t1 Later this term we’ll see how supporting just beq and bne simplifies the processor design. slt $at, $a0, $a1 // $at = 1 if $a0 < $a1 bne $at, $0, Label // Branch if $at != 0

v0 = *a0; lw $t0, 0($a0) if (v0 < 0) bge $t0, $zero, label v0 = -v0; sub $t0, $zero, $t0 v1 = v0 + v0; label: add $t1, $t0, $t0if (v0 < 0) bge $v0, $0, E v0 --; sub $v0, $v0, 1 j L else v0 ++; E: add $v0, $v0, 1 v1 = v0; L: move $v1, $v0

$s0-$s7 16-23 Saved temporaries Loop: lw $s0, 0($s1) ;$s1=x[1000] add $s3, $s0, $s2 ;$s2=h sw $s3, 0($s1) addi $s1, $s1, # - 4 bne $s1, $s5, Loop ;$s5=x[0]frodo: li $a0, 3 li $a1, 1 li $s0, 4 li $s1, 1 # Save registers # $a0, $a1 jal gollum # Restore registers # $a0 and $a1 add $v0, $a0, $a1 add $v1, $s0, $s1 jr $ra gollum: # Save registers # $s0,$s2 li $a0, 2 li $a2, 7 li $s0, 1 li $s2, 8 ... # Save $ra,$a0 & $a2 jal gollumson # Restore registers # $a0 & $a2 ... # Restore $s0,$s2,$ra

1.2

c. 0x00402004

1.1 A function calls another function and also changes the values in $t0, $t1, $s0, and $s1. How many bytes of memory need to be allocated on the stack to prese

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site