I am looking at page 49 of the book The elements of computing systems. It shows a register and after a register the Ram. I am confused what an address is. Could you explain to me what a address is? What does it do?
A register is a memory storage unit that stores a specific number of ordered bits. For the Hack computer the number of bits that a register stores is 16 bits; that is, w equals 16.
Registers are sequential logic devices whose value may be reset to the "in" value at during each clock cycle provided the load bit is asserted (set to logic "1"). In the next clock cycle the value that was set during the load will be emitted on the chip's "out" pins. If the load bit is not asserted (set to logic "0"), the register merely emits the last value that was set on its "out" pins.
RAM is a collection of registers arranged kind of like a linear array as implemented in many programming languages. The address is used to select exactly one of the registers in the array of the RAM array registers. The RAM register that is selected may be "read" or "written". An address is a non-negative integer value also specified as a set of bits. This binary represented integer acts as the index into the array. The physical implementation of the RAM is, of course, much more complex that the visualization model of an array.
RAM modules are built to be of a fixed number of identical registers, each with its own unique address - its index in the RAM chip array. The illustration on page 49 shows a generalized RAM chip containing "n" registers. If "n" equals 8, there are eight distinct registers and eight addresses (0 thru 7). If "n" equals 16K there are 16,348 fregisters having addresses 0 thru 16383. In each register, though, a 16-bit value is stored.
In addition to the array of "n" registers, the RAMn chip contains additional logic to connect the 16-bit input pins to the corresponding "in" pins of the register "addressed" by the address value. If the load bit is asserted during a clock cycle, the RAMn chip "in" value is written to the addressed register, overwriting whatever value is currently there. Additionally, there circuits to connect the "out" pins addressed register to the "out "pins of the RAMn chip.
That chip will take as input a 16-bit value, a load bit, and an address that is used to specify which of the 8 registers should be outputted by the chip's 16-bit output.
For RAM8, k is 3 because you will need a 3 bit address to be able to address any of the 8 registers. Why 3 bits? Because with 3 bits, each a 0 or 1, you have 2x2x2 = 8 possible addresses, specifically addresses 0, 1, 2, 3, 4, 5,6,7. If k were less than 3, the chip would be impossible to build. k could be greater than 3, but it would be a waste of unused bits. You only need 3 bits to be able to address 8 possible addresses.