Write an MIPS assembly program which contains the following data statements. .da
ID: 3630365 • Letter: W
Question
Write an MIPS assembly program which contains the following data statements.
.data
Data: .word 8, 127, 983, 16000, 65537
Value: .byte 255, 128, 64, 32, 5
Your program should read the 5 words labeled “ Data” from memory and sum them. Likewise, read the five bytes labeled “Value” from memory and display their sum also. Comment on the sum of the five byte values. (HINT: did you use signed or unsigned load?) What happens if the byte sum is stored in memory then retrieved and displayed?
There are at least 3 different answers for the sum of bytes and each may be correct. Discuss the conditions under which each result is correct and document your results in your program's comments section
Explanation / Answer
.globl main
.data
Data:
.word 8, 127, 16000, 65537
Value:
.byte 255,128,64,32,5
Dataout:
.asciiz "Data sum is: "
Valueout:
.asciiz "Value sum is: "
byte:
.space 1
new:
.asciiz " Value sum after storing: "
.text
main:
li $v0,4 #Output String
la $a0,Dataout
syscall
la $s0,Data #sequentially load and add words in Data
lw $s1,($s0)
lw $t1,4($s0)
add $s1,$s1,$t1
lw $t1,8($s0)
add $s1,$s1,$t1
lw $t1,12($s0)
add $s1,$s1,$t1
li $v0,1
move $a0,$s1
syscall
li $v0,4 #Output String
la $a0,Valueout
syscall
li $v0,1 #sequentially load and add bytes in Value
la $s0,Value
lbu $s1,($s0) #If you load unsigned
#end with negative values
lbu $t0,1($s0) #because the leading bit may be 1
add $s1,$s1,$t0
lbu $t0,2($s0)
add $s1,$s1,$t0
lbu $t0,3($s0)
add $s1,$s1,$t0
lbu $t0,4($s0)
add $s1,$s1,$t0
move $a0,$s1
syscall
li $v0,4 #Output String new
la $a0,new
syscall
li $v0,1
la $s3,byte #after storing
sb $s1,($s3)
lbu $s1,0($s3)
move $a0,$s1
syscall
j $ra
li $v0, 10 # Exit program
syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.