Home    About Me    Resume    Portfolio

MIPS

Here is a swap function involving MIPS (Millions of Instructions Per Second). This was not a whole lot of fun, but it fulfilled my abligation to working with a second level language.

Does it work? Well only I know that for sure. I will tell you that it compiles. If you have access to a MIPS Simulator compiler, that accepts this code, you can always spend the weekend computing the hex output!

#Joe Gakenheimer
#October 30, 2001
#Comp 360
#Sorting Array of 10
#Using MIPS
#/export/home/gakenh01/MIPS>array.asm

.text              0x40000000             #code territory
main: add $s0 $zero $gp #line 10
addi $s1 $zero 10
add $s1 $s1 $s1 #j=i-1
add $s1 $s1 $s1 #j=j-1
jal sortArray
add $t3 $zero $zero
jal printArray
add $t6 $zero $zero
add $t6 $zero $zero
.data 0x10000000
.word 8 3 44 5 24 69 9 38 51 21 #line 21, nums to sort
#str .asciiz 2"Number n = " #I wanted to print out the sorted
#answer, but for some odd reason this command doesn't work.
.text 0x40000180
firstTest: slt $t0 $s0 $a1 #reg $t0=0 if $s0
beq $t0 $zero exit1 #goto exit1 if $s0>=$a1
addi $s0 $s0 1 #i=i+1
j firstTest #jump to test of outer loop
j firstTest #jump to test of outer loop
#previous line 40
secondTest: slti $t0 $s1 0
bne $t0 $zero exit2 #goto exit to if $s1<0(<0)
add $t1 $s1 $s1
add $t1 $t1 $t1
add $t2 $s2 $t1
lw $t3 0($t2) #$t3=v[j]
lw $t4 4($t2) #$t4=v[j=1]
slt $t0 $t4 $t3 #$t0=0 if $t4>=$t3

#Print Array, using syscall command, line 39
syscall
syscall
syscall
syscall
syscall
syscall
syscall
syscall
syscall
j $ra #return to calling function




Home    About Me    Resume    Portfolio