Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN MIPS PART 2. AN ASM EXAMPLE ASM Programming instructions: For this part your

ID: 3896746 • Letter: I

Question

IN MIPS

PART 2. AN ASM EXAMPLE ASM Programming instructions: For this part your goal is to run some example assembly code (provided below), and then modify the code to read in and add 3 numbers instead of just 2 2. 3. 4. 5. 6. 7, 8. data # variable declarations follow this line text # instructions follow this line main: ## Code Part 1: Get first number from user, put into $t0 ori $v0, $0,5 # OUR CODE BEGINS HERE: load syscall read-int into $v0. syscall # make the syscall. addu $t0, $0, $v0 # move the number read into $t0 ## Get second number from user, put into $t1. ori $v0, $0,5 # load syscall read-int into $v0. 10. syscall # make the syscall. 11, addu $t1, $0, $v0 # move the number read into St1. 12, add $12, $t0, $t1 # compute the sum. 13. ## Print out $t2. 14, addu $a0, $0, $t2 # move the number to print into $a0 15, ori $v0, $0. 1 # load syscall print-int into $v0. 16. syscall # make the syscall. 17. ori $v0, $0, 10 # syscall code 10 is for exit. 18. syscall # make the syscall. 19. ## end of add2.asm.

Explanation / Answer


Given below is the modified code for the question. The program does not prompt, you just need to input 3 numbers and the result is displayed
Please do rate the answer if it was helpful. Thank you

Answer for Q1:
==========
.data
.text
main:
##Code Part 1: Get first number from user, put into $t0
ori $v0, $0, 5 #OUR CODE BEGINS HERE: load syscall read_int into $v0
syscall #make the syscall
addu $t0, $0, $v0 #move the number read into $t0
##Get second number from user, put into $t1
ori $v0, $0, 5 #load syscall read_int into $v0
syscall #make the syscall
addu $t1, $0, $v0 #move the number read into $t1
##Get third number from user, put into $t2
ori $v0, $0, 5 #load syscall read_int into $v0
syscall #make the syscall
addu $t2, $0, $v0 #move the number read into $t2
add $t3, $t0, $t1 #compute the sum $t3 = $t0 + $t1
add $t3, $t3, $t2 #add $t2 to computed sum, $t3 = $t3 + $t2
##Print out $t3
addu $a0, $0, $t3 #move the number to print into $a0
ori $v0, $0, 1 #load syscall print_int into $v0
syscall #make the syscall
ori $v0, $0, 10 #syscall code 10 for exit
syscall #make the syscall
##end of add2.asm

==================
Answer for Q2:
The code was modified to use read_int system call to get the third number from user. The sum of first and second was stored in $t3 and then the third number was added to this intermediate result stored in $t3. The results from $t3 was displayed using print_int system call.
The changes shown in bold

.data
.text
main:
##Code Part 1: Get first number from user, put into $t0
ori $v0, $0, 5 #OUR CODE BEGINS HERE: load syscall read_int into $v0
syscall #make the syscall
addu $t0, $0, $v0 #move the number read into $t0
##Get second number from user, put into $t1
ori $v0, $0, 5 #load syscall read_int into $v0
syscall #make the syscall
addu $t1, $0, $v0 #move the number read into $t1
##Get third number from user, put into $t2
ori $v0, $0, 5 #load syscall read_int into $v0
syscall #make the syscall
addu $t2, $0, $v0 #move the number read into $t2
add $t3, $t0, $t1 #compute the sum $t3 = $t0 + $t1
add $t3, $t3, $t2 #add $t2 to computed sum, $t3 = $t3 + $t2
##Print out $t3
addu $a0, $0, $t3 #move the number to print into $a0

ori $v0, $0, 1 #load syscall print_int into $v0
syscall #make the syscall
ori $v0, $0, 10 #syscall code 10 for exit
syscall #make the syscall
##end of add2.asm

output
====
3
2
6
11
-- program is finished running --