Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Does anyone here know Mips?
New Posts  All Forums:Forum Nav:

Does anyone here know Mips?

post #1 of 6
Thread Starter 
i have been working on an assignment for school that is in mips [assembly] that takes an array and sorts it, pretty simple, and i think i have the solution but i keep getting an error when i compile.
would anyone happen to know what its coming from / how to fix it? my code is as follows:
Code:

                        .text
                        .globl main
        main:           la      $a0, Array              # sets the base address of the array to $a0
        loop:           lw      $t0, 0($a0)             # sets $t0 to the current element in array
                        lw      $t1, 4($a0)             # sets $t1 to the next element in array
                        blt     $t1, $t0, swap          # if the following value is greater, swap them
                        addi    $a0, $a0, 4             # advance the array to start at the next location from last time
                        j       loop                    # jump back to loop so we can compare next two elements
                        
        swap:           sw      $t0, 4($a0)             # store the greater numbers contents in the higher position in array (swap)
                        sw      $t1, 0($a0)             # store the lesser numbers contents in the lower position in array (swap)
                        li      $a0, 0                  # resets the value of $a0 back to zero so we can start from beginning of array
                        j       loop                    # jump back to the loop so we can go through and find next swap
        
                        .data
                        
        Array:          .word   14, 12, 13, 5, 9, 11, 3, 6, 7, 10, 2, 4, 8, 1 

i know there could be more efficient ways to do this but i am native to java so this kinda throws me for a spin!
thanks in advance if any help!
post #2 of 6
Is your compiler spitting out an error, or does it actually compile without sorting? What error/line is it?

Don't know mips that well though, I'm native to ARM.
Edited by brucethemoose - 10/14/13 at 12:13am
Bruce
(20 items)
 
  
CPUMotherboardGraphicsRAM
4670k Asus Z87 Pro HIS 7950 IceQ X2 2x2gb + 2x4gb DDR3 1333 
Hard DriveHard DriveHard DriveOptical Drive
Seagate 1TB 7200RPM OCZ Agility 4 128GB PNY 240GB LG Blu Ray Burner 
CoolingOSMonitorKeyboard
Hyper 212+ with extra fan Windows 10 Education x64 Shimian QH270 @110hz Medieval Dell OEM Keyboard 
PowerCaseMouseAudio
Corsair TX750 V1 Antec 300 Black Illusion  Logitech G400s Xonar ST 
AudioOtherOtherOther
Fostex T50rp with BMF mod Archer T9E Wifi adapter 2x Yate Loon D12SL-12D 120x38mm fans Thermalright TY-143 fan 
  hide details  
Reply
Bruce
(20 items)
 
  
CPUMotherboardGraphicsRAM
4670k Asus Z87 Pro HIS 7950 IceQ X2 2x2gb + 2x4gb DDR3 1333 
Hard DriveHard DriveHard DriveOptical Drive
Seagate 1TB 7200RPM OCZ Agility 4 128GB PNY 240GB LG Blu Ray Burner 
CoolingOSMonitorKeyboard
Hyper 212+ with extra fan Windows 10 Education x64 Shimian QH270 @110hz Medieval Dell OEM Keyboard 
PowerCaseMouseAudio
Corsair TX750 V1 Antec 300 Black Illusion  Logitech G400s Xonar ST 
AudioOtherOtherOther
Fostex T50rp with BMF mod Archer T9E Wifi adapter 2x Yate Loon D12SL-12D 120x38mm fans Thermalright TY-143 fan 
  hide details  
Reply
post #3 of 6
Thread Starter 
Code:
line 6: Runtime exception at 0x00400008: address out of range 0x00000000

and line 6 is the beginning of the
Code:
loop:
post #4 of 6
Did you initialize the base address correctly?

It could also be a really simple syntax error. I can't tell you how much ARM code I've rewritten only to find that an extra space was the cause of my bug mad.gif
Bruce
(20 items)
 
  
CPUMotherboardGraphicsRAM
4670k Asus Z87 Pro HIS 7950 IceQ X2 2x2gb + 2x4gb DDR3 1333 
Hard DriveHard DriveHard DriveOptical Drive
Seagate 1TB 7200RPM OCZ Agility 4 128GB PNY 240GB LG Blu Ray Burner 
CoolingOSMonitorKeyboard
Hyper 212+ with extra fan Windows 10 Education x64 Shimian QH270 @110hz Medieval Dell OEM Keyboard 
PowerCaseMouseAudio
Corsair TX750 V1 Antec 300 Black Illusion  Logitech G400s Xonar ST 
AudioOtherOtherOther
Fostex T50rp with BMF mod Archer T9E Wifi adapter 2x Yate Loon D12SL-12D 120x38mm fans Thermalright TY-143 fan 
  hide details  
Reply
Bruce
(20 items)
 
  
CPUMotherboardGraphicsRAM
4670k Asus Z87 Pro HIS 7950 IceQ X2 2x2gb + 2x4gb DDR3 1333 
Hard DriveHard DriveHard DriveOptical Drive
Seagate 1TB 7200RPM OCZ Agility 4 128GB PNY 240GB LG Blu Ray Burner 
CoolingOSMonitorKeyboard
Hyper 212+ with extra fan Windows 10 Education x64 Shimian QH270 @110hz Medieval Dell OEM Keyboard 
PowerCaseMouseAudio
Corsair TX750 V1 Antec 300 Black Illusion  Logitech G400s Xonar ST 
AudioOtherOtherOther
Fostex T50rp with BMF mod Archer T9E Wifi adapter 2x Yate Loon D12SL-12D 120x38mm fans Thermalright TY-143 fan 
  hide details  
Reply
post #5 of 6
From what I see you just keep adding to a0? Do you ever check whether you've hit the end of the array without swapping? I'm rather tired but I don't see that in there. When you get back to line 6 you try to load something that isn't there (I believe it's totally unallocated space). Is this program made to work on arbitrarily sized arrays? If so you will need to count the number of elements to operate on beforehand.

Anyway instead of jump on the loop do a branch if less than (where you compare the current value of your index with the last value), and then jump to your finish after it so that you avoid your swap routine. It's been a while but that's probably where your issue is.
post #6 of 6
Your problem is that your loop has no exit to terminate the program. Therefore when the index is on the last element it tries to compare to the next address which is not allocated in the array. So to fix this, create a variable in the data section that is equal to the number of elements (in this case 14), and then create another variable that starts at 1.

Then before you get to the last line in your loop where it jumps back to the top, increase the counter by 1. After that statement do a beq that compares the counter to 14 and when it is equal to 14 have it jump to a new field called end.

loop: lw $t0, 0($a0) # sets $t0 to the current element in array
lw $t1, 4($a0) # sets $t1 to the next element in array
blt $t1, $t0, swap # if the following value is greater, swap them
addi $a0, $a0, 4 # advance the array to start at the next location from last time
addi #counter, 1 #adds 1 to the counter to indicate that another element has been compared and sorted if necessary
beq #counter, 14, end #Once the loop has iterated through all the elements jump to end
j loop # jump back to loop so we can compare next two elements

end:
li $v0, 4 # Load the system call to print string into $v0
lw $a0, Array #Load the array into $a1
syscall #System call to print out string

I am pretty sure that should fix your problem. I got an exam for another class today so I can't spend too much time on this. If it doesn't work, just let me know and I will look at it later tonight.
Macbook Air
(13 items)
 
  
CPUMotherboardGraphicsRAM
C2D E6600 2.4ghz @ 3.6ghz Gigabyte EP45-UD3P Rev 1.0 BFG GTX275 4x1gb Corsair XMS2 DDR2-800 
Hard DriveOptical DriveOSMonitor
150gb Raptor, 3x1tb Storage Samsung 22x DVDRW + LG 22x DVDRW (BOTH SATA) Windows 7 64-Bit Samsung 245BW 24" 1920x1200 5ms 
KeyboardPowerCaseMouse
Logitech G11 Silverstone Strider 750w Modular Antec 900 Razer Copperhead 
Mouse Pad
Custom Outer Space 
  hide details  
Reply
Macbook Air
(13 items)
 
  
CPUMotherboardGraphicsRAM
C2D E6600 2.4ghz @ 3.6ghz Gigabyte EP45-UD3P Rev 1.0 BFG GTX275 4x1gb Corsair XMS2 DDR2-800 
Hard DriveOptical DriveOSMonitor
150gb Raptor, 3x1tb Storage Samsung 22x DVDRW + LG 22x DVDRW (BOTH SATA) Windows 7 64-Bit Samsung 245BW 24" 1920x1200 5ms 
KeyboardPowerCaseMouse
Logitech G11 Silverstone Strider 750w Modular Antec 900 Razer Copperhead 
Mouse Pad
Custom Outer Space 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Does anyone here know Mips?