ELEC0010 Digital Design
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
ELEC0010 Digital Design
MICROPROCESSOR ARCHITECTURE AND IMPLEMENTATION
Introduction
We have examined the SystemVerilog descriptions of combinational and sequential building blocks used in digital systems, including arithmetic circuits, counters, register files, and memory arrays. The ELEC0010 lab will involve combining these building blocks to form a microprocessor microarchitecture. This document provides a recap of the lecture course in the first-year course ELEC0004 Digital Electronics 1, and is a reference guide for your lab activities.
The first step in designing a microprocessor is to define the architecture of the computer. The architecture is the programmer’s view of a computer. It is defined by the instruction set (the language) and operand locations (registers and memory).
The words in a computer’s language are called instructions. The computer’s vocabulary is called the instruction set. All programmes running on a computer use the same instruction set. Even complex software applications are compiled into a series of simple instructions such as add, subtract, and jump. Computer instructions indicate both the operation to perform and the operands (the values) to use in the operation. The operands may come from registers or from the instruction itself.
A computer architecture doesn’t define the underlying hardware implementation. Often, many different hardware implementations of a single architecture exist. For example, Intel and AMD sell various microprocessors based on the same x86 architecture. They can all run the same programmes, but have different underlying hardware. The underlying hardware is called the microarchitecture.
In this section, we will start by examining a simple computer architecture, and then examine a microarchitecture implementation of it.
1 INSTRUCTION SET ARCHITECTURE
Assembly language is the human-readable representation of the computer’s native language, which is called machine language. Each assembly language instruction specifies both the operation to perform and the operands which will be operated on. We’ll start by looking at simple arithmetic instructions and show how these operations are written in assembly language. We’ll then define the instruction operands which are stored in registers or as constants in the instruction itself.
1.1 Assembly language instructions
The codes below are for arithmetic operations on b and c with the results written into a. The code shown on the left is in a high-level language (using the syntax of e.g. C, C++, or Java), and the equivalent assembly language code is written on the right.
High-Level Code |
Assembly Code |
a = b + c; a = b – c; |
add a, b, c sub a, b, c |
The first part of the assembly instruction, e.g. add, is called the mnemonic and indicates what operation is to be performed. The operation is performed on b and c (the source operands), and the result is written into a (the destination operand). Instructions operate on, at most, two source operands. More complex high-level code translates into multiple assembly language instructions, as shown in the example below:
High-Level Code |
Assembly Code |
a = b + c - d; // Complex high-level code |
sub t, c, d # t = c – d add a, b, t # a = b + t |
Note that, in the high-level language example, comments begin with //, while in assembly language, they begin with #.
1.2 Operands: Registers and Constants
In the assembly code examples above, the variables a, b, c and t are all operands. But computers operate on 1’s and 0’s, not variable names. The instructions need physical locations from which to retrieve the binary data, and to which the resulting binary data can be stored. Operands can be variables stored in binary form in registers, or they may be constants stored in the instruction itself.
We will consider an 8-bit computer architecture. This means it uses 8-bits to represent the operands.
Registers
Most computer architectures specify a number of registers that hold the operands. In the architecture we are considering, there are 16 registers, forming what is called the register file. Each register can store an 8-bit word. The register file can be implemented as a 16 × 8-bit static random-access memory (SRAM) array.
In assembly code, the register names are preceded by the letter x. The 16 registers in the register file are referred to as x0, x1, x2, x3, … x15. Registers x1 to x15 inclusive can be written to by the user. Register x0 always holds the value 0 and cannot be written to, as 0 is a useful value to have readily available. The example below shows the add instruction with the variables a, b and c placed in registers x1, x2 and x3.
High-Level Code |
Assembly Code |
a = b + c; |
# x1 = a, x2 = b, x3 = c add x1, x2, x3 |
Constants/immediates
In assembly language, constants contained within the instruction are called immediates (since they are immediately available from the instruction itself, and don’t require a register access). Add immediate (addi) is a common assembly language instruction that uses an immediate operand.
Examples of code using immediate instructions are shown below.
High-Level Code |
Assembly Code |
a = b + 4; |
# x1 = a,x 2 = b addi x1, x2, 4 |
a = b – 12; |
# x3 = a, x4 = b addi x3, x4, -12 |
a = 9; |
# x7 = a addi x7, x0, 9 |
1.3 Machine language
Assembly language is convenient for humans to read. However, digital circuits understand only 1’s and 0’s. Therefore, a programme written in assembly language is translated from mnemonics and register names to a representation using only 1’s and 0’s, called machine language.
The architecture we are considering uses 24-bit instructions (Instr23:0), consisting of:
• a 4-bit field indicating the operation (this is called the op code),
• three 4-bit fields containing the three register addresses (the destination register and the two source registers)
• an 8-bit field containing an immediate value
The instruction format is shown below.
operation code |
destination register |
source register 1 |
source register 2 |
immediate value |
4 bits
[23:20]
4 bits
[19:16]
4 bits
[15:12]
4 bits
[11:8]
8 bits
[7:0]
This instruction format allows up to 24 = 16 possible operations, and allows all 24 = 16 registers in the register file to be addressed. The op code for the add operation is 0010, for the sub operation it’s 0011, and for the addi operation, 0110 is used. The full set of operations and the corresponding op codes for this architecture will be listed later on.
Some examples of assembly code translated into machine code are given in the table below:
Assembly code |
Machine code |
||||
|
op code |
destination register |
source register 1 |
source register 2 |
immediate |
addi x4, x6, 30 |
0110 |
0100 |
0110 |
0000 |
00011110 |
sub x3, x5, x12 |
0011 |
0011 |
0101 |
1100 |
00000000 |
add x1, x2, x3 |
0010 |
0001 |
0010 |
0011 |
00000000 |
Unused fields (e.g., the immediate field in the add and sub instructions, and the source register 2 field in the addi instruction) can be simply set to zero. The machine code can also be represented in hex (with six digits per instruction), as follows.
Assembly code |
Machine code |
||||
|
op code |
destination register |
source register 1 |
source register 2 |
immediate |
addi x4, x6, 29 |
6 |
4 |
6 |
0 |
1 E |
sub x3, x5, x12 |
3 |
3 |
5 |
C |
0 0 |
add x1, x2, x3 |
2 |
1 |
2 |
3 |
0 0 |
The instructions are stored in a programmable memory array, called the instruction memory. The instruction memory has an 8-bit address, and its size is 256 × 24 bits. The figure below shows how machine instructions are stored in memory:
A229mdlV Oob9
2才oT9b qTo且T6mm9
M9moTV AbbT922
|
ln2才TuO才ion m9moTV
qD
Program memory
To run or execute the programme, the processor fetches the instructions from memory sequentially (one after the other). Each fetched instruction is decoded and executed by the digital hardware. The address of the current instruction is kept in an 8-bit register called the programme counter (PC). To execute the lines of code in the example above, the value of PC is set to the address of the first line of the code, 00000100 (which can be conveniently written in hexadecimal as 0x04). The processor reads (fetches) the instruction at that memory address and executes the instruction (add x1, x2, x3). The processor then increments the value of the programme counter (PC) to the next memory address (0x05), fetches that instruction (sub x3, x5, x12) and executes it, and keeps repeating this process.
The architecture we are considering has 8 instructions, performing arithmetic operations (addition and subtraction on two variables, addition on one variable and one constant), logical operations (bit-wise AND and OR, either on two variables, or on one variable and one constant), and a conditional branch operation (the programme counter jumps to a new value in the case of two variables being equal). The detailed description of each of these instructions, and the corresponding assembly code mnemonics and op codes, are listed in the table below (In this table, rs1 and rs2 refer to source register 1 and source register 2, respectively, and rd refers to the destination register).
2023-02-27
MICROPROCESSOR ARCHITECTURE AND IMPLEMENTATION