Memory Bank Addressing – Formula & Example
Guide
Reference Memory:
logic [63:0] mem [4095:0];
Base address a = 0x2000_0000, with 8 banks.
1■■ bank_start(n) = a + n * bank_size_bytes
Question: If each bank is 32 KB, what is the starting address of Bank 5?
bank_size_bytes = 32 KB = 0x8000
a = 0x2000_0000
n = 5
bank_start(5) = 0x2000_0000 + 5×0x8000 = 0x2002_8000
Answer: Bank 5 starts at 0x2002_8000.
2■■ bank_end(n) = bank_start(n) + bank_size_bytes - 1
Question: If Bank 5 starts at 0x2002_8000, what address does it end at?
bank_end(5) = 0x2002_8000 + 0x8000 - 1 = 0x2002_FFFF
Answer: Bank 5 ends at 0x2002_FFFF.
3■■ bank_number = floor((addr - a) / bank_size_bytes)
Question: Which bank contains address 0x2001_8ABC?
bank_number = (0x2001_8ABC - 0x2000_0000) / 0x8000 = 3
Answer: Address lies in Bank 3.
4■■ word_index = floor((addr - bank_start(bank_number)) / ws)
Question: Which mem[i] corresponds to address 0x2001_8ABC?
Each word = 8 bytes (since [63:0] → 8 bytes)
bank_start(3) = 0x2001_8000
word_index = (0x2001_8ABC - 0x2001_8000)/8 = 350
Answer: mem[350] within Bank 3.
5■■ byte_offset = (addr - bank_start(bank_number)) % ws
Question: Which byte within that word is being accessed?
byte_offset = 0xABC % 8 = 0x4
Answer: 4th byte within mem[350] (bits [39:32]).
6■■ mem[i] (bank n) covers start = bank_start(n) + i * ws; end =
start + ws - 1
Question: What address range does mem[20] in Bank 2 occupy?
bank_start(2) = 0x2001_0000, ws = 8
start = 0x2001_0000 + 20×8 = 0x2001_00A0
end = 0x2001_00A0 + 7 = 0x2001_00A7
Answer: mem[20] covers 0x2001_00A0 → 0x2001_00A7.
7■■ Write spill check
Question: If I do a 32-bit write (4 bytes) at 0x2000_0004, which part is modified?
bank = 0, word_index = 0, byte_offset = 4, ws = 8
4+4=8 → fits in same word
Answer: Bank 0, mem[0], upper 4 bytes (bits [63:32]).
If 8-byte write → spills into mem[1].
Recap Table
# Formula Question Type Quick Example
1 bank_start(n) Where does bank n start? Bank 5 → 0x2002_8000
2 bank_end(n) Where does it end? Bank 5 → 0x2002_FFFF
3 bank_number Which bank has this address? 0x2001_8ABC → Bank 3
4 word_index Which mem[i] in that bank? mem[350]
5 byte_offset Which byte within that word? Offset 4
6 mem[i] range What address range? mem[20] → 0x2001_00A0–A7
7 Write spill Does write cross next word? 32-bit @0x2000_0004 → mem[0]