Home / Expert Answers / Computer Science / trace-each-program-by-writing-the-contents-of-each-relevant-register-after-the-execution-of-each-ins-pa447

(Solved): Trace each program by writing the contents of each relevant register after the execution of each ins ...



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



We have an Answer from Expert

View Expert Answer

Expert Answer


We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe