Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

high level language translation into mips

Status
Not open for further replies.

boogpicker

Newbie level 1
Newbie level 1
Joined
Apr 18, 2006
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,305
hey,
i am new to mips and have been trying to translate a quicksort algorithm into mips. problem is that when i load it into PCSpim, it gets hung up and just continues to run until I close Spim. can anyone look at what I have and see if you can figure out where its getting hung up?
Oh and i didnt comment it yet.
.data
array: .word 8,2,7,1,5,6,3,4,9,0
length: .word 10
.text
.globl main

main:
la $a0, array
move $a1, $zero
lw $a2, length
sub $a2, $a2, 1
jal QuickSort

li $v0, 10
syscall


################################################################

QuickSort:

# $a0 contains array
# $a1 contains 0
# $a2 contains n-1
# $s0 contains low
# $s1 contains high
# $s2 contains pivotPosition

sub $sp,$sp, 16
sw $s0, 0($sp)
sw $s1, 4($sp)
sw $s2, 8($sp)
sw $ra, 12($sp)
move $s0, $a1
move $s1, $a2
if: bge $s0, $s1, end_if
jal Partition
move $s2, $v0
sub $a2, $s2, 1
jal QuickSort
move $a2, $s1
addi $a1, $s2, 1
jal QuickSort
end_if:
lw $s0, 0($sp)
lw $s1, 4($sp)
lw $s2, 8($sp)
lw $ra, 12($sp)
addi $sp, $sp, 16
jr $ra

end_QuickSort:

###############################################################

Swap:
move $t0, $a0
move $t1, $a1
sw $t1, 0($t2)
sw $t0, 0($t2)
sw $t0, 0($t2)
end_Swap:

###############################################################

Partition:

# $a0 contains array
# $s0 contains left
# $s1 contains right
# $s2 contains pivot
# $a1 contains low
# $a2 contains high
# $t1 calculations array[low]
# $t0 contains base address
# $t2 contains calculations for array

# $t3 contains array

# $t4 contains calculations for array

# $t5 contains array


sub $sp, $sp, 16
sw $s0, 0($sp)
sw $s1, 4($sp)
sw $s2, 8($sp)
sw $ra, 12($sp)
la $t0, array
begin:
move $s0, $a1
move $s1, $a2
mul $t1, $a1, 4
add $t1, $t0, $t1
lw $s2, 0($t1)
while_condition:
bge $s0, $s1, end_while
mul $t2, $s1, 4
add $t2, $t0, $t2
lw $t3, 0($t2)
while_condition_2:
ble $t3, $s2, end_while_2
sub $s1, $s1, 1
j while_condition_2
end_while_2:

while_condition_3:
bge $s0, $s1, end_while_3
mul $t4, $s0, 4
add $t4, $t0, $t4
lw $t5, 0($t4)
bgt $t5, $s2, end_while_3
addi $s0, $s0, 1
j while_condition_3
end_while_3:

if_2:
bge $s0, $s1, end_if_2
mul $t4, $s0, 4
add $t4, $t0, $t4
lw $a0, 0($t4)
mul $t2, $s1, 4
add $t2, $t0, $t2
lw $a1, 0($t2)
jal Swap
end_if_2:

end_while:
mul $t1, $a1, 4
add $t1, $t0, $t1
mul $t2, $s1, 4
add $t2, $t0, $t2
lw $t3, 0($t2)
sw $t3, 0($t1)
sw $s2, 0($t2)
move $v0, $s2

lw $s0, 0($sp)
lw $s1, 4($sp)
lw $s2, 8($sp)
lw $ra, 12($sp)
addi $sp, $sp, 16
end_Partition:​
 

Hi

If you already have a hi-level program so you don't need to translate it into mips assembly

just use MIPS gcc compiler.
you may face some compiling errors but it could be overcome

if you need the aeembly to simulate over SPIM just set GCC to generate assembly code

Salam
Hossam Alzomor
www.i-g.org
 

that is:

mips-elf-gcc -S -mips1

you can use these options.
but the assembly code will not contain the "syscall" statements. It will contain actual calls to libc primitives (i think).

it seems that you want to interpret and simulate your assembly file with spim.

the_penetrator©
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top