Answered step by step
Verified Expert Solution
Link Copied!

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.
Program1(add.asm):
.data
x: .word 0
y: .word 0
z: .word 0
nl: .asciiz "
"
.text
main:
li $v0,5 # Read x
syscall
la $t0, x
sw $v0,0($t0)
li $v0,5 # Read y
syscall
la $t0, y
sw $v0,0($t0)
la $t0, x # z = x + y
lw $t1,0($t0)
lw $t2,4($t0)
add $t3, $t1, $t2
la $t0, z
sw $t3,0($t0)
li $v0,1 # Print z
lw $a0,0($t0)
syscall
li $v0,4
la $a0, nl
syscall
la $t0, x
lw $t1,0($t0)
lw $t2,4($t0)
sub $t3, $t1, $t2
sw $t3,8($t0)
li $v0,1
lw $a0,8($t0)
syscall
li $v0,4
la $a0, nl
syscall
li $v0,10 # Exit
syscall
Program 2(countdown.asm):
.data
cstart:
.word 10
nl:
.asciiz "
"
.text
main:
la $t0, cstart # step 1: Load counter
lw $s0,0($t0)
loop:
li $v0,1 # step 2: Print counter
or $a0, $s0, $zero
syscall
li $v0,4 # Print newline
la $a0, nl
syscall
bne $s0, $zero, continue # If counter !=0, go to continue
li $v0,10 # exit
syscall
continue:
addi $s0, $s0,-1 # step 4: decrement counter
b loop # step 5: go to 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

13-4 What is deethnicization? Give an example.

Answered: 1 week ago