954,153 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

i'm a rookie, please help with MIPS

so i'm learning MIPS right now and i think i get the hang of things, mind you it's all relatively easy (so i've been told), but i can't seem to get around this one problem. i was given a C++ fragment and need to convert (translate) it directly to MIPS.

and that equation is array[a+b] = array[a-b]+d

intially i thought, this would be the same as array[a]+array[b] = array[a+b]...and of course i was wrong.

though wrong, i'd still like to post what i do have....and if someone can correct me and guide me to the right direction, that'll be great!

add	$t1, $s0, $s0		# $t1 = 2*a
add	$t1, $t1, $t1		# $t1 = 4*a
add	$t2, $s1, $s1		# $t1 = 2*b
add	$t2, $t2, $t2		# $t1 = 4*b
sub 	$t3, $t1, $t2		# $t3 = A[a] – A[b] (or A[a-b]
add	$t3, $t3, $t0		# $t3 = address of A[a-b]
lw	$t3, 0($t0)		# $t3 = A[c-b]
add	$t4, $t3, $s2		# $t4 = A[a-b] + d
add	$t5, $t1, $t2		# $t5 = A[a] + A[b]
add	$t5, $t5, $t0		# $t5 = address of A[a+b]
lw	$t5, 0($t0)		# $t5 = A[a+b]
sw	$t5, 0($t0)		# A[a+b] = $t3

thanks in advance
to the admin: see i have put a HONEST effort...so can i now get help? /lol

ulethgeek
Newbie Poster
1 post since Oct 2004
Reputation Points: 10
Solved Threads: 0
 
thanks in advance to the admin: see i have put a HONEST effort...so can i now get help? /lol

That's all we ask :D

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

so i'm learning MIPS right now and i think i get the hang of things, mind you it's all relatively easy (so i've been told), but i can't seem to get around this one problem. i was given a C++ fragment and need to convert (translate) it directly to MIPS.

and that equation is array[a+b] = array[a-b]+d

intially i thought, this would be the same as array[a]+array[b] = array[a+b]...and of course i was wrong.

though wrong, i'd still like to post what i do have....and if someone can correct me and guide me to the right direction, that'll be great!

add    $t1, $s0, $s0        # $t1 = 2*a
add    $t1, $t1, $t1        # $t1 = 4*a
add    $t2, $s1, $s1        # $t1 = 2*b
add    $t2, $t2, $t2        # $t1 = 4*b
sub     $t3, $t1, $t2        # $t3 = A[a] – A[b] (or A[a-b]
add    $t3, $t3, $t0        # $t3 = address of A[a-b]
lw    $t3, 0($t0)        # $t3 = A[c-b]
add    $t4, $t3, $s2        # $t4 = A[a-b] + d
add    $t5, $t1, $t2        # $t5 = A[a] + A[b]
add    $t5, $t5, $t0        # $t5 = address of A[a+b]
lw    $t5, 0($t0)        # $t5 = A[a+b]
sw    $t5, 0($t0)        # A[a+b] = $t3
thanks in advance


Unless you have some la and lw instructions that you're not putting here, then you are missing the actual putting of values into registers

MacGyver Orca
Light Poster
39 posts since Jan 2007
Reputation Points: 19
Solved Threads: 4
 

moved

Ancient Dragon
Retired & Loving It
Team Colleague
30,042 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You