liveBook · Manning

Memory

As explained in Rust in Action: Systems programming concepts and techniques

RAM is volatile computer memory that stores data and instructions available to a running processor.

RAM gives a CPU a place to store bytes it can read as instructions. In a CHIP-8 emulator, memory is a 4,096-byte array; the CPU reads an opcode from the current address, advances its position, and executes the instruction. section 5.7.3

Listing 5.23 Defining a CPU struct
1 struct CPU {
2   registers: [u8; 16],
3   position_in_memory: usize,      #1
4   memory: [u8; 0x1000],
5 }

The CPU structure places its registers, instruction position, and 4 KB memory array together. section 5.7.3

Memory also holds function code: a sequence of opcodes can be converted to bytes and copied into RAM. A stack stores return addresses so the CPU can resume after a function call. section 5.7.4

Loading function bytes

A short addition function is represented as six bytes and copied into memory at address 0x100. section 5.7.4

Memory is also a shared resource managed by the operating system. Programs’ views of memory, pointers, and memory management help explain how applications interact with the OS and affect performance and memory use. Creating threads also demands memory. section 6.0 section 10.2.4

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Models RAM as a fixed byte array and demonstrates instruction reads and function loading, while broader OS memory behavior is introduced through examples.
Examples
Shows a 4 KB CHIP-8 memory array, function bytes loaded at 0x100, and memory demand from threads.
What it assumes
Assumes no prior exposure to memory topics and develops them through examples.
What you can do after
Build it from scratch by adding a memory array to a CHIP-8 CPU and loading function opcodes into RAM.
How it connects
Connects memory with CPUs, opcodes, stacks, pointers, operating systems, and threads.

Also explained in

Compare how 14 books explain memory →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.