.macro SAVE_T_REGISTERS
# brace yourself for a long, unrolled loop...
sw $t0, ($sp)
subiu $sp, $sp, 4
sw $t1, ($sp)
subiu $sp, $sp, 4
sw $t2, ($sp)
subiu $sp, $sp, 4
sw $t3, ($sp)
subiu $sp, $sp, 4
sw $t4, ($sp)
subiu $sp, $sp, 4
sw $t5, ($sp)
subiu $sp, $sp, 4
sw $t6, ($sp)
subiu $sp, $sp, 4
sw $t7, ($sp)
subiu $sp, $sp, 4
sw $t8, ($sp)
subiu $sp, $sp, 4
sw $t9, ($sp)
subiu $sp, $sp, 4
.end_macro
.macro RESTORE_T_REGISTERS
# brace yourself for a long, unrolled loop...
addiu $sp, $sp, 4
lw $t9, ($sp)
addiu $sp, $sp, 4
lw $t8, ($sp)
addiu $sp, $sp, 4
lw $t7, ($sp)
addiu $sp, $sp, 4
lw $t6, ($sp)
addiu $sp, $sp, 4
lw $t5, ($sp)
addiu $sp, $sp, 4
lw $t4, ($sp)
addiu $sp, $sp, 4
lw $t3, ($sp)
addiu $sp, $sp, 4
lw $t2, ($sp)
addiu $sp, $sp, 4
lw $t1, ($sp)
addiu $sp, $sp, 4
lw $t0, ($sp)
.end_macro
.macro SAVE_SPILL_MEM
# brace yourself for a long, unrolled loop...
lw $a3, SPILL_MEMORY
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 4
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 8
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 12
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 16
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 20
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 24
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 28
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 32
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 36
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 40
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 44
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 48
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 52
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 56
sw $a3, ($sp)
subiu $sp, $sp, 4
lw $a3, SPILL_MEMORY + 60
sw $a3, ($sp)
subiu $sp, $sp, 4
.end_macro
.macro RESTORE_SPILL_MEM
# brace yourself for a long, unrolled loop...
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 60
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 56
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 52
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 48
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 44
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 40
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 36
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 32
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 28
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 24
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 20
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 16
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 12
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 8
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY + 4
addiu $sp, $sp, 4
lw $a3, ($sp)
sw $a3, SPILL_MEMORY
.end_macro
.macro CALLEE_FUNCTION_PROLOGUE (%variable_size)
# set $fp to the proper spot by recovering the value from $a0
add $fp, $a0, $zero
# allocate stack space for variables ($sp = $sp - space for variables)
li $a0, 4
mulu $a1, $a0, %variable_size
sub $sp, $sp, $a1
.end_macro
.macro CALLEE_FUNCTION_EPILOGUE
# de-allocate the memory used for local variables and parameters
add $sp, $fp, $zero
# jump back to the caller
jr $ra
.end_macro
.macro CALLER_FUNCTION_PROLOGUE
# caller should save it's own $ra, $fp, and registers
sw $ra, ($sp)
subiu $sp, $sp, 4
sw $fp, ($sp)
subiu $sp, $sp, 4
# caller pushes registers and spill memory onto the stack as well
SAVE_T_REGISTERS()
SAVE_SPILL_MEM()
# save the value of $sp here into $a0 as temporary storage until the arguments are moved
# $fp needs to stay where it's at while the arguments are copied after this macro
add $a0, $sp, $zero
.end_macro
.macro CALLER_FUNCTION_EPILOGUE
# recover the spill memory and the stored registers
RESTORE_SPILL_MEM()
RESTORE_T_REGISTERS()
# recover the caller's $fp and $ra
addiu $sp, $sp, 4
lw $fp, ($sp)
addiu $sp, $sp, 4
lw $ra, ($sp)
.end_macro
.macro __LAND (%lhs, %rhs)
beqz %lhs, __LAND_FALSE
beqz %rhs, __LAND_FALSE
li $a2, 1
j __LAND_END
__LAND_FALSE:
li $a2, 0
__LAND_END:
.end_macro
.macro __LOR (%lhs, %rhs)
beqz %lhs, __LOR_TRUE
beqz %rhs, __LOR_TRUE
li $a2, 0
j __LOR_END
__LOR_TRUE:
li $a2, 1
__LOR_END:
.end_macro
.data
SPILL_MEMORY: .space 64
N_ITEMS: .word 5
.text
add $fp, $sp, $zero
add $a0, $fp, $zero
jal main
j PROG_END
bubble_sort:
CALLEE_FUNCTION_PROLOGUE(3)
CALLER_FUNCTION_PROLOGUE()
li $t0, 0
mul $t0, $t0, 4
lw $t1, ($fp)
lw $t2, -4($fp)
sub $t2, $t1, $t2
sub $t0, $t1, $t0
tlt $t1, $t0
tge $t2, $t0
lw $t0, ($t0)
sw $t0, ($sp)
sub $sp, $sp, 4
jal print_int
CALLER_FUNCTION_EPILOGUE()
add $t0, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t0, 10
sw $t0, ($sp)
sub $sp, $sp, 4
jal print_char
CALLER_FUNCTION_EPILOGUE()
add $t0, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t0, 1
mul $t0, $t0, 4
lw $t2, ($fp)
lw $t1, -4($fp)
sub $t1, $t2, $t1
sub $t0, $t2, $t0
tlt $t2, $t0
tge $t1, $t0
lw $t0, ($t0)
sw $t0, ($sp)
sub $sp, $sp, 4
jal print_int
CALLER_FUNCTION_EPILOGUE()
add $t0, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t0, 10
sw $t0, ($sp)
sub $sp, $sp, 4
jal print_char
CALLER_FUNCTION_EPILOGUE()
add $t0, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t0, 2
mul $t0, $t0, 4
lw $t1, ($fp)
lw $t2, -4($fp)
sub $t2, $t1, $t2
sub $t0, $t1, $t0
tlt $t1, $t0
tge $t2, $t0
lw $t0, ($t0)
sw $t0, ($sp)
sub $sp, $sp, 4
jal print_int
CALLER_FUNCTION_EPILOGUE()
add $t0, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t0, 10
sw $t0, ($sp)
sub $sp, $sp, 4
jal print_char
CALLER_FUNCTION_EPILOGUE()
add $t0, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t0, 3
mul $t0, $t0, 4
lw $t2, ($fp)
lw $t1, -4($fp)
sub $t1, $t2, $t1
sub $t0, $t2, $t0
tlt $t2, $t0
tge $t1, $t0
lw $t0, ($t0)
sw $t0, ($sp)
sub $sp, $sp, 4
jal print_int
CALLER_FUNCTION_EPILOGUE()
add $t0, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t0, 10
sw $t0, ($sp)
sub $sp, $sp, 4
jal print_char
CALLER_FUNCTION_EPILOGUE()
add $t0, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t0, 4
mul $t0, $t0, 4
lw $t1, ($fp)
lw $t2, -4($fp)
sub $t2, $t1, $t2
sub $t0, $t1, $t0
tlt $t1, $t0
tge $t2, $t0
lw $t0, ($t0)
sw $t0, ($sp)
sub $sp, $sp, 4
jal print_int
CALLER_FUNCTION_EPILOGUE()
add $t0, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t0, 10
sw $t0, ($sp)
sub $sp, $sp, 4
jal print_char
CALLER_FUNCTION_EPILOGUE()
add $t0, $v0, $zero
la $t0, -12($fp)
li $t2, 0
sw $t2, ($t0)
LOOP_CONDITION_00000:
lw $t2, -12($fp)
li $t0, 5
lw $t0, N_ITEMS
slt $t1, $t2, $t0
bne $t1, $zero, LOOP_BODY_00000
j LOOP_EXIT_00000
LOOP_BODY_00000:
la $t0, -16($fp)
lw $t2, -12($fp)
sw $t2, ($t0)
LOOP_CONDITION_00001:
lw $t2, -16($fp)
li $t0, 5
lw $t0, N_ITEMS
slt $t3, $t2, $t0
bne $t3, $zero, LOOP_BODY_00001
j LOOP_EXIT_00001
LOOP_BODY_00001:
lw $t0, -12($fp)
mul $t0, $t0, 4
lw $t2, ($fp)
lw $t4, -4($fp)
sub $t4, $t2, $t4
sub $t0, $t2, $t0
tlt $t2, $t0
tge $t4, $t0
lw $t0, ($t0)
lw $t4, -16($fp)
mul $t4, $t4, 4
lw $t2, ($fp)
lw $t5, -4($fp)
sub $t5, $t2, $t5
sub $t4, $t2, $t4
tlt $t2, $t4
tge $t5, $t4
lw $t4, ($t4)
slt $t5, $t0, $t4
bne $t5, $zero, IF_TRUE_00000
IF_FALSE_00000:
j ENDIF_00000
IF_TRUE_00000:
la $t4, -20($fp)
lw $t0, -12($fp)
mul $t0, $t0, 4
lw $t2, ($fp)
lw $t6, -4($fp)
sub $t6, $t2, $t6
sub $t0, $t2, $t0
tlt $t2, $t0
tge $t6, $t0
lw $t0, ($t0)
sw $t0, ($t4)
lw $t0, -12($fp)
mul $t0, $t0, 4
lw $t4, ($fp)
lw $t6, -4($fp)
sub $t6, $t4, $t6
sub $t0, $t4, $t0
tlt $t4, $t0
tge $t6, $t0
lw $t6, -16($fp)
mul $t6, $t6, 4
lw $t4, ($fp)
lw $t2, -4($fp)
sub $t2, $t4, $t2
sub $t6, $t4, $t6
tlt $t4, $t6
tge $t2, $t6
lw $t6, ($t6)
sw $t6, ($t0)
lw $t6, -16($fp)
mul $t6, $t6, 4
lw $t0, ($fp)
lw $t2, -4($fp)
sub $t2, $t0, $t2
sub $t6, $t0, $t6
tlt $t0, $t6
tge $t2, $t6
lw $t2, -20($fp)
sw $t2, ($t6)
ENDIF_00000:
la $t5, -16($fp)
lw $t2, ($t5)
add $t6, $t2, $zero
addiu $t2, $t2, 1
sw $t2, ($t5)
j LOOP_CONDITION_00001
LOOP_EXIT_00001:
la $t6, -12($fp)
lw $t2, ($t6)
add $t5, $t2, $zero
addiu $t2, $t2, 1
sw $t2, ($t6)
j LOOP_CONDITION_00000
LOOP_EXIT_00000:
CALLER_FUNCTION_PROLOGUE()
li $t5, 10
sw $t5, ($sp)
sub $sp, $sp, 4
jal print_char
CALLER_FUNCTION_EPILOGUE()
add $t5, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t5, 0
mul $t5, $t5, 4
lw $t2, ($fp)
lw $t6, -4($fp)
sub $t6, $t2, $t6
sub $t5, $t2, $t5
tlt $t2, $t5
tge $t6, $t5
lw $t5, ($t5)
sw $t5, ($sp)
sub $sp, $sp, 4
jal print_int
CALLER_FUNCTION_EPILOGUE()
add $t5, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t5, 10
sw $t5, ($sp)
sub $sp, $sp, 4
jal print_char
CALLER_FUNCTION_EPILOGUE()
add $t5, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t5, 1
mul $t5, $t5, 4
lw $t6, ($fp)
lw $t2, -4($fp)
sub $t2, $t6, $t2
sub $t5, $t6, $t5
tlt $t6, $t5
tge $t2, $t5
lw $t5, ($t5)
sw $t5, ($sp)
sub $sp, $sp, 4
jal print_int
CALLER_FUNCTION_EPILOGUE()
add $t5, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t5, 10
sw $t5, ($sp)
sub $sp, $sp, 4
jal print_char
CALLER_FUNCTION_EPILOGUE()
add $t5, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t5, 2
mul $t5, $t5, 4
lw $t2, ($fp)
lw $t6, -4($fp)
sub $t6, $t2, $t6
sub $t5, $t2, $t5
tlt $t2, $t5
tge $t6, $t5
lw $t5, ($t5)
sw $t5, ($sp)
sub $sp, $sp, 4
jal print_int
CALLER_FUNCTION_EPILOGUE()
add $t5, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t5, 10
sw $t5, ($sp)
sub $sp, $sp, 4
jal print_char
CALLER_FUNCTION_EPILOGUE()
add $t5, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t5, 3
mul $t5, $t5, 4
lw $t6, ($fp)
lw $t2, -4($fp)
sub $t2, $t6, $t2
sub $t5, $t6, $t5
tlt $t6, $t5
tge $t2, $t5
lw $t5, ($t5)
sw $t5, ($sp)
sub $sp, $sp, 4
jal print_int
CALLER_FUNCTION_EPILOGUE()
add $t5, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t5, 10
sw $t5, ($sp)
sub $sp, $sp, 4
jal print_char
CALLER_FUNCTION_EPILOGUE()
add $t5, $v0, $zero
CALLER_FUNCTION_PROLOGUE()
li $t5, 4
mul $t5, $t5, 4
lw $t2, ($fp)
lw $t6, -4($fp)
sub $t6, $t2, $t6
sub $t5, $t2, $t5
tlt $t2, $t5
tge $t6, $t5
lw $t5, ($t5)
sw $t5, ($sp)
sub $sp, $sp, 4
jal print_int
CALLER_FUNCTION_EPILOGUE()
add $t5, $v0, $zero
CALLEE_FUNCTION_EPILOGUE()
main:
CALLEE_FUNCTION_PROLOGUE(5)
la $t1, ($fp)
li $t3, 5
sw $t3, ($t1)
addi $t1, $t1, -4
li $t3, 1
sw $t3, ($t1)
addi $t1, $t1, -4
li $t3, 4
sw $t3, ($t1)
addi $t1, $t1, -4
li $t3, 3
sw $t3, ($t1)
addi $t1, $t1, -4
li $t3, 2
sw $t3, ($t1)
addi $t1, $t1, -4
CALLER_FUNCTION_PROLOGUE()
lw $t1, ($fp)
la $t1, ($fp)
sw $t1, ($sp)
sub $sp, $sp, 4
li $t1, 20
sw $t1, ($sp)
sub $sp, $sp, 4
li $t1, 5
sw $t1, ($sp)
sub $sp, $sp, 4
jal bubble_sort
CALLER_FUNCTION_EPILOGUE()
add $t1, $v0, $zero
li $t1, 0
add $v0, $t1, $zero
CALLEE_FUNCTION_EPILOGUE()
CALLEE_FUNCTION_EPILOGUE()
print_char:
CALLEE_FUNCTION_PROLOGUE(0)
# load $v0 with the value for the print char syscall
li $v0, 11
# the first (and only) argument is the value to print
lw $a0, ($fp)
syscall
CALLEE_FUNCTION_EPILOGUE()
print_int:
CALLEE_FUNCTION_PROLOGUE(0)
# load $v0 with the value for the print int syscall
li $v0, 1
# the first (and only) argument is the value to print
lw $a0, ($fp)
syscall
CALLEE_FUNCTION_EPILOGUE()
print_string:
CALLEE_FUNCTION_PROLOGUE(0)
# load $v0 with the value for the print string syscall
li $v0, 4
# the first (and only) argument is the base address of the null terminated ascii string
la $a0, ($fp)
syscall
CALLEE_FUNCTION_EPILOGUE()
print_float:
CALLEE_FUNCTION_PROLOGUE(0)
# load $v0 with the value for the print float syscall
li $v0, 2
# the first (and only) argument is the base address of the null terminated ascii string
lwc1 $f12, ($fp)
syscall
CALLEE_FUNCTION_EPILOGUE()
PROG_END:
add $a0, $v0, $zero
li $v0, 17
syscall
Bubble Sort
Input
const int N_ITEMS = 5;
int bubble_sort(int things[])
{
int i, j, temp;
print_int(things[0]); // expect to see 5
print_char('\n');
print_int(things[1]); // expect to see 1
print_char('\n');
print_int(things[2]); // expect to see 4
print_char('\n');
print_int(things[3]); // expect to see 3
print_char('\n');
print_int(things[4]); // expect to see 2
print_char('\n');
for (i = 0; i < N_ITEMS; i++) {
for (j = i; j < N_ITEMS; j++) {
if (things[i] < things[j]) {
temp = things[i];
things[i] = things[j];
things[j] = temp;
}
}
}
print_char('\n');
print_int(things[0]); // expect to see 5
print_char('\n');
print_int(things[1]); // expect to see 4
print_char('\n');
print_int(things[2]); // expect to see 3
print_char('\n');
print_int(things[3]); // expect to see 2
print_char('\n');
print_int(things[4]); // expect to see 1
}
int main() {
int things[N_ITEMS] = {5, 1, 4, 3, 2};
bubble_sort(things);
return 0;
}
MIPS
Output
5
1
4
3
2
5
4
3
2
1
3AC (Three-Address Code)
.data
GLOBLDECL , N_ITEMS , .word , 5
.text
JAL , main , - , -
BR , PROG_END , - , -
bubble_sort:
PROCENTRY , 12 , - , -
CALL_PROC , print_int , 0 , -
LI , ireg_00001 , 0 , -
MUL , ireg_00001 , ireg_00001 , 4
LOAD , ireg_00002 , ($FP) , 4
LOAD , ireg_00003 , -4($FP) , 4
SUB , ireg_00003 , ireg_00002 , ireg_00003
SUB , ireg_00001 , ireg_00002 , ireg_00001
BOUND , ireg_00001 , ireg_00002 , ireg_00003
KICK , ireg_00002 , - , -
KICK , ireg_00003 , - , -
LOAD , ireg_00001 , (ireg_00001) , 4
STORE , ireg_00001 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00001 , - , -
JAL , print_int , - , -
END_PROC , 0 , - , -
ADD , ireg_00000 , $RV , $ZERO
KICK , ireg_00000 , - , -
CALL_PROC , print_char , 0 , -
LI , ireg_00005 , 10 , -
STORE , ireg_00005 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00005 , - , -
JAL , print_char , - , -
END_PROC , 0 , - , -
ADD , ireg_00004 , $RV , $ZERO
KICK , ireg_00004 , - , -
CALL_PROC , print_int , 0 , -
LI , ireg_00007 , 1 , -
MUL , ireg_00007 , ireg_00007 , 4
LOAD , ireg_00008 , ($FP) , 4
LOAD , ireg_00009 , -4($FP) , 4
SUB , ireg_00009 , ireg_00008 , ireg_00009
SUB , ireg_00007 , ireg_00008 , ireg_00007
BOUND , ireg_00007 , ireg_00008 , ireg_00009
KICK , ireg_00008 , - , -
KICK , ireg_00009 , - , -
LOAD , ireg_00007 , (ireg_00007) , 4
STORE , ireg_00007 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00007 , - , -
JAL , print_int , - , -
END_PROC , 0 , - , -
ADD , ireg_00006 , $RV , $ZERO
KICK , ireg_00006 , - , -
CALL_PROC , print_char , 0 , -
LI , ireg_00011 , 10 , -
STORE , ireg_00011 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00011 , - , -
JAL , print_char , - , -
END_PROC , 0 , - , -
ADD , ireg_00010 , $RV , $ZERO
KICK , ireg_00010 , - , -
CALL_PROC , print_int , 0 , -
LI , ireg_00013 , 2 , -
MUL , ireg_00013 , ireg_00013 , 4
LOAD , ireg_00014 , ($FP) , 4
LOAD , ireg_00015 , -4($FP) , 4
SUB , ireg_00015 , ireg_00014 , ireg_00015
SUB , ireg_00013 , ireg_00014 , ireg_00013
BOUND , ireg_00013 , ireg_00014 , ireg_00015
KICK , ireg_00014 , - , -
KICK , ireg_00015 , - , -
LOAD , ireg_00013 , (ireg_00013) , 4
STORE , ireg_00013 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00013 , - , -
JAL , print_int , - , -
END_PROC , 0 , - , -
ADD , ireg_00012 , $RV , $ZERO
KICK , ireg_00012 , - , -
CALL_PROC , print_char , 0 , -
LI , ireg_00017 , 10 , -
STORE , ireg_00017 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00017 , - , -
JAL , print_char , - , -
END_PROC , 0 , - , -
ADD , ireg_00016 , $RV , $ZERO
KICK , ireg_00016 , - , -
CALL_PROC , print_int , 0 , -
LI , ireg_00019 , 3 , -
MUL , ireg_00019 , ireg_00019 , 4
LOAD , ireg_00020 , ($FP) , 4
LOAD , ireg_00021 , -4($FP) , 4
SUB , ireg_00021 , ireg_00020 , ireg_00021
SUB , ireg_00019 , ireg_00020 , ireg_00019
BOUND , ireg_00019 , ireg_00020 , ireg_00021
KICK , ireg_00020 , - , -
KICK , ireg_00021 , - , -
LOAD , ireg_00019 , (ireg_00019) , 4
STORE , ireg_00019 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00019 , - , -
JAL , print_int , - , -
END_PROC , 0 , - , -
ADD , ireg_00018 , $RV , $ZERO
KICK , ireg_00018 , - , -
CALL_PROC , print_char , 0 , -
LI , ireg_00023 , 10 , -
STORE , ireg_00023 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00023 , - , -
JAL , print_char , - , -
END_PROC , 0 , - , -
ADD , ireg_00022 , $RV , $ZERO
KICK , ireg_00022 , - , -
CALL_PROC , print_int , 0 , -
LI , ireg_00025 , 4 , -
MUL , ireg_00025 , ireg_00025 , 4
LOAD , ireg_00026 , ($FP) , 4
LOAD , ireg_00027 , -4($FP) , 4
SUB , ireg_00027 , ireg_00026 , ireg_00027
SUB , ireg_00025 , ireg_00026 , ireg_00025
BOUND , ireg_00025 , ireg_00026 , ireg_00027
KICK , ireg_00026 , - , -
KICK , ireg_00027 , - , -
LOAD , ireg_00025 , (ireg_00025) , 4
STORE , ireg_00025 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00025 , - , -
JAL , print_int , - , -
END_PROC , 0 , - , -
ADD , ireg_00024 , $RV , $ZERO
KICK , ireg_00024 , - , -
CALL_PROC , print_char , 0 , -
LI , ireg_00029 , 10 , -
STORE , ireg_00029 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00029 , - , -
JAL , print_char , - , -
END_PROC , 0 , - , -
ADD , ireg_00028 , $RV , $ZERO
KICK , ireg_00028 , - , -
LA , ireg_00030 , -12($FP) , -
LI , ireg_00031 , 0 , -
STORE , ireg_00031 , (ireg_00030) , 4
KICK , ireg_00030 , - , -
KICK , ireg_00031 , - , -
LOOP_CONDITION_00000:
LOAD , ireg_00032 , -12($FP) , 4
LI , ireg_00033 , 5 , -
LOAD , ireg_00033 , N_ITEMS , 4
LT , ireg_00034 , ireg_00032 , ireg_00033
KICK , ireg_00032 , - , -
KICK , ireg_00033 , - , -
BRNE , LOOP_BODY_00000, ireg_00034 , $ZERO
BR , LOOP_EXIT_00000, - , -
LOOP_BODY_00000:
LA , ireg_00035 , -16($FP) , -
LOAD , ireg_00036 , -12($FP) , 4
STORE , ireg_00036 , (ireg_00035) , 4
KICK , ireg_00035 , - , -
KICK , ireg_00036 , - , -
LOOP_CONDITION_00001:
LOAD , ireg_00037 , -16($FP) , 4
LI , ireg_00038 , 5 , -
LOAD , ireg_00038 , N_ITEMS , 4
LT , ireg_00039 , ireg_00037 , ireg_00038
KICK , ireg_00037 , - , -
KICK , ireg_00038 , - , -
BRNE , LOOP_BODY_00001, ireg_00039 , $ZERO
BR , LOOP_EXIT_00001, - , -
LOOP_BODY_00001:
LOAD , ireg_00040 , -12($FP) , 4
MUL , ireg_00040 , ireg_00040 , 4
LOAD , ireg_00041 , ($FP) , 4
LOAD , ireg_00042 , -4($FP) , 4
SUB , ireg_00042 , ireg_00041 , ireg_00042
SUB , ireg_00040 , ireg_00041 , ireg_00040
BOUND , ireg_00040 , ireg_00041 , ireg_00042
KICK , ireg_00041 , - , -
KICK , ireg_00042 , - , -
LOAD , ireg_00040 , (ireg_00040) , 4
LOAD , ireg_00043 , -16($FP) , 4
MUL , ireg_00043 , ireg_00043 , 4
LOAD , ireg_00044 , ($FP) , 4
LOAD , ireg_00045 , -4($FP) , 4
SUB , ireg_00045 , ireg_00044 , ireg_00045
SUB , ireg_00043 , ireg_00044 , ireg_00043
BOUND , ireg_00043 , ireg_00044 , ireg_00045
KICK , ireg_00044 , - , -
KICK , ireg_00045 , - , -
LOAD , ireg_00043 , (ireg_00043) , 4
LT , ireg_00046 , ireg_00040 , ireg_00043
KICK , ireg_00040 , - , -
KICK , ireg_00043 , - , -
BRNE , IF_TRUE_00000 , ireg_00046 , $ZERO
IF_FALSE_00000:
BR , ENDIF_00000 , - , -
IF_TRUE_00000:
LA , ireg_00047 , -20($FP) , -
LOAD , ireg_00048 , -12($FP) , 4
MUL , ireg_00048 , ireg_00048 , 4
LOAD , ireg_00049 , ($FP) , 4
LOAD , ireg_00050 , -4($FP) , 4
SUB , ireg_00050 , ireg_00049 , ireg_00050
SUB , ireg_00048 , ireg_00049 , ireg_00048
BOUND , ireg_00048 , ireg_00049 , ireg_00050
KICK , ireg_00049 , - , -
KICK , ireg_00050 , - , -
LOAD , ireg_00048 , (ireg_00048) , 4
STORE , ireg_00048 , (ireg_00047) , 4
KICK , ireg_00047 , - , -
KICK , ireg_00048 , - , -
LOAD , ireg_00051 , -12($FP) , 4
MUL , ireg_00051 , ireg_00051 , 4
LOAD , ireg_00052 , ($FP) , 4
LOAD , ireg_00053 , -4($FP) , 4
SUB , ireg_00053 , ireg_00052 , ireg_00053
SUB , ireg_00051 , ireg_00052 , ireg_00051
BOUND , ireg_00051 , ireg_00052 , ireg_00053
KICK , ireg_00052 , - , -
KICK , ireg_00053 , - , -
LOAD , ireg_00054 , -16($FP) , 4
MUL , ireg_00054 , ireg_00054 , 4
LOAD , ireg_00055 , ($FP) , 4
LOAD , ireg_00056 , -4($FP) , 4
SUB , ireg_00056 , ireg_00055 , ireg_00056
SUB , ireg_00054 , ireg_00055 , ireg_00054
BOUND , ireg_00054 , ireg_00055 , ireg_00056
KICK , ireg_00055 , - , -
KICK , ireg_00056 , - , -
LOAD , ireg_00054 , (ireg_00054) , 4
STORE , ireg_00054 , (ireg_00051) , 4
KICK , ireg_00051 , - , -
KICK , ireg_00054 , - , -
LOAD , ireg_00057 , -16($FP) , 4
MUL , ireg_00057 , ireg_00057 , 4
LOAD , ireg_00058 , ($FP) , 4
LOAD , ireg_00059 , -4($FP) , 4
SUB , ireg_00059 , ireg_00058 , ireg_00059
SUB , ireg_00057 , ireg_00058 , ireg_00057
BOUND , ireg_00057 , ireg_00058 , ireg_00059
KICK , ireg_00058 , - , -
KICK , ireg_00059 , - , -
LOAD , ireg_00060 , -20($FP) , 4
STORE , ireg_00060 , (ireg_00057) , 4
KICK , ireg_00057 , - , -
KICK , ireg_00060 , - , -
ENDIF_00000:
KICK , ireg_00046 , - , -
LA , ireg_00061 , -16($FP) , -
LOAD , ireg_00062 , (ireg_00061) , 4
ADD , ireg_00063 , ireg_00062 , $ZERO
ADDIU , ireg_00062 , ireg_00062 , 1
STORE , ireg_00062 , (ireg_00061) , 4
KICK , ireg_00061 , - , -
KICK , ireg_00062 , - , -
KICK , ireg_00063 , - , -
BR , LOOP_CONDITION_00001, - , -
LOOP_EXIT_00001:
LA , ireg_00064 , -12($FP) , -
LOAD , ireg_00065 , (ireg_00064) , 4
ADD , ireg_00066 , ireg_00065 , $ZERO
ADDIU , ireg_00065 , ireg_00065 , 1
STORE , ireg_00065 , (ireg_00064) , 4
KICK , ireg_00064 , - , -
KICK , ireg_00065 , - , -
KICK , ireg_00066 , - , -
BR , LOOP_CONDITION_00000, - , -
LOOP_EXIT_00000:
CALL_PROC , print_char , 0 , -
LI , ireg_00068 , 10 , -
STORE , ireg_00068 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00068 , - , -
JAL , print_char , - , -
END_PROC , 0 , - , -
ADD , ireg_00067 , $RV , $ZERO
KICK , ireg_00067 , - , -
CALL_PROC , print_int , 0 , -
LI , ireg_00070 , 0 , -
MUL , ireg_00070 , ireg_00070 , 4
LOAD , ireg_00071 , ($FP) , 4
LOAD , ireg_00072 , -4($FP) , 4
SUB , ireg_00072 , ireg_00071 , ireg_00072
SUB , ireg_00070 , ireg_00071 , ireg_00070
BOUND , ireg_00070 , ireg_00071 , ireg_00072
KICK , ireg_00071 , - , -
KICK , ireg_00072 , - , -
LOAD , ireg_00070 , (ireg_00070) , 4
STORE , ireg_00070 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00070 , - , -
JAL , print_int , - , -
END_PROC , 0 , - , -
ADD , ireg_00069 , $RV , $ZERO
KICK , ireg_00069 , - , -
CALL_PROC , print_char , 0 , -
LI , ireg_00074 , 10 , -
STORE , ireg_00074 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00074 , - , -
JAL , print_char , - , -
END_PROC , 0 , - , -
ADD , ireg_00073 , $RV , $ZERO
KICK , ireg_00073 , - , -
CALL_PROC , print_int , 0 , -
LI , ireg_00076 , 1 , -
MUL , ireg_00076 , ireg_00076 , 4
LOAD , ireg_00077 , ($FP) , 4
LOAD , ireg_00078 , -4($FP) , 4
SUB , ireg_00078 , ireg_00077 , ireg_00078
SUB , ireg_00076 , ireg_00077 , ireg_00076
BOUND , ireg_00076 , ireg_00077 , ireg_00078
KICK , ireg_00077 , - , -
KICK , ireg_00078 , - , -
LOAD , ireg_00076 , (ireg_00076) , 4
STORE , ireg_00076 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00076 , - , -
JAL , print_int , - , -
END_PROC , 0 , - , -
ADD , ireg_00075 , $RV , $ZERO
KICK , ireg_00075 , - , -
CALL_PROC , print_char , 0 , -
LI , ireg_00080 , 10 , -
STORE , ireg_00080 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00080 , - , -
JAL , print_char , - , -
END_PROC , 0 , - , -
ADD , ireg_00079 , $RV , $ZERO
KICK , ireg_00079 , - , -
CALL_PROC , print_int , 0 , -
LI , ireg_00082 , 2 , -
MUL , ireg_00082 , ireg_00082 , 4
LOAD , ireg_00083 , ($FP) , 4
LOAD , ireg_00084 , -4($FP) , 4
SUB , ireg_00084 , ireg_00083 , ireg_00084
SUB , ireg_00082 , ireg_00083 , ireg_00082
BOUND , ireg_00082 , ireg_00083 , ireg_00084
KICK , ireg_00083 , - , -
KICK , ireg_00084 , - , -
LOAD , ireg_00082 , (ireg_00082) , 4
STORE , ireg_00082 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00082 , - , -
JAL , print_int , - , -
END_PROC , 0 , - , -
ADD , ireg_00081 , $RV , $ZERO
KICK , ireg_00081 , - , -
CALL_PROC , print_char , 0 , -
LI , ireg_00086 , 10 , -
STORE , ireg_00086 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00086 , - , -
JAL , print_char , - , -
END_PROC , 0 , - , -
ADD , ireg_00085 , $RV , $ZERO
KICK , ireg_00085 , - , -
CALL_PROC , print_int , 0 , -
LI , ireg_00088 , 3 , -
MUL , ireg_00088 , ireg_00088 , 4
LOAD , ireg_00089 , ($FP) , 4
LOAD , ireg_00090 , -4($FP) , 4
SUB , ireg_00090 , ireg_00089 , ireg_00090
SUB , ireg_00088 , ireg_00089 , ireg_00088
BOUND , ireg_00088 , ireg_00089 , ireg_00090
KICK , ireg_00089 , - , -
KICK , ireg_00090 , - , -
LOAD , ireg_00088 , (ireg_00088) , 4
STORE , ireg_00088 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00088 , - , -
JAL , print_int , - , -
END_PROC , 0 , - , -
ADD , ireg_00087 , $RV , $ZERO
KICK , ireg_00087 , - , -
CALL_PROC , print_char , 0 , -
LI , ireg_00092 , 10 , -
STORE , ireg_00092 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00092 , - , -
JAL , print_char , - , -
END_PROC , 0 , - , -
ADD , ireg_00091 , $RV , $ZERO
KICK , ireg_00091 , - , -
CALL_PROC , print_int , 0 , -
LI , ireg_00094 , 4 , -
MUL , ireg_00094 , ireg_00094 , 4
LOAD , ireg_00095 , ($FP) , 4
LOAD , ireg_00096 , -4($FP) , 4
SUB , ireg_00096 , ireg_00095 , ireg_00096
SUB , ireg_00094 , ireg_00095 , ireg_00094
BOUND , ireg_00094 , ireg_00095 , ireg_00096
KICK , ireg_00095 , - , -
KICK , ireg_00096 , - , -
LOAD , ireg_00094 , (ireg_00094) , 4
STORE , ireg_00094 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00094 , - , -
JAL , print_int , - , -
END_PROC , 0 , - , -
ADD , ireg_00093 , $RV , $ZERO
KICK , ireg_00093 , - , -
ENDPROC , - , - , -
main:
PROCENTRY , 32 , - , -
LA , ireg_00097 , -12($FP) , -
LI , ireg_00098 , 5 , -
STORE , ireg_00098 , (ireg_00097) , 4
KICK , ireg_00098 , - , -
ADDI , ireg_00097 , ireg_00097 , -4
LI , ireg_00099 , 1 , -
STORE , ireg_00099 , (ireg_00097) , 4
KICK , ireg_00099 , - , -
ADDI , ireg_00097 , ireg_00097 , -4
LI , ireg_00100 , 4 , -
STORE , ireg_00100 , (ireg_00097) , 4
KICK , ireg_00100 , - , -
ADDI , ireg_00097 , ireg_00097 , -4
LI , ireg_00101 , 3 , -
STORE , ireg_00101 , (ireg_00097) , 4
KICK , ireg_00101 , - , -
ADDI , ireg_00097 , ireg_00097 , -4
LI , ireg_00102 , 2 , -
STORE , ireg_00102 , (ireg_00097) , 4
KICK , ireg_00102 , - , -
ADDI , ireg_00097 , ireg_00097 , -4
KICK , ireg_00097 , - , -
CALL_PROC , bubble_sort , 24 , -
LOAD , ireg_00104 , -12($FP) , 4
KICK , ireg_00104 , - , -
LA , ireg_00105 , -12($FP) , -
STORE , ireg_00105 , ($SP) , 4
SUB , $SP , $SP , 4
LI , ireg_00105 , 20 , -
STORE , ireg_00105 , ($SP) , 4
SUB , $SP , $SP , 4
LI , ireg_00105 , 5 , -
STORE , ireg_00105 , ($SP) , 4
SUB , $SP , $SP , 4
KICK , ireg_00105 , - , -
JAL , bubble_sort , - , -
END_PROC , 24 , - , -
ADD , ireg_00103 , $RV , $ZERO
KICK , ireg_00103 , - , -
LI , ireg_00106 , 0 , -
RETURN , ireg_00106 , - , -
ENDPROC , - , - , -
PROG_END: