Development, Education, Life

It Literally Pays Off to Do Homework in Cambridge

Well done! - joint shortest traditional (and practical :-) sort for the OS1a prize tick.

"Well done! - joint shortest traditional (and practical :-) sort for the OS1a prize tick". Cambridge, 2009.

45 minutes, 28 MIPS instructions and £25.
Computer Science FTW.

# Copyright Manfredas Zabarauskas, 2009.
# MIPS routine that reads an array of ten integers 
# and prints the sorted array to console.
.text
main:   sub $t7, $sp, 40
l_read: li $v0, 5
        syscall
        sw $v0, 0($t7)
        add $t7, $t7, 4
        bne $t7, $sp, l_read
l_out:  sub $t8, $sp, 36
        sub $t7, 40
l_inn:  add $t8, $t8, 4
        lw $t2, -8($t8)
        lw $t3, -4($t8)
        ble $t2, $t3, no_swp
        sw $t2, -4($t8)
        sw $t3, -8($t8)
        move $t7, $sp
no_swp: bne $t8, $sp, l_inn
        beq $t7, $sp, l_out
l_prnt: li $v0, 11
        li $a0, 10
        syscall
        li $v0, 1
        lw $a0, 0($t7)
        syscall
        add $t7, $t7, 4
        bne $t7, $sp, l_prnt
        li $v0, 10
        syscall

 

 
36 Kudos
Don't
move!

Leave a Reply

Your email address will not be published. Required fields are marked *


3 − = one