Question: Trace each program by writing the contents of each relevant register after the execution of each instruction. In the case of a loop, show the
Trace each program by writing the contents of each relevant register after the execution of each instruction. In the case of a loop, show the contents of each relevant register for the first two iterations and the last one.
Programaddasm:
data
x: word
y: word
z: word
nl: asciiz
text
main:
li $v # Read x
syscall
la $t x
sw $v$t
li $v # Read y
syscall
la $t y
sw $v$t
la $t x # z x y
lw $t$t
lw $t$t
add $t $t $t
la $t z
sw $t$t
li $v # Print z
lw $a$t
syscall
li $v
la $a nl
syscall
la $t x
lw $t$t
lw $t$t
sub $t $t $t
sw $t$t
li $v
lw $a$t
syscall
li $v
la $a nl
syscall
li $v # Exit
syscall
Program countdownasm:
data
cstart:
word
nl:
asciiz
text
main:
la $t cstart # step : Load counter
lw $s$t
loop:
li $v # step : Print counter
or $a $s $zero
syscall
li $v # Print newline
la $a nl
syscall
bne $s $zero, continue # If counter go to continue
li $v # exit
syscall
continue:
addi $s $s # step : decrement counter
b loop # step : go to
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
