Lab 4 –MIPS Assembly language The purpose of this lab is to introduce you to the
ID: 667118 • Letter: L
Question
Lab 4 –MIPS Assembly language
The purpose of this lab is to introduce you to the layout and structure of the Mars IDE development tool in addition to Procedures programming. In this lab, a procedure is called to sort three numbers (ascending sort) in the memory.
.text
.globl _start
_start:
la $a0, array
lw $a1, count # in the jal statement
jal sort # jump to “sort:”
j print # jump to “print:’
# start subrouten
sort: sw $ra, -4($sp) #load the return address in to the stack pointer
move $t6, $a1 #outter counter
outter: sub $t6, $t6, 1 #sub the outter counter
move $t7, $a0 #savc the address for ‘array” into 5t7
move $t5, $a1 #inncr counter
linner: sub $t5, $t5, 1 #sub I from inncr counter
lw $s0,($t7) #load the two variables
lw $s1,4($t7) #to be tested
ble $s0,$s1,next #ifSsO<Ssl branch
sw $s1 ,($t7) # else switch the two
sw $s0,4($t7)
ncxt:add $t7, $t7, 4 #add 4 to the saved address for next loop
bnez $t5, inner #1f the inner counter is not O then branch
bnez $t6, outter #1f the outter counter is not O then branch
lw $ra, -4($sp) #ifouttcr counter is O load top
jr $ra #stack point and exit subrouten
print: #print out the final memery locatinn
la $t7,array
lw $t0,($t7)
lw $t1,4($t7)
lw $t2,8($t7)
.data
array: .word 3,2,1
count: .word 3
#4 end of file
Observe the registers/Memory locations values after each Step Run. Record the final values.
Use $t0, $t1, and $t2 to hold the numbers after the ascending sort. What are the final values of $t0, $t1, and $t2?
Explanation / Answer
Final values of
$t0-1
$t1-2
$t2-3
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.