DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Assembly (http://www.daniweb.com/forums/forum125.html)
-   -   i'm a rookie, please help with MIPS (http://www.daniweb.com/forums/thread12673.html)

ulethgeek Oct 20th, 2004 3:25 am
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

alc6379 Oct 20th, 2004 10:27 am
Re: i'm a rookie, please help with MIPS
 
Quote:

Originally Posted by ulethgeek
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

MacGyver Orca Feb 8th, 2007 7:14 am
Re: i'm a rookie, please help with MIPS
 
Quote:

Originally Posted by ulethgeek (Post 61804)
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

Ancient Dragon Feb 8th, 2007 8:51 am
Re: i'm a rookie, please help with MIPS
 
moved


All times are GMT -4. The time now is 6:35 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC