MIPS Assembly to C++ convert

Sonar87

n00b
Joined
Sep 22, 2017
Messages
7
I am doing book problem that wants translated MIPS assembly to matching C++ lines.

it gives:

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

addi $t0, $s7, 4
add #t1, $s7, $0
sw $t1, 0($t0)
lw $t0, 0($t0)
add $s0, $t1, $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] ???
 
The first two lines of assembly assign the first two addresses of an array with base address s7 to t1 and t0, in that order:
Code:
t0 = &A[1];
t1 = &A[0];
The next line stores the contents of $t1 into the location with address $t0 + offset 0:
Code:
A[1] = t1;   // A[1] = &A[0]
The fourth line loads the word found at address $t0 + offset 0 into $t0:
Code:
t0 = A[1];   // t0 = &A[0]
Finally, the contents of $t1 and $t0 are added and stored into $s0:
Code:
s0 = t1 + t0;   // s0 = &A[0] + &A[0]

It's a goof problem with a goof solution.
 
Last edited:
Thanks. *sigh* for the price of these books it would be nice if they'd at least make sure all their problems make sense...
 
It’s been a few years since I’ve used it, but this provided really good introductory MIPs coverage. I worked through all its problems and can provide some help if you need.
 
As an Amazon Associate, HardForum may earn from qualifying purchases.
Back
Top