Full picture
10

Random-Access Memory (RAM)

10.1 Overview

The components we saw previously already let us have a simple, yet capable computer up and running. The CPU will read the instructions from the ROM and execute them. At that point, the program must be fairly simple as it doesn't have any memory space apart from the CPU registers. It cannot even call functions. This is where the Random-access Memory, or RAM, comes in.

The RAM will give us an area of memory to store any kind of temporary data that can be written to or read from. While it is very efficient in terms of access time, it loses all the data it stores when the power is off.

10.2 Hardware implementation

On Zeal 8-bit Computer, the RAM component is the Alliance AS6C4008 chip, referenced U3 on the PCB. It is presented in a DIP-32 package in a socket. This component offers 512KB of static memory, that doesn't need to be refreshed, as opposed to dynamic memory. It is mapped at the physical address 0x80000 (512KB), so it follows the ROM.

The RAM is primordial on a computer, not only because the programs will use it to store data, but also because it is required by the CPU when calling and returning from routines. Indeed, the Z80 has a special 16-bit register, called SP, that must always point to RAM. When the CPU performs instructions call, ret, push, pop, it will read or write the RAM at the address pointed by that register.

Zeal 8-bit Computer doesn't present any memory protection, even for the RAM, this makes it possible to not only read and write to RAM but also execute code from RAM. This is very handy when executing self-modifying code or operating systems that require their code to be adjacent to their data.

In terms of pinout, here is how it is organized:

RAM pinout
Pinout of the RAM

Let's see the regular signals connected to it:

  • $ADDR\ 0$ to $ADDR\ 18$: represent the address of the byte to read or write. The lines $ADDR\ 0$ to $ADDR\ 13$ come from the CPU directly, and $ADDR\ 14$ to $ADDR\ 18$ come from the MMU.
  • $DATA\ 0$ to $DATA\ 7$: represent the byte that was just read from the ROM.
  • $\overline{RD}$: signal coming from the CPU, active when the CPU is performing a read.
  • $\overline{WR}$: signal coming from the CPU, active when the CPU is performing a write.
  • $\overline{CE}$: signal coming from the logic glue, active when the CPU tries to access the address range where the RAM is mapped: from physical address 0x80000 to 0xFFFFF. More info in the logic glue chapter.

10.3 Hardware dependencies and timing

Just like the ROM, the RAm depends on the MMU, to get all the required address lines, and the logic glue, as it generates the $\overline{RAM\_ENABLE}$ signal.

In fact, this signal is connected to the RAM's $\overline{CE}$ pin.

In terms of timing, the AS6C4008-55PCN has a propagation delay of at most 55ns, which makes it very fast and doesn't require the CPU to wait for any extra clock cycle when executing a read or write instruction. As such, the fastest way to access to write or read RAM when using the CPU is to use any instruction that involves registers only (7 T-states):

  • ld a, (de)
  • ld a, (bc)
  • ld a, (hl)
  • ld b, (hl)
  • ld c, (hl)
  • ld d, (hl)
  • ld e, (hl)
  • ld h, (hl)
  • ld l, (hl)

It is also possible to use the block copy instructions, such as ldi, ldir, ldd, or lddr.

All the details about the delay and timings are explained in the official datasheet.

📝 Going further...

As noted above, reading or writing to RAM requires at least 7 T-States, even though the RAM is fast enough to do it in less than 1 T-States. This is due to the Z80 CPU, it needs more clock cycles to read the instruction and execute it.

As such, the fastest way to access the RAM would be to bypass the CPU and have a component communicate with the RAM directly, using less clock cycles. This is the main principle of Direct Memory Access, or DMA, implemented by some components, such as Zilog's Z84C10 DMA Controller. It will be programmed by the CPU and then perform copies (read or write) from any address, not only RAM's range, to any address, without going through the CPU, making transfers much faster.

Zeal 8-bit Computer doesn't present any DMA controller but it is possible to connect one to the extension port. More info about the extension port in the dedicated section.