Fundamentals of Computing System (4)

Fundamentals of Computing System (4)

1. Instruction set structure

In the last chapter, we talked about the hardware components of the computer: from its most basic electronic components to the entire von Neumann system, the C language can help us understand how the programming language we know gives instructions to the computer. But there is a generation gap between C language and hardware: machine instructions . Machine instructions can be simply understood as: a binary sequence that has been given meaning. Due to the circuit structure of the computer, the machine can only read binary sequences. The c language must be translated into machine instructions according to the rules before it can be read and executed by the machine. This meaningful set of binary sequences is called the instruction set structure (ISA).

Concept in the book: The instruction set structure indicates all the information that needs to be paid attention to when writing software on a machine.

2. Starting from the software (or C language)...

We will simulate a simple computer: DLX to learn computer principles. (Because computers in real situations are much more complicated due to super evolution!)

In general, DLX specifies three types of instructions:

Fundamentals of Computing System (4)

Opcode [31 to 26 bits]: specifies the types and differences of instructions. When it is 000000, it means the instruction is of type R; otherwise, it is of type I or R.

According to the different types of instructions, there will be various regulations as shown in the figure. The terms are explained below:

  1. SR1/SR2: indicates the source register, generally used to write or read data in the register

  2. DR: Indicates the target register, generally used to write calculated data

  3. Imm16: indicates a sixteen-bit immediate number; PC: indicates the process of the control unit, which will be explained in the base address + offset part of the next chapter

  4. Function: The internal classification of the I type, the 6-digit number is basically the same as the classification of the R type. Such as: 000001 means addition

The following figure lists some basic instructions of DLX, which can be compared by yourself:

Fundamentals of Computing System (4)

3. Starting from the hardware...

We arranged the DLX memory and marked the serial number: x00000000, x00000001 …… x40000000 …… xFFFFFFFF. This corresponds to the pointer in the C language , but it should be noted that the memory corresponding to the C language is big-endian storage , while the memory of DLX is little-endian storage . Use an example to visualize the difference between the two:

0001 0010 | 0011 0100 | 0101 0110 | 0111 1000

In the memory corresponding to the C language, it means x78563412.

In the memory of DLX, it means x12345678.

Registers are around the CPU to store temporary data to speed up operation. For DLX, there are 32 general-purpose registers and 32 floating-point registers. We mainly discuss general-purpose registers, which are represented by unique identifiers: R0, R1, R2, ... R31

Note: We stipulate that the value in R0 is always 0, because if you do not leave a register to clear the register (return to 0 operation), you cannot reset the entire register file.

4. Still confused? A simple example

Fundamentals of Computing System (4)

What kind of instruction is shown in the figure above?

The answer is to add the values ​​in R0 and R1 and store them in R2. Since R0 is always 0, this instruction should be expressed in C language thinking as value (R2) = value (R1).

Fundamentals of Computing System (4)

In the above figure, the first 6 bits are 000001, which means I type, value (R4) = 6, and the immediate value is 14, then it means value (R1) = value (R4) + 14, that is, 20 is written into R1

Five, matters needing attention

The instruction set contains many operations unique to binary, and even pointers, references, and dereference operations. You must understand and master them in order to understand the underlying computing logic of the computer.And the safety degree expires the final exam.

Guess you like

Origin blog.51cto.com/14930847/2674937