New Posts  All Forums:Forum Nav:

Help with MIPS -

post #1 of 3
Thread Starter 
I'm having a hard time understanding why my MIPS program is not outputing the expected result. Please refer to the c++ code, followed is my version of mips

**The C++ version:**

#include
using namespace std;

int x[10] = {0};
int pos[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
int d[10] = {73, 47, 23, 26, 67, 99, 13, 53, 1, 97};

int main()
{

int count = 0;
int key = 24;
for (int i=0; i<10; i++)
{
if (d >= key)
{
pos[count] = i;
x[count] = d
;
count++;
}
}

for (int i=0; i<10; i++)
{
if (pos < 0)
break;
cout << pos
<< " " << x << endl;
}

system("PAUSE");
return 0;
}


___________________________________________

**My MIPS version:**

.data

x:
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0

pos:
.word -1
.word -1
.word -1
.word -1
.word -1
.word -1
.word -1
.word -1
.word -1
.word -1

d:
.word 73
.word 47
.word 23
.word 26
.word 67
.word 99
.word 13
.word 53
.word 1
.word 97

sp: .asciiz " "
endl: .asciiz "\n"

# $s0 count
# $s1 key
# $s2 i

.text
.globl main

main:
addi $s0, $0, 0 # int count = 0;
addi $s1, $0, 24 # int key = 24;
addi $s2, $0, 0 # int i = 0
la $s3, d # address of d into s3
la $s4, pos # address of pos into s4
la $s5, x # address of x into s5


# for (int i=0; i<10; i++) {
loop: # $t0 = temp_array_0
sll $t0, $s2, 2 # temp_array_0 = i * sizeof(int)
lw $t0, d($t0) # $t0 = d

blt $t0, $s1, loop1 # if (d < key)
# temp_array_1
sll $t1, $s0, 2 # temp_array_1 = count * sizeof(int)
sw $s2, pos($t1) # pos[count] = i
sw $t0, x($t1) # x[count] = d

addi $s0, $s0, 1 # count++
addi $s2, $s2, 1 # i++
blt $s2, 10, loop # i < 10 }
# for (int i=0; i<10; i++) {
loop1: # $t2 = temp_array_2
sll $t2, $s2, 2 # temp_array_2 = i * sizeof(int)
lw $t2, pos($t2) # temp_array_2 = pos
bge $t2, 0, for1 # break }
addi $s2, $s2, 1 # i++

for1:
lw $a0, ($s4)
li $v0, 1
syscall
la $a0, sp
li $v0, 4
syscall
lw $a0, ($s5)
li $v0, 1
syscall
la $a0, endl
li $v0, 4
syscall
addi $s3, $s3, 4
addi $s4, $s4, 4
addi $s5, $s5, 4
addi $s2, $s2, 1
blt $s2, 10, for1

exit:
li $v0, 10
syscall
__________________________________

**The expected result:**


0 73
1 47
3 26
4 67
5 99
7 53
9 97
Press any key to continue . . .

**My result by using MARS**


0 73
1 47
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0

-- program is finished running --
HAYATE
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7930 @ 4.438ghz ASUS Rampage III Extreme 3-way SLI 2xevga GRX480+Zotac GTX 480 AMP Edition 20GB DDR3 
Hard DriveOptical DriveOSMonitor
SSD baby :) SSD baby :) WIN 7 64 bit Ultimate Alienware AW2310 
KeyboardPowerCaseMouse
Logitech g19 Corsair HX 1000W corsair full tower big black box Razer Naga 
Mouse Pad
steeleries 
  hide details  
Reply
HAYATE
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7930 @ 4.438ghz ASUS Rampage III Extreme 3-way SLI 2xevga GRX480+Zotac GTX 480 AMP Edition 20GB DDR3 
Hard DriveOptical DriveOSMonitor
SSD baby :) SSD baby :) WIN 7 64 bit Ultimate Alienware AW2310 
KeyboardPowerCaseMouse
Logitech g19 Corsair HX 1000W corsair full tower big black box Razer Naga 
Mouse Pad
steeleries 
  hide details  
Reply
post #2 of 3
I don't have any input on your issue, but I strongly recommend using the tags around each section of code, and then wrapping both in spoiler tags to reduce the clutter.[code] tags around each section of code, and then wrapping both in spoiler tags to reduce the clutter.
post #3 of 3
Thread Starter 
Quote:
Originally Posted by EfemaN View Post

I don't have any input on your issue, but I strongly recommend using the tags around each section of code, and then wrapping both in spoiler tags to reduce the clutter.[/quote] Will do next time I have a question. Mods please close the thread. I was able to figure the issues I had.[code] tags around each section of code, and then wrapping both in spoiler tags to reduce the clutter.

Will do next time I have a question.

Mods please close the thread. I was able to figure the issues I had.
HAYATE
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7930 @ 4.438ghz ASUS Rampage III Extreme 3-way SLI 2xevga GRX480+Zotac GTX 480 AMP Edition 20GB DDR3 
Hard DriveOptical DriveOSMonitor
SSD baby :) SSD baby :) WIN 7 64 bit Ultimate Alienware AW2310 
KeyboardPowerCaseMouse
Logitech g19 Corsair HX 1000W corsair full tower big black box Razer Naga 
Mouse Pad
steeleries 
  hide details  
Reply
HAYATE
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7930 @ 4.438ghz ASUS Rampage III Extreme 3-way SLI 2xevga GRX480+Zotac GTX 480 AMP Edition 20GB DDR3 
Hard DriveOptical DriveOSMonitor
SSD baby :) SSD baby :) WIN 7 64 bit Ultimate Alienware AW2310 
KeyboardPowerCaseMouse
Logitech g19 Corsair HX 1000W corsair full tower big black box Razer Naga 
Mouse Pad
steeleries 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming