10 min readJust now
–
This post does not reflect the views of current, past, or future employers. The opinions in this article are my own.
When I was a sophomore in high school my parents bought our first computer — an Atari 800! It was an awesome system and I spent many an hour hacking on it. One of the most interesting features was PEEK and POKE. PEEK reads a memory location, and POKE writes a memory location. The memory locations didn’t have to be actual memory, they could be registers. PEEKing a register could be done to read some state, and POKEing a register could be done to produce side effects. POKE was the interface to change graphics modes, invoke the sound generator, or change character set (e.g. highlight or invert characters on the screen). This was the days before everything was documented, so POKEing random locations and to see what happens was a fun pastime of the geek crowd! :-)
**My favorite book in high school **(much more fun than having to read the Brothers Karamazov!). The book documented many memory mapped I/O registers in the Atari 800 that can be PEEKed or POKEd.
By today’s standard’s, the Atari 800 is quaint and simplistic. Nevertheless, I believe it was a great learning platform for the basics of computer function and how a CPU interacts with memory and hardware. With that in mind let’s take a look at how CPUs interact with memory and I/O devices using memory addresses and memory mapped I/O in a modern system.
Memory addressing
Memory addresses are fundamental. For instance, pointers in C or C++ are in actuality memory addresses from the system’s point of view. A memory address is a reference to a specific memory location in memory used by both software and hardware. These addresses are fixed-length sequences of bits, typically displayed and handled as unsigned integers. Programming language constructs treat the memory like an array like with pointers.
Physical addresses
A computer’s main memory, or RAM for Random Access Memory, consists of many memory locations, each identified by a unique physical address. CPUs and other devices use these identifiers to access the corresponding memory locations. Usually, only system software, like BIOS and operating systems, directly addresses physical memory using machine code instructions. The instructions tell the CPU to interact with a hardware component called the memory controller.