NAND2GO Chapter 5. Computer Architecture
1. Context |
Learn about all the chips built in Chapter 1-3 and machine language. Complete Chapter 1-4. Learn about boolean logic and sequential logic. Learn about the syntax of machine language. Basically know about assembly and its translation to machine language. | ||
2. Goal |
Learn about von Neumann architecture. Understand the connection between hardware and software. Complete a computer which is able to run programs in machine language with chips in chapter 1-3. Be familiar with machine language and assembly. Provide a hardware platform for following chapters. Understand how a modern computer works at the hardware level. Know memory allocation. | ||
3. Measurable Effects |
Complete a computer which is able to run programs in machine language with chips in chapter 1-3 in HDL and pass all of the test scripts. | ||
4. Outputs | 5. Process | 6. Inputs | |
CPU memory computer in HDL |
Base on the syntax and structure of machine language instructions, determine which chip can realize the functions of each part of an instruction. Analyst the data flow and connect the chips. Connect CPU and I/O devices to memory base on von Neumann architecture. |
Elements of Computing Systems p.79-101 chapter 5 Hardware stimulator von Neumann architecture chips built in chapter 1-3 Machine language (binary code) | |
7. External Factors |
Introduction
This chapter is the last chapter of hardware part. In chapter 1 and 2 we combine logic gates in order to do any types of calculations, but the size of the circuit would increase infinitely when the complexity of the calculation increases. To solve the problem, chapter 3 introduces the concept of sequential logic in order to store the data. The machine language introduced in chapter 4 is also very close to hardware, for it is binary code, in other words, a set of 0s and 1s, which is suitable for hardware that deals with only boolean signals. Finally, in this chapter, we are going to build a computer which can both calculate and remember like human does, in the instruction of von Neumann architecture.
von Neumann architecture
The von Neumann architecture is the most widely used computer architecture in modern computers, which contains 3 parts, CPU, memory and I/O devices. The connection between them is as Figure 5.1. The memory receives data from CPU and input devices and also provides data for CPU and output devices. Not only data but also instructions are stored in memory, which tells the CPU what to do.
Fig 5.1 von Neumann architecture
Memory
Memory is an important part of the computer, which stores all the data and instructions and links the CPU with the I/O devices. Memory consists of a series of registers, each of which can store a 16-bit binary number. To access a specific register, an address or in other words, a serial number of it is needed. According to the reading and writing permissions, there are two types of memory, random access memory (RAM) and read-only memory (ROM).
Data Memory (RAM)
In a program, there are usually many variables which can be read or modified at any time, therefore these variables are stored in RAM. From its function, we know RAM has a least 3 inputs, an address that determines which register to access, a number that CPU output, and a single bit that determine whether modifying the register with the input number or not. Then the RAM returns the number stored in that register to the CPU.
Instruction Memory (ROM)
Instructions are programs in machine language. To ensure the stability of the program, the program itself is not allowed to be modified while running, so the instructions are stored in ROM. Though the instructions cannot change, the order of execution is not unique. The order of execution is precisely the order they are read. Obviously, the input is only one, that is the address CPU sends for fetching an instruction each time, and the output is the instruction at the address.
I/O Memory
To operate the computer, we also need some output devices to observe the status of the computer and some input devices to control it. Because these devices also produce and receive data, they are connected to RAM as well, and some special area is reserved for them. In this course, the input device is a keyboard that needs only one register to reflect which key is currently pressed, while the output device is a screen that shows the memory area in real time. These areas can also be read and modified by CPU, so they are parts of RAM.
CPU
CPU is the core and the most complex part of the computer, which not only executes the programs but also controls the screen and responds to the keyboard. A program in machine language consists of a series of instructions, which tell the CPU what to do. There are 2 categories of instructions, A-instruction and C-instruction, either of which is a 16-bit binary value with the specific syntax.
A instruction
As it is mentioned in chapter 4, an A-instruction is used for storing a constant value into the A register. An A-instruction has a general formula "0vvv vvvv vvvv vvvv", where "0" tells this is an A-instruction, and the following 15-bit value is the value that should be stored into A register. The full name of A register is addressing register, which has 3 functions. First, it provides constants for ALU to compute. Second, it provides the address for CPU to access the RAM mentioned before. Third, it tells the CPU address of the instruction that should jump.
C-instruction
Unlike A-instruction, C-instruction can almost do everything. C-instruction tells the CPU what to compute, where to store the computed value, and what to do next. It has the general formula of "111a cccc ccdd djjj". The leading 1s represent that this is a C-instruction, and the other can be divided into 3 fields, comp, dest, and jump, which answer the 3 questions respectively.
What to compute
The comp field answer the question what to compute. comp stands for computing, and consists of 1 "a" bit and 6 "c" bits. The chip corresponding to this field must be ALU. According to chapter 2, ALU has 2 data inputs and 6 control bits. According to figure 4.2, one data input of the ALU always comes from a register called D register. D register stands for data register, because it always provides data. The other data input comes from A register or memory, which is decided by the "a" bit. Here, a multiplexor is needed for selecting data from A register and memory, the selection bit is precisely the "a" bit.
Then we focus on "c" bits. When we compare the ALU truth table in figure 2. to figure 4.2, it is easy to find that "c" bits play the role of control bits of ALU, which tells the ALU which type of operation should be performed on input data.
Where to store the computed value
The dest field answer the question where to store the computed value. dest stands for destination, consisting 3 "d" bits. These 3 bits tells CPU whether storing the computed value into A register, memory and D register respectively. For A and D registers, these "d" bits is their load bits, and for memory, this bit is one of the outputs of the CPU because memory is not in CPU. All of their data input is the computed value from ALU.
What to do next
The jump field answer the question what to do next. Although jump stands for jumping, the program is usually executed in the order of the instructions stored in ROM. However, to solve more problem, a program usually contains branches and loops. Generally, jumping forward means branch and jumping backward means loop. To realize these functions, there is a special register called program counter which stores the address of the next instruction and fetches it from ROM. Unlike other registers, the value in program counter plus one in every clock cycle if its load bit is zero. The load bit is determined by this formula, Load=Or(And(Not(Or(zr,ng)),j[1]),Or(And(zr,j[2]),And(ng,j[3]))), where zr and ng stand for whether the computed value is zero and negative and j[1], j[2], j[3] stand for the 3 "j" bits of jumpfield. zr and ng are also the output of ALU. When the load is one, the address in A register will be assigned in program counter, and the program "jumps" to that address. Moreover, sometimes we need to reset the whole computer to run the program again. At this time, the program counter is set to zero and the program goes back to the 0th instruction.
Fig 5.2 CPU implemtation
Overview of CPU
As it is explained before, CPU fetches an instruction from ROM, decodes and executes it. Figure 5.2 shows the connection between each chip
Perspective
In this project, we learn how machine language controls the machine, and get familiar with machine language. This can largely help understanding assembly and writing assembler in chapter 6. What is more, understanding the von Neumann architecture really helpful for other program language learning, especially those with "pointer", which stands for address of memory.
Glossary
von Neumann architecture
Central Processing Unit, CPU
Memory
Register
Arithmetic Logic Unit, ALU
Program Counter, PC
Machine Language
Instruction
References
Description: References are divided into books, journal articles, audio recordings, videos, web pages, research reports, etc. Please select the appropriate template for reference according to your needs.
- Noam Nisan & Shimon Schocken,《The Elements of Computing Systems: Building a Modern Computer from First Principles》, 1st Edition, MIT Press, 2005, ISBN:9780262640688, ,