
1 of 1
Boise State University
Department of Electrical and Computer Engineering
ECE 332 Microprocessors
Quiz 3 โ September 26, 2007
Name: ______________________________
1. You have main, subroutine sub1, and subroutine sub2. main calls subroutine sub1. subroutine sub1 calls
subroutine sub2. What do you need to do with the return addresses in each case so that the program will
complete its execution as designed?
When main calls sub1, the return address (which is pc+4) is automatically saved into ra (or r31) register. In sub1,
before calling sub2, the content of ra register will need to be saved to stack. When sub1 calls sub2, the return
address (from sub2 to sub1) will automatically saved into r31. Our previous save into stack preserved the return
address for sub1 to return to main. After sub2 returns to sub1, we need to restore the return address from stack. This
way, sub1 can return to main correctly.
2. Answer the following questions using this assembly code.
.text
.global _start
_start:
movia r5,VCOUNT
ldw r3,0(r5)
2a. The content of r5 and r7?
movia r7,VALUES address of VCOUNT in r5
address of VALUES in r7
movi r2,0
movi r4,0
loop:
beq r2,r3,loop_end
ldw r6,0(r7)
add r4,r4,r6
addi r7,r7,4 2b. Provide the mathematical expression for this
addi r2,r2,1 segment of code.
br loop
if you have r4 = 1+2+3+4 you are okay or
loop_end: r4 =
r4=mem(i)
i=0
3
๎
movia r7,SUM
stw r4,0(r7)
.data
VCOUNT: .word 4
VALUES: .word 1,2,3,4,5
SUM: .word 0 2c. The value of SUM after execution of โstw r4,0(r7)โ?
.end 10
2d. Why we add โ4โ in โadd r7,r7,4โ?
Because VALUES is declared as .word, in this architecture, it is 32 bits or 4 bytes. The 4 corresponds to 4 bytes for
go to the next word. To go to the next memory location to access the new value.