? Write a MIPS assembly language function, shellSort() , to sort the volumes int
ID: 3709077 • Letter: #
Question
? Write a MIPS assembly language function, shellSort(), to sort the volumes into ascending order (small to large). To sort the numbers, use the following Shell Sort2 algorithm.
h = 3 * h + 1;
}
h = h / 3;
}
Note, the algorithm assumes array index’s start at 0. As necessary, you can define additional variables.
# ---------------------------------------------------------------------------
# Arguments:
# $a0 - starting address of the list
# $a1 - list length
# Returns:
# sorted list (via reference)
.globl shellSort
.ent shellSort
shellSort:
Explanation / Answer
Here is the code of MIPS assembly language function for ShellSort():
shellsort:
.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
sw $fp,28($sp)
move $fp,$sp
sw $4,32($fp)
sw $5,36($fp)
movz $31,$31,$0
li $2,1 # 0x1
sw $2,8($fp)
b $L2
nop
$L3:
lw $3,8($fp)
nop
move $2,$3
sll $2,$2,1
addu $2,$2,$3
addiu $2,$2,1
sw $2,8($fp)
$L2:
lw $3,8($fp)
nop
move $2,$3
sll $2,$2,1
addu $2,$2,$3
addiu $3,$2,1
lw $2,36($fp)
nop
slt $2,$3,$2
bne $2,$0,$L3
nop
b $L4
nop
$L10:
lw $2,8($fp)
nop
addiu $2,$2,-1
sw $2,12($fp)
b $L5
nop
$L9:
lw $2,12($fp)
nop
sll $2,$2,2
lw $3,32($fp)
nop
addu $2,$3,$2
lw $2,0($2)
nop
sw $2,20($fp)
lw $2,12($fp)
nop
sw $2,16($fp)
lw $2,12($fp)
nop
sw $2,16($fp)
b $L6
nop
$L8:
lw $2,16($fp)
nop
sll $2,$2,2
lw $3,32($fp)
nop
addu $2,$3,$2
lw $4,16($fp)
lw $3,8($fp)
nop
subu $3,$4,$3
sll $3,$3,2
lw $4,32($fp)
nop
addu $3,$4,$3
lw $3,0($3)
nop
sw $3,0($2)
lw $3,16($fp)
lw $2,8($fp)
nop
subu $2,$3,$2
sw $2,16($fp)
$L6:
lw $3,16($fp)
lw $2,8($fp)
nop
slt $2,$3,$2
bne $2,$0,$L7
nop
lw $3,16($fp)
lw $2,8($fp)
nop
subu $2,$3,$2
sll $2,$2,2
lw $3,32($fp)
nop
addu $2,$3,$2
lw $3,0($2)
lw $2,20($fp)
nop
slt $2,$2,$3
bne $2,$0,$L8
nop
$L7:
lw $2,16($fp)
nop
sll $2,$2,2
lw $3,32($fp)
nop
addu $2,$3,$2
lw $3,20($fp)
nop
sw $3,0($2)
lw $2,12($fp)
nop
addiu $2,$2,1
sw $2,12($fp)
$L5:
lw $3,12($fp)
lw $2,36($fp)
nop
slt $2,$3,$2
bne $2,$0,$L9
nop
lw $3,8($fp)
li $2,3 # 0x3
bne $2,$0,1f
div $0,$3,$2
break 7
1:
mfhi $2
mflo $2
sw $2,8($fp)
$L4:
lw $2,8($fp)
nop
bgtz $2,$L10
nop
nop
move $sp,$fp
lw $fp,28($sp)
addiu $sp,$sp,32
j $31
nop
.set macro
.set reorder
.end shellsort
.size shellsort, .-shellsort
.rdata
.align 2
$LC0:
.ascii "%d"
.text
.align 2
.globl main
.set nomips16
.set nomicromips
.ent main
.type main, @function
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.