Yes, when you add $0
and 1
, you get 1
, which is put into $t2
.
Then, when you evaluate a($t2)
, that's the second byte (offset 1 since it's based at offset 0) of a
which is the "0", ASCII code 0x30
or 48
.
From various pieces of information:
ADDI -- Add immediate (with overflow)
Description:
Adds a register and a sign-extended immediate value
and stores the result in a register
Operation:
$t = $s + imm; advance_pc (4);
Syntax:
addi $t, $s, imm
LB -- Load byte
Description:
A byte is loaded into a register from the specified address.
Operation:
$t = MEM[$s + offset]; advance_pc (4);
Syntax:
lb $t, offset($s)
Register $0
always contains the hardwired value 0. MIPS has established a set of conventions as to how registers should be used. These suggestions are guidelines, which are not enforced by the hardware. However a program that violates them will not work properly with other software.
Those little snippets should hopefully be enough to explain what it's doing.
And, regarding your edit, you're incorrectly thinking that .word 12,-5,4,0
has a length of 4 bytes. In fact it has a length of 16 bytes since words in MIPS are 32 bits (four bytes) wide.
So when you load from byte offset 8, you will get the word 4
.