# type | var | register # ---------------------- # int | f | $s0 # int | g | $s1 # int | h | $s2 # int | i | $s3 # int | j | $s4 # int* | p | $s5 # int* | q | $s6 # Convert this C statement to MIPS assembly # f = 1; li $s0, 1 # Convert this C statement to MIPS assembly # g = -2; li $s1, -2 # Convert this C statement to MIPS assembly # f = g + 1; addi $s0, $s1, 1 # Convert this C statement to MIPS assembly # f = i - 1; addi $s0, $s3, -1 # Why isn't there a subi instruction? # It's unnecessary: we can just pass negative numbers to addi # Convert this C statement to MIPS assembly # f = (g + h) - (i + j); add $s0, $s1, $s2 # f = g + h sub $s0, $s0, $s3 # f -= i sub $s0, $s0, $s4 # f -= j # We can also write: add $t0, $s1, $s2 add $t1, $s3, $s4 sub $s0, $t0, $t1 # Convert this C statement to MIPS assembly # f = g - h + i - 1; sub $s0, $s1, $s2 # f = g - h add $s0, $s0, $s3 # f += i addi $s0, $s0, -1 # Convert this C statement to MIPS assembly # f = g >> 2; srl $s0, $s1, 2 # Convert this C statement to MIPS assembly # f = g / 4; sra $s0, $s1, 2 # -20 in binary: 101100 # -20 >> 2: 001011 = 11 # -20 >>> 2: 111011 = -5 # Convert this C statement to MIPS assembly # f = g << 1; sll $s0, $s1, 1 # Convert this C statement to MIPS assembly # f = g * 8; sll $s0, $s1, 3 # sla does not exist because the sign bit is not empty