You are encouraged to post any questions about the reading on the course discussion board!
After implementing a series of RAM chips we will now explore a few more details of our memory organization that will help us implement our final Memory
chip.
As we start talking about memory addresses more, we will use a new representation called hexadecimal. Hexadecimal is nice because it requires less digits than binary to represent numbers. It is also way easier to convert between hexadecimal and binary than it is between decimal and binary.
Hexadecimal is a base 16 number system, which means it uses 16 symbols for each digit. The symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. Notice how we use the first six letters of the alphabet once we run out of numbers! To help wrap your head around what these letters mean, we created a table with decimal, hexadecimal, and binary values.
decimal | hexadecimal | binary |
---|---|---|
0 | 0 | 0000 |
1 | 1 | 0001 |
2 | 2 | 0010 |
3 | 3 | 0011 |
4 | 4 | 0100 |
5 | 5 | 0101 |
6 | 6 | 0110 |
7 | 7 | 0111 |
8 | 8 | 1000 |
9 | 9 | 1001 |
10 | A | 1010 |
11 | B | 1011 |
12 | C | 1100 |
13 | D | 1101 |
14 | E | 1110 |
15 | F | 1111 |
Note that decimal numbers and hexadecimal numbers can look really similar! For example, if I give you the value 32
, how would you know that is 32
in hexadecimal or 32
in decimal? To solve this confusion, we will prepend hexadecimal numbers with 0x
to signify the digits to come are meant to be interpreted in hexadecimal. To read this representation, simply drop the 0x
and you have your hexadecimal digits. For example, if I write 0xFF
, I am specifying the hexadecimal value FF
.
To convert between decimal and hexadecimal numbers, we can use the same processes we used for binary but use a base of 16 instead of 2. For example, converting 0x2F
to decimal, we calculate 0x2F = 0x2 * 16^1 + 0xF * 16^0 = 32 + 15 = 47
.
We are omitting the process of going from decimal to hexadecimal since it's not the focus of this reading, but it follows as similar process as going from decimal to binary just using a base of 16 instead of 2.
Converting between hexadecimal and binary is actually really easy! Notice how 4 binary digits represent exactly the same number of values as 1 hexadecimal digit (2^4 = 16
which is the same as the number of symbols in hexadecimal). Using the table above, we can simply swap out each hexadecimal digit for the equivalent 4 digit binary value, or vice versa!
Here's a hexadecimal to binary example:
hexadecimal: 0xABCD
A = 1010
B = 1011
C = 1100
D = 1101
binary: 1010 1011 1100 1101
And here's a binary to hexadecimal example:
binary: 1011 0101 0110 1001
1011 = B
0101 = 5
0110 = 6
1001 = 9
hexadecimal: 0xB569
Notice how since our addresses in our computer use 16 binary digits, that means they use 4 hexadecimal digits. Often you will see memory addresses referred to in hexadecimal instead of binary because it is less verbose. Now you have the tools to convert between the two when you need to!
There are two devices our computer uses to interact with users: a screen and a keyboard. Chapter 4 does a good job describing these interfaces, so we won't repeat the information here. Specifically, just read sections 4.2.5 (a bit of review on symbols) and 4.2.6 (I/O Devices).
We will briefly review these interfaces in lecture before discussing a high level approach of their implementation.
In project 4 you will start the process of building our final computer by completing the Memory
chip. In lecture, we will talk more about how to implement this chip, as well as continuing to explore the Hack assembly language.