please help!! Sorting numbers is a very common problem; here, you just have 3 nu
ID: 3801877 • Letter: P
Question
please help!!
Sorting numbers is a very common problem; here, you just have 3 numbers to sort. This MIPS/SPIM program includes a subroutine called myadd that performs x=(y+z);. In the space below, replace the myadd subroutine with one named mysort that will sort the values of x, y, and z and into increasing order (i.e., make x the smallest and z the largest). You should test your routine using SPIM before you submit it, which will require merging it with a test framework like the one used in this MIPS/SPIM program -- but only submit the mysort routine here. #### # # Addition routine: # x = y + z # .text .globl my add myadd: la $t0, y #t0 = y lw $t0, 0($t0) la $t1, z #t1 = z lw $t1, 0($t1) addu $t2, $t0, $t1 #t2 = y + z la $t0, x #x = 12 sw $t2, 0($t0) jr $ra #returnExplanation / Answer
This program sorts the given integer variables x,y,z x-smallest,y-middle,z-largest
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.text
.align 2
.globl mysort
$LFB0 = .
.set nomips16
.ent main
.type main, @function
mysort:
.frame $fp,32,$31 # vars= 16, regs= 1/0, args= 0, gp= 8
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-32
$LCFI0:
sw $fp,28($sp)
$LCFI1:
move $fp,$sp
movz $31,$31,$0
$LCFI2:
la $2,x # 0x5
sw $2,16($fp)
la $2,y # 0x2
sw $2,12($fp)
la $2,z # 0x3
sw $2,8($fp)
lw $3,16($fp)
lw $2,12($fp)
nop
slt $2,$2,$3
beq $2,$0,$L2
nop
lw $3,16($fp)
lw $2,12($fp)
nop
addu $2,$3,$2
sw $2,16($fp)
lw $3,16($fp)
lw $2,12($fp)
nop
subu $2,$3,$2
sw $2,12($fp)
lw $3,16($fp)
lw $2,12($fp)
nop
subu $2,$3,$2
sw $2,16($fp)
$L2:
lw $3,16($fp)
lw $2,8($fp)
nop
slt $2,$2,$3
beq $2,$0,$L3
nop
lw $3,16($fp)
lw $2,8($fp)
nop
addu $2,$3,$2
sw $2,16($fp)
lw $3,16($fp)
lw $2,8($fp)
nop
subu $2,$3,$2
sw $2,8($fp)
lw $3,16($fp)
lw $2,8($fp)
nop
subu $2,$3,$2
sw $2,16($fp)
$L3:
lw $3,12($fp)
lw $2,8($fp)
nop
slt $2,$2,$3
beq $2,$0,$L4
nop
lw $3,12($fp)
lw $2,8($fp)
nop
addu $2,$3,$2
sw $2,12($fp)
lw $3,12($fp)
lw $2,8($fp)
nop
subu $2,$3,$2
sw $2,8($fp)
lw $3,12($fp)
lw $2,8($fp)
nop
subu $2,$3,$2
sw $2,12($fp)
$L4:
move $2,$0
move $sp,$fp
lw $fp,28($sp)
addiu $sp,$sp,32
j $31
nop
.set macro
.set reorder
.end main
$LFE0:
.size main, .-main
.ident "GCC: (Debian 4.4.5-8) 4.4.5"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.