# Do I need to use the 'add' function in mips to store into a variable or can I store into a variable with load word?

The following problems deal with translating from C to MIPS. Assume that the variables f,g,h,i, and j are assigned to registers $s0,$s1, $s2,$s3, and $s4, respectively. Assume that the base address of the arrays A and B are registers$s6 and $s7, respectively. Write the MIPS code for the following C lines of code: I am trying to mimic the following code snippet from a C program and write it in MIPS. if(g != h){ f = A[3]; } else{ f = B[4]; }  Below is the MIPS I have so far bne$s1, $s2, Tru lw$s0, 16($s7) j Done Tru: lw$t0, 12($s6) add$s0, $t0,$zero
Done:


If I was unclear please comment below.

You used lw $s0, 16($s7) for your f=B[4]; line.
As long as that line works, why are you overcomplicating f=A[3]; with the additional ASM line add $s0,$t0, $zero? Just lw$s0, 12($s6) & be done with it. • ok so as long as you lw into the$s0 register, your fine? – Brandon Woodard Mar 1 '16 at 5:47
• @BrandonWoodard If you were to assume that you could not lw into the $s0 register directly, how would using lw into$t0; then adding $t0+$zero into $s0 circumvent anything? - To my knowlege, there's no intance where you could gain anything (besides increased CPU lag) by adding the second operation there. .. So yes, as long as you lw the correct value into$s0, that sets f=__ correctly. – Robherc KV5ROB Mar 1 '16 at 5:56