MIPS Memory Addressing

Byte vs word addressing, alignment, and the “address of the last byte/word” calculation (Q3(c) most semesters).

Byte addressing

Memory is one large single-dimension array; an address is an index into it. MIPS uses byte addressing: each address points to 1 byte (8 bits), and a load/store’s unit is a byte. MIPS uses a 32-bit byte address.

Words

  • Most data items are 4 bytes wide. For MIPS a word = 32 bits = 4 bytes.
  • Registers hold 32 bits, matching a word.
  • Word address = the address of the first byte in the word.
  • Words are aligned: word addresses are 0, 4, 8, 12, … so the low 2 bits of a word address are always 00.
0
1
2
3
word 0
4
5
6
7
word 4
8
9
10
11
word 8
Byte addresses grouped into words — the word address is its first byte.

MIPS-32 address space

QuantityValue
Total bytes2322^{32} bytes
Byte addresses023210 \dots 2^{32} - 1
Address of last byte23212^{32} - 1
Total words2302^{30} words
Word addresses0,4,8,,23240, 4, 8, \dots, 2^{32} - 4
Address of last word23242^{32} - 4
Why 2302^{30} words? 232 bytes÷4 bytes/word=230 words2^{32}\ \text{bytes} \div 4\ \text{bytes/word} = 2^{30}\ \text{words}. The last word starts 4 bytes before the end of memory, so its (first-byte) address is 23242^{32} - 4.

MIPS-64 (Autumn-24 Q3b)

“Calculate the address of the last word in MIPS-64, assuming everything is similar to MIPS-32.”

Scale the widths up by analogy. In MIPS-32 the address width (32) equals the word width (32 bits = 4 bytes). Keeping the same relationship for MIPS-64: 64-bit addresses, and a word = 64 bits = 8 bytes.

Total bytes=264Address of last byte=2641Word=8 bytes    last word address=2648\begin{aligned} \text{Total bytes} &= 2^{64} \\ \text{Address of last byte} &= 2^{64} - 1 \\ \text{Word} = 8\ \text{bytes} \;&\Rightarrow\; \text{last word address} = 2^{64} - 8 \end{aligned}
Primary answer: last byte = 26412^{64} - 1, last word = 26482^{64} - 8 (8-byte words). If your instructor keeps the word at 4 bytes (“similar” = same word size), then last word = 26442^{64} - 4 — state your assumption either way.

Max offset of a load (Spring-26 Q3c)

lw $s1, offset($s2): the offset lives in the 16-bit immediate field and is signed.
Max positive offset=2151=32767=01111111111111112\text{Max positive offset} = 2^{15} - 1 = 32767 = 0111\,1111\,1111\,1111_2

Machine instruction with the max offset (lw op = 100011, $s2 = 18 = 10010, $s1 = 17 = 10001):

100011op6 bits10010rs5 bits10001rt5 bits0111111111111111offset (16)16 bits
lw $s1, 32767($s2)