> For the complete documentation index, see [llms.txt](https://wiki.zacheller.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.zacheller.dev/hardware/nand2tetris/memory.md).

# Memory

**In a nutshell:** Having built the computer's ALU, this module we turn to building the computer's *main memory* unit, also known as *Random Access Memory,* or *RAM*. This will be done gradually, going bottom-up from elementary flip-flop gates to one-bit registers to *n*-bit registers to a family of RAM chips. Unlike the computer's processing chips, which are based on *combinational logic*, the computer's memory logic requires a clock-based *sequential logic*. We will start with an overview of this theoretical background, and then move on to build our memory chipset.

**Key concepts:** combinational vs sequential logic, clocks and cycles, flip-flops, registers, RAM units, counters.

## Sequential Logic

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIPw-8PXLxDZnIMigq8%2F-MIPw50yPlzPntsgWl2d%2Fimage.png?alt=media\&token=1d2550cf-a409-4b2d-abcc-c42f8ac2f217)

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIPw-8PXLxDZnIMigq8%2F-MIPwGYjU5zwqaJYK2Ji%2Fimage.png?alt=media\&token=f83f9076-2b7b-4c04-bfa9-1884437732eb)

* Why do we use discrete time steps instead of continuous time?
  * To ensure the system state is stabilized.

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIPwI1w-HARfkFw_HOz%2F-MIQ1d2q0kU2-R0i-SxY%2Fimage.png?alt=media\&token=cd2d8667-c0e5-4e59-b573-fa2c71725c7c)

## Flip Flops

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQ1iggX2F7o_OI3ytp%2F-MIQ1vdvsTsYHbm5cjdR%2Fimage.png?alt=media\&token=5dcf590c-06c2-490f-a0db-698c107779b9)

![Little triangle means chip is dependent on time, sequential, has state](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQ1wKwaJTaEk0FOqQr%2F-MIQ2dLxE-NrFj8M7Tj3%2Fimage.png?alt=media\&token=476e28b5-5fb2-43fb-a5e9-219bee5baa91)

* Implementation of the D Flip Flop
  * in this course: it is a primitive
  * in physical implementations, it may be built from actual Nand gates

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQ1wKwaJTaEk0FOqQr%2F-MIQ37nqiy4LjSewGG0i%2Fimage.png?alt=media\&token=ee7f3bfb-23ac-4ca9-a060-63fad75bc941)

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQ1wKwaJTaEk0FOqQr%2F-MIQ45pWHZeunrqqgfOh%2Fimage.png?alt=media\&token=4f0adcbb-912e-4cb1-a3de-3fc5448bfa8e)

* What are the differences between the DFF chip and the Bit chip?
  * DFF always stores the “in” bit, while Bit only stores it if “load” is set to 1.
  * DFF can store information for one time unit only, while Bit can store it for many cycles.

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQ1wKwaJTaEk0FOqQr%2F-MIQ4vcN7BPgqM-NZD62%2Fimage.png?alt=media\&token=686cfcbc-234c-4347-84d1-d05f1128bf45)

## Memory Units

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQ4ylEjrIiVANxNCSI%2F-MIQ6Y6SZlGVKKggP8xX%2Fimage.png?alt=media\&token=3f9a02db-fba2-4922-9282-a4e2b52897ed)

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQFxLlMHS5Dbvj-DmI%2F-MIQWOsm3f-Pm_xMFUT1%2Fimage.png?alt=media\&token=7ab17c2f-e5c7-4f96-a090-2cc884c9f20e)

Current value of a register is always being outputted.

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQFxLlMHS5Dbvj-DmI%2F-MIQYAZMF5m-2rA-JB3I%2Fimage.png?alt=media\&token=81256153-8fb7-46fe-9428-4b28461abe9d)

* What is the difference between a register’s width and a register’s address?
  * Width is the amount of data a single register holds, address is the location of the register within a larger chip.

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQFxLlMHS5Dbvj-DmI%2F-MIQYaXlWhUXeGvBzL5d%2Fimage.png?alt=media\&token=57dee270-efa2-4c3e-85e3-b038a92098e3)

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQFxLlMHS5Dbvj-DmI%2F-MIQYXonjhW8kDrT-nLc%2Fimage.png?alt=media\&token=b00eefd6-29a0-4db8-baeb-cf20eca953e9)

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQFxLlMHS5Dbvj-DmI%2F-MIQZJKfAW02C1rPDR7j%2Fimage.png?alt=media\&token=615060e2-4525-48d0-b383-f708a35b6e5d)

## Counters

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQFxLlMHS5Dbvj-DmI%2F-MIQZl4yEwJ4oYmQ0nye%2Fimage.png?alt=media\&token=e9e500a9-9d24-4dae-8f9a-7a0cacb581ba)

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQFxLlMHS5Dbvj-DmI%2F-MIQ_4_cxZGhDl8GxpgX%2Fimage.png?alt=media\&token=c9969e89-a37c-411d-9b45-52392d8c9b20)

## Project 3 Overview

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQ_IntA321VsJ30wnU%2F-MIQ_Q-M4m8KVIc9GiHy%2Fimage.png?alt=media\&token=c442cd4c-ec7b-40e8-a086-b473de2ef2d1)

![16 bit register can be built from multiple 1-bit registers](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQ_IntA321VsJ30wnU%2F-MIQ_cXXI5RcfNG8pR_G%2Fimage.png?alt=media\&token=388c3371-c4ef-4f89-9456-bf50143ae6f3)

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQb-_7zRYhG9HrNM8S%2F-MIQcJ6vgK27TYiRk_66%2Fimage.png?alt=media\&token=abaac31d-7139-4925-9dcc-cdc7cedad446)

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQcN91rrfTOSBkoeqx%2F-MIQfFR-3GqzjCvwSeg5%2Fimage.png?alt=media\&token=ccba457b-aa73-4d4c-adc4-3a07f12b873c)

![](https://1094113337-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M3hoduT4ByoNaznkzhG%2F-MIQfK_LpaJLyiI6IGMJ%2F-MIQn8JAxtqNqaXeCpZa%2Fimage.png?alt=media\&token=62437111-ac88-4303-98a7-01e7cac44c52)
