Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: MIPS 32 ASM to C code, did i do this right?

  1. Sep 13, 2006 #1
    have the following MIPS 32 asm code:
    Assuming B is an array of 10 words whose base address is in register $s0, andvariable c and i are in $s1 and $s2, respectively. What is the C statement implemented by the below MIPS assembly code?
    add $t0, $s2, $s2
    add $t0, $t0, $t0
    lw $t1, 0($s0)
    lw $t2, 8($s0)
    sub $s1, $t2, $t1

    In C what does it look like?
    i said c = B[i+2] - B

    but the other optpoins are:
    c = B - B[i+2]
    c = B - B[i+8]
    c = B[i+8] - B

    Can someone see if i'm correct?

    lw $t2,8($s0);
    I said was really index B[2] because, in mips memory is set up by 4's.

    If i have memory set up like this:

    [0x10ff00ff] 32
    [0x00ff00ff] 28
    [0x0000ffff] 24
    [0xffff0000] 20
    [0x10ffff00] 12
    [0xff00ffff] 8
    [0xff0000ff] 4
    [0x0000ff44] 0
    32 bit data and the numbers are word address

    I'm confused on what the beginning codes prupose is for, the 2 add statements.
    It basically does this i think:
    $t0 = i + i;
    $t0 = (i+i) + (i+i)?
  2. jcsd
  3. Sep 13, 2006 #2
    Yep it was correct
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook