From machine language to assembly

From machine language to assembly

The underlying hardware of our computer can only recognize binary data, and the previous article mentioned that people have designed a series of instruction sets to tell the CPU what to do and what functions to perform. However, if we directly write and check the instruction set, there will be a big problem. For example, because the instruction set is composed of a bunch of 010101010 binary, if there is a problem with the program, or when we want to troubleshoot bugs, should we go to Check these binaries line by line, obviously the efficiency is very low! Therefore, can we translate these machine languages ​​and use mnemonics to make us better understand machine languages? This leads to assembly language.

Assembly language

Assembly language (Assembly Language) is any low-level language used in electronic computers, microprocessors, microcontrollers or other programmable devices, also known as symbolic language. In assembly language, mnemonics are used instead of opcodes for machine instructions, and address symbols or labels are used instead of addresses of instructions or operands. In different devices, the assembly language corresponds to different machine language instruction sets, which are converted into machine instructions through the assembly process.

features

1. Assembly language is related to hardware, because the upper-level instruction sets corresponding to different hardware may be different, so each processor has a corresponding assembly language;

2. Assembly language is related to machine code, and instructions usually correspond to machine code one by one;

effect

1. Able to deeply understand the working principle of hardware;

2. Make full use of computer characteristics (such as SIMD, that is, single instruction multiple data);

3. Develop the operating system kernel, drivers, etc.;

4. Optimize the program. Assembly language is the translation of machine language. If you understand assembly language, it will be of great help to optimize our program.

register

The registers used in assembly language are not actually physical registers, but are mapped to specific physical registers inside the CPU through certain operations. You can also understand it this way, assembly language is to operate registers! In the early 8086 processor, there were 14 registers. In the next article, I will analyze these registers from the perspective of push.

general purpose register

Data register
AX
Accumulator: Accumulation register, also known as accumulator, is often used to store operands or results in arithmetic and logic operations. In addition, all input and output instructions of external devices can only use AL or AX as data registers.

BX
BX (Base): Base address register, which can be used for data registers. When accessing memory, it can store the address of the accessed memory. It is a register with dual functions

CX
CX (Count): counter register; used as a counter in loop and string operation instructions. For example, it is used as a counter in a loop cycle.

DX
DX (Data): data register; used as a data accumulator in multiplication and division, and stores the address of the port in input and output operations. In addition, when doing double-word long multiplication and division operations, DX and AX are combined to store a double-word long number (32 bits), where DX stores the upper 16 bits (remainder), and AX stores the lower 16 bits (quotient).

Pointer register
SP
Stack Pointer: The stack pointer register, which stores the offset position of the top of the stack, is used for stack operations, and is often used with SS

BP
Base Pointer: base pointer register; base address for storing data in the stack

Index register
SI
Source Index: source index register; mainly used to store addresses, and store the offset address of the source operand in string operations. The address stored in the index register has the function of automatic modification after the data transmission is completed.

DI
Destination Index: Destination index register; mainly used to store addresses, and store the offset address of the destination operand in string operations.

2. Control register
IP
IP (Instruction Pointer): instruction pointer register, often used in conjunction with CS for common addressing.

FLAG
flag register

3. Segment register
CS (Code Segment): code segment register
DS (Data Segment): data segment register
SS (Stack Segment): stack segment register
ES (Extra Segment): additional segment register
CS: code segment register

Summarize

This chapter explains the importance of assembly language from the perspective of derivation, and introduces some registers of the early 8086.

Guess you like

Origin blog.csdn.net/weixin_44821965/article/details/126351117