Why is my assembly code in MIPS wrong?
The books solution is wrong:

sub $t0, $s3, $s4
add $t0, $s6, $t0
lw $t1, 16($t0)
sw $t1, 32($s7)


The use of lw and sw instruction imply that the arrays A and B are 32 bit in size, otherwise instructions such as lb/lbu, lh/lhu would be used to load 8 or 16 bit wide entities (or LD, SD for 64 bit machines).

However, the address calculation does not take the size of the elements into account. This causes the address calculation to be wrong.

You did it right by scaling the offset into the array using the sll instruction.


  I am confused. How did they come up with the third statement lw $t1,
  16($t0) ?


The offset of 16 makes no sense in this context. The offset of 32 in the store instruction is fine because it directly addresses element 8 in the B array as it should.