Electrical – 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

assemblycodemips

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.

Best Answer

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.