Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started