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

MIPS/SPIM programming Write a loop program that analyzes the bytes in words w, x

ID: 3717070 • Letter: M

Question

MIPS/SPIM programming
Write a loop program that analyzes the bytes in words w, x, y in its data declaration. The program needs to store all non-number characters at address label out: which reserves enough memory for that as declared in .data. Once all bytes have been analyzed, print the stored string of characters.

Note : You would need to use a counter to exit the loop
how program will start

.text

main:(code will go here)

.data

w: .word 0x524c3043

x: .word 0x20452654

y: .word 0x35333130

out: .space 8

Assuming Big Endian convention,
What is the output on the console?

Explanation / Answer

ScreenShot

-----------------------------------------------------------

Program

#main function
.text
main:
#load address of w,x,y and out
la $t0,w
la $t1,x
la $t2,y
la $t3,out
#counter
li $t4,8
#w non number check
loop:
#until loop 0
beq $t4,0,X
#load each byte
lb $t5,0($t0)
#compare non number
bgt $t5,47,next
#otherwise add into out
sb $t5,0($t3)
#increment adresses and decrement counte
addi $t0,$t0,1
addi $t3,$t3,1
addi $t4,$t4,-1
#continue loop
j loop
next:
#check nun number
blt $t5,58,next1
sb $t5,0($t3)
addi $t0,$t0,1
addi $t3,$t3,1
addi $t4,$t4,-1
j loop
#if number then just increment adresses to get next byte
next1:
addi $t0,$t0,1
addi $t4,$t4,-1
j loop
#x non number check
X:
li $t4,8
#loop to check non number (number between 48-57 in ascii)
loop1:
beq $t4,0,Y
lb $t5,0($t1)
bgt $t5,47,nextX
sb $t5,0($t3)
addi $t1,$t1,1
addi $t3,$t3,1
addi $t4,$t4,-1
j loop1
nextX:
blt $t5,58,next2
sb $t5,0($t3)
addi $t1,$t1,1
addi $t3,$t3,1
addi $t4,$t4,-1
j loop1
next2:
addi $t1,$t1,1
addi $t4,$t4,-1
j loop1
#Y non number check
Y:
li $t4,8
#loop to check non number (number between 48-57 in ascii)
loop2:
beq $t4,0,exit
lb $t5,0($t2)
bgt $t5,47,nextY
sb $t5,0($t3)
addi $t2,$t2,1
addi $t3,$t3,1
addi $t4,$t4,-1
j loop2
nextY:
blt $t5,58,next3
sb $t5,0($t3)
addi $t2,$t2,1
addi $t3,$t3,1
addi $t4,$t4,-1
j loop2
next3:
addi $t2,$t2,1
addi $t4,$t4,-1
j loop2
exit:
la $t0,out
li $t4,8
loopExit:
beq $t4,0,end
lb $a0,0($t0)
li $v0,11
syscall
addi $t0,$t0,1
addi $t4,$t4,-1
j loopExit
#exit from the program
end:
li $v0,10
syscall
#variable declaration section
.data
w: .word 0x524c3043
x: .word 0x20452654
y: .word 0x35333130
out: .space 8