Write a simple loop program in MIPS/QtSpim that will examine each number in the
ID: 3825594 • Letter: W
Question
Write a simple loop program in MIPS/QtSpim that will examine each number in the data declaration below and do the following: If the number is negative, it is printed out to the console using syscall 1. If it is positive, the 2’s compliment of the number is calculated and stored back in the same data location. Thus at the end of the program, ALL of the data will be negative. After you output a data word to the console, output a CR/LF so that each number is on a separate line. (No manual calculation is needed).
Question 1 is the program
Question 2 is : List the numbers that are printed out (as address labels or Hex representation)
.data
num1: .word 0x76546162
num2: .word 0x33346a6b
num3: .word 0x96548b8d
num4: .word 0x20666a4b
num5: .word 0x92773445
num6: .word 0x343f787c
num7: .word 0x86578778
num8: .word 0x41456669
num9: .word 0x8072204f
num0: .word 0
Explanation / Answer
Hi,
Please find the code for MIPS PROGRAM below:-
CODE:-
========================================================================================
.data
num1: .word 0x76546162
num2: .word 0x33346a6b
num3: .word 0x96548b8d
num4: .word 0x20666a4b
num5: .word 0x92773445
num6: .word 0x343f787c
num7: .word 0x86578778
num8: .word 0x41456669
num9: .word 0x8072204f
num0: .word 0
.text
global _start
_start :
mov $t2 ,1 #move 1 to t2
loop:
beq t2, 10,endloop #check if end of list is reached
move $t1 , (num)t2 #else move (num)t2 values to t1
add $t2,t2,1 #increment t2 by 1
bgtz $t1 ,POSITIVE #if t1 is positive jump to label POSITIVE
move $a0 ,$t1 #ELSE move value of t1 to$ao
li $vo ,1 #load syscall print_int into $v0
syscall # make the syscall.
call Crlf
POSITIVE:
sub $t3,0,$t1 # take 2’s complement by subtracting from 0
move $a0 ,$t3 # move value of t3 to $ao
li $v0,1 #load syscall print_int into $v0
syscall #load syscall print_int into $v0
call Crlf
b loop # and repeat the loop.
endloop:
li $vo,10 #After loop completes call exit
syscall
end:
===================================================================================
Please let me know in case of any clarification.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.