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













