Write MIPS assembly language functions to implement bubble sort. you will create
ID: 3582091 • Letter: W
Question
Write MIPS assembly language functions to implement bubble sort. you will create a recursive function that pulls off the first number from the array until there is only one number left in the array. Since an array with only one number is sorted, the algorithm is then automatically successful. As you backtrack through the recursion, at each stage, you’ll get one number that needs to be bubble sorted into the sorted array. So, you will want a loop to shift the number down the array until it gets to where it belongs.
Explanation / Answer
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.rdata
.align 2
$LC0:
.ascii "Enter number of elements"
.align 2
$LC1:
.ascii "%d"
.align 2
$LC2:
.ascii "Enter %d integers
"
.align 2
$LC3:
.ascii "Sorted list in ascending order:"
.align 2
$LC4:
.ascii "%d
"
.text
.align 2
.globl main
$LFB0 = .
.set nomips16
.ent main
.type main, @function
main:
.frame $fp,448,$31 # vars= 416, regs= 2/0, args= 16, gp= 8
.mask 0xc0000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-448
$LCFI0:
sw $31,444($sp)
$LCFI1:
sw $fp,440($sp)
movz $31,$31,$0
$LCFI2:
move $fp,$sp
$LCFI3:
.cprestore 16
lw $2,%got($LC0)($28)
nop
addiu $4,$2,%lo($LC0)
lw $2,%call16(puts)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
addiu $2,$fp,36
lw $3,%got($LC1)($28)
nop
addiu $4,$3,%lo($LC1)
move $5,$2
lw $2,%call16(scanf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
lw $2,36($fp)
lw $3,%got($LC2)($28)
nop
addiu $4,$3,%lo($LC2)
move $5,$2
lw $2,%call16(printf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sw $0,32($fp)
b $L2
nop
$L3:
lw $2,32($fp)
addiu $3,$fp,40
sll $2,$2,2
addu $2,$3,$2
lw $3,%got($LC1)($28)
nop
addiu $4,$3,%lo($LC1)
move $5,$2
lw $2,%call16(scanf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
lw $2,32($fp)
nop
addiu $2,$2,1
sw $2,32($fp)
$L2:
lw $2,36($fp)
lw $3,32($fp)
nop
slt $2,$3,$2
andi $2,$2,0x00ff
bne $2,$0,$L3
nop
sw $0,32($fp)
b $L4
nop
$L8:
sw $0,28($fp)
b $L5
nop
$L7:
lw $2,28($fp)
nop
sll $2,$2,2
addiu $3,$fp,24
addu $2,$3,$2
lw $3,16($2)
lw $2,28($fp)
nop
addiu $2,$2,1
sll $2,$2,2
addiu $4,$fp,24
addu $2,$4,$2
lw $2,16($2)
nop
slt $2,$2,$3
beq $2,$0,$L6
nop
lw $2,28($fp)
nop
sll $2,$2,2
addiu $3,$fp,24
addu $2,$3,$2
lw $2,16($2)
nop
sw $2,24($fp)
lw $4,28($fp)
lw $2,28($fp)
nop
addiu $2,$2,1
sll $2,$2,2
addiu $3,$fp,24
addu $2,$3,$2
lw $3,16($2)
sll $2,$4,2
addiu $4,$fp,24
addu $2,$4,$2
sw $3,16($2)
lw $2,28($fp)
nop
addiu $2,$2,1
sll $2,$2,2
addiu $3,$fp,24
addu $2,$3,$2
lw $3,24($fp)
nop
sw $3,16($2)
$L6:
lw $2,28($fp)
nop
addiu $2,$2,1
sw $2,28($fp)
$L5:
lw $3,36($fp)
lw $2,32($fp)
nop
subu $2,$3,$2
addiu $3,$2,-1
lw $2,28($fp)
nop
slt $2,$2,$3
andi $2,$2,0x00ff
bne $2,$0,$L7
nop
lw $2,32($fp)
nop
addiu $2,$2,1
sw $2,32($fp)
$L4:
lw $2,36($fp)
nop
addiu $3,$2,-1
lw $2,32($fp)
nop
slt $2,$2,$3
andi $2,$2,0x00ff
bne $2,$0,$L8
nop
lw $2,%got($LC3)($28)
nop
addiu $4,$2,%lo($LC3)
lw $2,%call16(puts)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
sw $0,32($fp)
b $L9
nop
$L10:
lw $2,32($fp)
nop
sll $2,$2,2
addiu $3,$fp,24
addu $2,$3,$2
lw $2,16($2)
lw $3,%got($LC4)($28)
nop
addiu $4,$3,%lo($LC4)
move $5,$2
lw $2,%call16(printf)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
lw $2,32($fp)
nop
addiu $2,$2,1
sw $2,32($fp)
$L9:
lw $2,36($fp)
lw $3,32($fp)
nop
slt $2,$3,$2
andi $2,$2,0x00ff
bne $2,$0,$L10
nop
move $2,$0
move $sp,$fp
lw $31,444($sp)
lw $fp,440($sp)
addiu $sp,$sp,448
j $31
nop
.set macro
.set reorder
.end main
$LFE0:
.size main, .-main
.section .eh_frame,"aw",@progbits
$Lframe1:
.4byte $LECIE1-$LSCIE1
$LSCIE1:
.4byte 0x0
.byte 0x1
.globl __gxx_personality_v0
.ascii "zP"
.uleb128 0x1
.sleb128 -4
.byte 0x1f
.uleb128 0x5
.byte 0x0
.4byte __gxx_personality_v0
.byte 0xc
.uleb128 0x1d
.uleb128 0x0
.align 2
$LECIE1:
$LSFDE1:
.4byte $LEFDE1-$LASFDE1
$LASFDE1:
.4byte $LASFDE1-$Lframe1
.4byte $LFB0
.4byte $LFE0-$LFB0
.uleb128 0x0
.byte 0x4
.4byte $LCFI0-$LFB0
.byte 0xe
.uleb128 0x1c0
.byte 0x4
.4byte $LCFI2-$LCFI0
.byte 0x11
.uleb128 0x1e
.sleb128 2
.byte 0x11
.uleb128 0x1f
.sleb128 1
.byte 0x4
.4byte $LCFI3-$LCFI2
.byte 0xd
.uleb128 0x1e
.align 2
$LEFDE1:
.ident "GCC: (Debian 4.4.5-8) 4.4.5"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.