.data array: .word 1, 7, 2, 8, 3, 6, 4, 5, 10, 9 size: .word 10 before: .asciiz "before insertion sort: " after: .asciiz "after insertion sort: " nl: .asciiz "\n" sp: .asciiz " " .text .globl main main: subu $sp, $sp, 32 # stack frame is 32 bytes long sw $ra, 20($sp) # save return address sw $fp, 16($sp) # save old frame pointer addiu $fp, $sp, 28 # set up frame pointer # print out the original array content la $t0, array li $t1, 0x00 li $t2, 0x0a li $t3, 0x01 li $v0, 4 la $a0, before syscall print: li $v0, 1 lw $a0, 0($t0) syscall # print the integer li $v0, 4 la $a0, sp syscall # print space addiu $t1, $t1, 1 addiu $t0, $t0, 4 bne $t1, $t2, print beq $t3, $0, exit # calling the insertion sort routine la $a0, array # loading the argument subu $sp, $sp, 32 sw $a0, 0($sp) sw $a1, 4($sp) sw $a2, 8($sp) sw $a3, 12($sp) sw $t0, 16($sp) sw $t1, 20($sp) sw $t2, 24($sp) sw $t3, 28($sp) jal sort lw $t3, 28($sp) lw $t2, 24($sp) lw $t1, 20($sp) lw $t0, 16($sp) lw $a3, 12($sp) lw $a2, 8($sp) lw $a1, 4($sp) lw $a0, 0($sp) addiu $sp, $sp, 32 li $v0, 4 la $a0, nl syscall # print newline # print out the array content after sorting la $t0, array li $t1, 0x00 # reset the counter add $t3, $0, $0 li $v0, 4 la $a0, after syscall j print # do the print again exit: subu $fp, $sp, 28 lw $fp, 16($sp) lw $ra, 20($sp) addiu $sp, $sp, 32 # exit li $v0, 10 syscall sort: # function proloque # write your assembly code here done: # function epiloque