### MIPS Assembly to C++ convert

I am doing book problem that wants translated MIPS assembly to matching C++ lines.

it gives:

k = \$s0, A[] base address = \$s7

sw \$t1, 0(\$t0)
lw \$t0, 0(\$t0)

my attempt to solve what it doing:

t0 = &A[1]
t1 = &A[0]
0(t0)/A[1] = &A[0] ??
t0 = 0(t0) => to = A[0]
k = A[0] + &A[0] ???

I don't know mips asm but you don't have to translate 1 to 1; often many assembler statements are only 1 c++ statement. Keep that in mind as you do this .. the whole thing could just be (making it up)
t = a+b + c;
Last edited on
Yea, I figured it would likely be, probably the k = statement as the long final thing. I'm just having trouble figuring out what that is because what I got in the post above doesn't seem to make any sense.
That MIPS code is nonsense. I'm not sure what you are supposed to get out of this.
 ``12345`` `````` addi \$t0, \$s7, 4 ; t0 = A + 4 add \$t1, \$s7, \$0 ; t1 = A + 0 sw \$t1, 0(\$t0) ; *t0 = t1 → A[4] = A lw \$t0, 0(\$t0) ; t0 = *t0 → t0 = A[4] → t0 = A add \$s0, \$t1, \$t0 ; k = t1 + t0 → k = A + A``````

The produced C++ code is also nonsense (and technically illegal):
`k = A + A`

Hint: keep references handy. Here's one I googled for you
http://www.cs.uwm.edu/classes/cs315/Bacon/Lecture/HTML/ch05.html
Huh. So nice to know you can count on overpriced books to give you actually useful exercises........... Though nice to know it's not just me having that bad of an understanding of it all...

Thanks a lot (and for the link as well).
some authors will give you a mention or a free copy or something when you find a goof :) report it.

Ha, yea. May have to do that when I get the chance. Yea... don't want anyone more than can be helped spending upwards of a hour trying to firgure out where they're going wrong here.
Last edited on
Topic archived. No new replies allowed.