The past and present life of assembly language

0 and 1 in computers are represented by the state of electricity. Specifically, disconnected is 0 and connected is 1. Naturally, this also corresponds to binary. The binary adding machine of the past era was an epoch-making product, capable of adding two 8-bit binary numbers in real time, although it seems very low today.

Insert image description here

Figure 1 Binary adder (real-time circuit)

Registers (temporary registers) are composed of multiple flip-flops, and registers are multiple inputs and multiple outputs. The flip-flop has a single input and a single output, and the input becomes the output only after the latch command is executed.

Insert image description here

Figure 2 Schematic diagram of the trigger (triggered by executing the latch command)

Insert image description here

Figure 3 Register (composed of 8 flip-flops)

Registered adding machine:

Insert image description here

Figure 4 Adding machine with register

Command:
● Preset: perform latch operation
● Add: add the data in the input and register.
Continuous addition can be realized.

A machine that can do four arithmetic operations.
This is a functional improvement on the previous section. It is mainly reflected in the improvement of the circuit. On the original basis, three circuit functions of subtraction and division have been added.
Insert image description here

Figure 5 Four arithmetic operation circuits

Machine instructions:
Insert image description here

Figure 6 Four arithmetic circuits

The calculation process of the formula with brackets in the four-register circuit with one register:
● Input the toggle to 207, press "Preset", latch 207
● Input the toggle to 9, press "Add", after adding 207 and 9 Latch 216
● At this time, you need to calculate (56-48), but the register is occupied, take out 216 and write it down
● Enter the toggle as 56, press "Preset", latch 56
● Enter the toggle as 48, press " "Subtract", 56 and 48 are subtracted and 8 is latched
● At this time, (216/8) needs to be calculated, but the register is occupied, take out 8 and write it down
● Enter the toggle to 216, press "Preset", and latch 216
● The input toggle is 8, press "divide", 216 is divided by 8 and latches
more than 27. It is a machine with one register. The pain point is that when performing complex calculations, additional intermediate results need to be recorded.
How to solve pain points? The answer is "add registers"
Below, is a machine with two registers:
Insert image description here

Figure 7 Four-register arithmetic circuit (improved version)

For each operation switch, add a lower switch. As the number of registers and types of operations increase, switches will also increase. In the long run, this is not a long-term solution, and a better method needs to be found.
A row of binary numbers is designated as an instruction, which is an execution command given to the machine. When will it be executed? Press the "Go" switch.
Insert image description here

Figure 8 Instruction binary

The process of calculating (207+9)/(56-48) using a machine with two registers:
● Input toggle is 207, input command is 00001, latch 207 to R
● Input toggle is 9, input command is After adding 00101, 207 and 9, latch 216 to R
● At this time, (56-48) needs to be calculated, but the register is occupied, take out 216 and write it down
● The input toggle is 56, the input command is 00010, latch 56 to Z
● The input toggle is 48, the input command is 01010, 56 and 48 are subtracted and latched 8 to Z
● At this time, (216/8) needs to be calculated, but the register is occupied, take out 8 and write it down
● Input the toggle as 216, press "Preset", latch 216
● Input the toggle as 8, press "Division", 216 and 8 will be divided and latch 27
● Input the command as 10000, 216 in R and 8 in Z Divide, latched into R

Memory:

A device with memory capability—memory. Very important device.
As machine functionality increases, instructions become more complex. Can instructions (binary numbers representing instructions) be stored in one place and executed step by step? Memory!
Insert image description here

Figure 9 Memory diagram

Memory consists of a large number of memory units. In mainstream computers, one computing unit is 8 bits.
How to distinguish memory units? Answer: Each memory unit has a number, the first memory unit is numbered 0, the second memory unit is numbered 1, the third memory unit is numbered 2, and so on. The number of the memory unit is also called the address. How do you know which memory unit to access? Answer: Memory uses a row of wires, called address wires, to specify the number of the memory unit. When you want to access a certain unit, enter the number on the address line and select a certain unit.
The number of address lines determines how many cells can be accessed, as follows (two address lines can only access four cells):

Insert image description here

Figure 10 Memory diagram of two address lines

What about the 8 address lines?
Insert image description here

Figure 11 Memory diagram of 8 address lines

There are a total of 256 combinations of 8-bit binary numbers, so 256 (memory) units can be accessed. This binary combination is the memory address, represented in hexadecimal on the left. If there are N address lines, how many memory units can be accessed? Answer: "2N".

Memory is used to save or read data. For this purpose, there are additional wires: data lines. The reading and writing of data through the data line is bidirectional. A read/write control line is also needed to indicate whether to read or write to the memory unit.
Write: First, there is an address on the address line pointing to the memory unit. Then, a number to be read and written is given on the data line. Finally, the read/write control line issues a write command. At this time, the memory will write the data into the memory unit.
Read: First, an address is given on the address line to indicate where to read from, then the read/write control line issues a write command, and finally, the data is read through the data line.
Example (write 8bit data to 110):

Insert image description here

Figure 12 Write data (10001101) to the memory (110) with 16 address lines

Automatic calculation:
Build a computing machine that can automatically fetch instructions and execute them. The arithmetic
unit can automatically "fetch addresses and execute" from memory.

Insert image description here

Figure 13 Operator and memory

Instruction pointer register: holds the address of the instruction.
When the arithmetic unit starts working, the arithmetic unit transfers the address of the instruction pointer register to the address line, which is the address of the first instruction to be executed. Then the memory places the content of the address on the data line and enters the arithmetic unit through the data line. The arithmetic unit carries out frame shifting according to the instruction and executes the instruction. At the same time, the instruction pointer register is automatically modified (according to the address and length of the currently executed instruction) is the value of the next address, because instructions are stored in order. Then repeat the process again.

Specific examples:
Insert image description here

Figure 14 The first instruction is executed

The first instruction occupies a two-byte memory unit. The instruction contains an operation code and an operand. The number being operated is directly included in the instruction. Such a number is called an immediate value.
Insert image description here

Figure 15 The whole process of instruction execution

The last instruction is to stop. After execution, the arithmetic unit stops working. At this time, you can see the result from 0C.

Processor:
the history and development of processors.
The arithmetic unit (with limited functions) developed into a processor.
Insert image description here

Figure 16 Processor diagram

Processor composition:

  • Bus interface components
    • Send address signal
    • Send/receive data signals
  • control parts
    • Complex control and coordination of the running status of the entire process (when to fetch instructions, output addresses, send data, receive data)
  • instruction execution unit
    • Responsible for executing instructions

In 1974, he invented a chip that automatically fetches and executes instructions, the 4004 processor.
Insert image description here
Then came the 8008 (8-bit processor) and the epoch-making 8086 (16-bit processor). The x86 series has always maintained compatibility with the 8086.
Insert image description here

There are several processors with several registers and several arithmetic logic units.

Insert image description here

Figure 17 Number of processor bits

Subsequently, Intel produced 80286 and 80386. 80386 was an epoch-making product. The first part of the course is based on 8086 explanations, and the second part is based on 80386 explanations.
Later, more products were launched and more types were subdivided according to different fields. i3-3220. Pins are used to connect data lines, address lines, and control lines.

Insert image description here

Figure 18 i3-3220

The processor's job is to automatically fetch instructions and execute them. Which instructions can be executed are determined during design and manufacturing.

  • Instruction set: The set of all instructions that can be recognized and executed

    • More than a dozen kinds, dozens of kinds
    • hundreds to thousands
  • Arithmetic operation instructions and logical operation instructions

  • data transfer instructions

    • between registers
    • between processor and memory
    • between processor and peripherals
    • Insert image description here
  • Processor status control instructions
    ○ Used to control the internal working mode and running status of the processor, such as power management and program running status

The birth of assembly language:
Assembly language uses text symbols instead of machine instructions
Insert image description here
mov r, 207 Move 207 to register r
add r, 9 The value of register r is added to 9 and placed in r
mov z, 56 56 is moved to register z
sub z, 48 The value of register z is subtracted from 48, and the result is placed in z
div r, z The value of register r is divided by the value of register z, and the result is placed in r
mov [12], r The value of register r is placed
Stop and pause in the memory unit hlt with memory address 12

The processor can only understand machine instructions
Insert image description here

Figure 19 Execution process

Guess you like

Origin blog.csdn.net/weixin_44417441/article/details/134981132