using PCspim

PCspim is a MIPS compiler where you write a code in mips assembly language.
To get started with this software, you need first to download it from here .
Moreover, you will want to have the Notpad++, if you still don’t have it, you definitely need to!

this is the window you will see when opening the software:

hmmm...doesn't say much, eh?!  well soon it will!
hmmm…doesn’t say much, eh?! well soon it will!

So the first impression was not tempting to code anything, and there is no place to write your code even! well, the code should be written in Notepad(Notepad++ or your average\ordinary  Notepad), and PCspim reads this .txt file.

Sorting Numbers – assembly code _ Mips

The Algorithm:
the idea is to compare and sort each pair alone, then to compare the Max from one pair with the Min from the other pair, and replace the numbers accordingly, then check if we got a sorted 4 numbers, if no, then start over(no loops included!)
Here is the code:

L1: .word 9
L2: .word 1
L3: .word 3
L4: .word 6

.globl _main
 andi $0, $0, 0
 lw $8, L1($0)
 lw $9, L2($0)
 lw $10, L3($0)
 lw $11, L4($0) 
L1_2: slt $12, $8, $9 
 beq $12, $0, Swap8_9 
L3_4: slt $12, $10, $11 
 beq $12, $0, Swap10_11 
L2_3: slt $12, $9, $10 
 beq $12, $0, Swap9_10 
 j Exit 

 add $13, $0, $9 
 add $9, $0, $10
 add $10, $0, $13
 j L1_2 
 add $13, $0, $10 
 add $10, $0, $11
 add $11, $0, $13
 j L2_3

 add $13, $0, $8 
 add $8, $0, $9
 add $9, $0, $13
 j L3_4 
 sw $8, L1($0)
 sw $9, L2($0)
 sw $10, L3($0)
 sw $11, L4($0)

Note the jump to L3_4 in swap8_9, this is the part where the sorting process is being done again.

after the sort
before the sort

here is a simulation for the code:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: