Skip to content

Memory and I/O

The system around the CPUThe CPU sends every load and store to the address decoder, which picks data memory, stack, video mode A or MMIO by the address. Doom adds video mode B and the SDRAM behind two caches.Instruction memory16 KB on chip · the program .hexCPUmips_pipeline5 stages · 25 MHzlw / swAddressdecoderlife_system.vno region → haltE + cause on HEXData memory · 16 KB0x1001_0000 · e.g. the Life boardsStack · 4 KB0x7FFF_E000Video mode A · 128×960x1004_0000 · one word per pixelMMIO0xFFFF_0010 · SW, KEY, LEDR, HEX, timerVideo mode B · 320×200 + palette0x1005_0000 · one byte per pixelCaches → SDRAM · 64 MB0x2000_0000 · I-cache 8 KB, D-cache 16 KBDoom + WAD loaded over JTAGVGA monitor640×480Board I/OSW · KEY · LEDR · HEXDoom: instructions come from the SDRAM through the instruction cache
Game of Life and the graded programs (top_life, top_program)added for Doom (top_doom)halt on an invalid address

Data, framebuffer, stack and MMIO follow MARS’s default memory map, so every program can be checked in MARS first. Text starts at 0 because the spec asks for an initial PC of 0.

Region Addresses Size Used by
Text (code) 0x0000_0000 – 0x0000_3FFF 16 KB (4,096 instructions) Every program. PC starts at 0
Data 0x1001_0000 – 0x1001_3FFF 16 KB .data: the algorithm’s inputs, the Life boards
Framebuffer, mode A 0x1004_0000 – 0x1004_BFFF 48 KB (128 × 96 words) Game of Life
Stack 0x7FFF_E000 – 0x7FFF_EFFF 4 KB $sp starts at 0x7FFF_EFFC
MMIO 0xFFFF_0010 – 0xFFFF_0027 6 registers Switches, keys, LEDs, HEX, timer, video mode
Framebuffer, mode B 0x1005_0000 – 0x1005_F9FF 62.5 KB (320 × 200 bytes) Doom only
Palette, mode B 0x1005_FC00 – 0x1005_FFFF 256 words Doom only
SDRAM 0x2000_0000 – 0x23FF_FFFF 64 MB Doom only: code, data, heap and the WAD

Big-endian everywhere: the byte at the lowest address is the most significant one (bits 31–24) of the word, in the instruction memory, the data memory, the assembler’s images and the Doom build.

Timing: every memory reads on a clock edge, so Quartus can build it from the FPGA’s memory blocks (M9K). Data memory, stack, framebuffer and MMIO work on the falling edge: the address is ready in the first half of the cycle, and the data in the second.

Address Register Access What it does
0xFFFF_0010 SW read Bits 9–0 = the 10 switches
0xFFFF_0014 KEY read Bits 1–0 = the 2 keys, 1 = pressed (inverted and debounced in hardware)
0xFFFF_0018 LEDR write Bits 9–0 = the 10 LEDs
0xFFFF_001C HEX write Bits 23–0 shown in hexadecimal on the 6 displays
0xFFFF_0020 TIMER read Milliseconds since reset (Doom’s clock)
0xFFFF_0024 VIDEO_MODE write 0 = mode A, 1 = mode B

So reading a key is lw $t1, 0x14($s4) with $s4 = 0xFFFF_0000, and showing a number is sw $k0, 0x1C($s4): the same instructions as for any memory. rtl/mmio.v synchronizes the switches, debounces the keys (10 ms) and drives the displays.

  • Register view: with SW9 up, the HEX displays show a register instead of the program’s output. SW4–SW0 pick the register (HEX5–HEX4 show its number in decimal), HEX3–HEX0 its value (bits 15–0, or 31–16 with SW5 up).
  • This is how we read the graded algorithm’s result on the board (Algorithm).

The spec asks to stop invalid accesses visibly. The CPU halts, and the failing instruction writes nothing (no register, no memory), when:

  • an instruction is fetched outside the text region or from an address not aligned to 4, or
  • a load or store goes to an address outside every region above, or is misaligned for its size.

Older instructions finish; the failing one and every younger one are dropped. Only a reset leaves the halt.

On the board Meaning
LEDR9 on Halted
LEDR1–0, HEX4 Cause: 1 = fetch, 2 = load, 3 = store
HEX5 E
HEX3–HEX0 The bad address, bits 15–0 (SW8 up: the PC instead)

Example (halt.do): sw to 0x7FFF_F000, just past the stack, halts with LEDR = 0x203 and HEX = E3F000.