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
…
MIPS-32 address space
| Quantity | Value |
|---|---|
| Total bytes | bytes |
| Byte addresses | |
| Address of last byte | |
| Total words | words |
| Word addresses | |
| Address of last word |
Why words? . The last word starts 4 bytes before the end of memory, so its (first-byte) address is .
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.
Primary answer: last byte = , last word = (8-byte words). If your instructor keeps the word at 4 bytes (“similar” = same word size), then last word = — 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.Machine instruction with the max offset (lw op = 100011, $s2 = 18 = 10010, $s1 = 17 = 10001):