Solved

how can i write this code in MIPS

Posted on 2009-04-09
2
300 Views
Last Modified: 2012-05-06
$s0 = f, $s1 = g, $s2 = h, $s3 = i, $s4 = j.  
base address of array A and B stored in $s6 and $s7 respectively.

1) f = -g + h + B[1];

2) f = A[B[g] + 1];

I have this so far but i don't its right
1)
sub $t0, $s2, $s1
lw $t1, 4($s7)
add $s0, $t0, $t1

2)
sll $t0, $s1, 2
lw $t1, $t0($s7)    #not sure about this
addi $t2, $t1, 1
sll $t3, $t2, 2
lw $t4, $t3($s6)    #not sure about this
add $s0, $t4, $zero

0
Comment
Question by:emreayman
  • 2
2 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 50 total points
Comment Utility
>> lw $t1, $t0($s7)    #not sure about this

You'll have to calculate the address ($s7+$t0), and then use that calculated address with the lw instruction. The offset for the address calculation can only be an immediate (constant) value.

Same for :

>> lw $t4, $t3($s6)    #not sure about this


The rest looks ok.
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
Sorry for the late reply btw (I just noticed this question now) - I hope it's not too late :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
False Theorem 27 909
How to calculate time ticks with rdtsc in x86 computer? 2 599
Address Range Confusion??? 4 372
Convert from Binary to Hexadecimal 15 685
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now