jrhetf4xb
jrhetf4xb

Reputation: 161

Memory addressing in MIPS assembly

I was recently reading Patterson and Hennessy's book "Computer Organization and Design" in order to study a bit of assembly. I came across a section where the lw and sw machine instructions were explained and how they take a 16-bit immediate as the load/store address. What the authors pointed here is this: "The 16-bit address means a load word instruction can load any word within a region of [...] 8192 words of the address in the base register rs".

My question is:

Upvotes: 0

Views: 12674

Answers (1)

Michael
Michael

Reputation: 58497

Does that mean that all registers' addresses are spaced 8192 words apart from each other?

No. Registers don't have addresses.

Also, does it mean that the whole available memory for operating is 32 * 8192 = 262144 words?

No. These immediates are offsets to the base address used for the load/store. It allows you do specify addresses within -32768..+32767 bytes from the base address. 32768/sizeof(word) == 8192. You can simply change the value of the base register if you want to move beyond that range.
The amount of registers has nothing to do with the amount of memory you can address.

For example:

li $a0,0       # set $a0 to 0
lw $t0,0($a0)  # load a word from address 0
lw $t0,8($a0)  # load a word from address 8

lui $a0,0xffff # set the upper half-word of $a0 to 0xffff
lw $t0,4($a0)  # load a word from address 0xffff0004

Upvotes: 4

Related Questions