Getting started with crazy summer vacation Study Notes (1)
Reference: Chapter 1 and Chapter 2 of Assembly Language
I. Basic Knowledge
1. Working Process of programming in assembly language
The essence of assembly is to make it easier for programmers to use assembly commands to represent binary code.
Assembly instruction ----------------> compiler ----------------> machine code ----------------> Computer execution
Mov ax, bx 100010001
...............................
2. assembly language composition
The Assembly is composed of the following three types of commands:
(1) Assembly commands: for example, mov and add have corresponding machine codes.
(2) pseudo-command: no corresponding machine code is executed by the compiler and not by the computer.
(3) Other symbols: such as +,-, *,/, are identified by the compiler, and there is no corresponding machine code.
3. commands and Data
There is no difference between commands and data in memory. For example, the same binary 1000100111011000
The cpu can regard it as the instruction mov ax, and the bx can also be seen as the data 89D8H
4. Bit, byte, word, word length, and storage unit
Byte: consists of eight digits.
Word: A group of binary data processed by a computer within the same time is called the word of a computer. The size is determined by the cpu. For example, 8086cpu is a 16-bit cpu, that is, two bytes.
Word Length: The word length.
Storage Unit: memory is divided into several storage units. The size is 8 bytes. For example, the minimum memory unit is a byte, and [0] is a byte.
5. CPU Bus
External Bus
Address Bus: determines the addressing capability of the CPU. 8086CPU has 20 IP Address Bus addressing capacities of 2 ^ 20, that is, 1 MB.
Data Bus: determines the amount of data transmitted between the CPU and other devices (such as memory and video card. The 8086CPU has 16 address buses (that is, the word length ).
Control Bus: determines the control capability of the CPU on other devices (such as memory and video card) in the system.
6. Address Space
A computer consists of many devices. Such as memory, Nic, and video card. They all have memory. They are all connected to the cpu bus. The CPU sends out memory read/write commands through the control line when reading or writing them. That is to say, when the CPU controls them, it treats them as memory and treats them as a logical memory composed of several storage units, this memory is the memory address space (that is, the CPU address space, not only the memory of the memory, but all the memory on the computer)
For example:
00000 ~ 9 FFFF primary address space (memory)
9FFFF ~ A0000 memory address space
C0000 ~ Fffff rom address space (such as motherboard BIOS and video card BIOS)
Ii. Registers
The bus mentioned above is an external bus for the cpu. The memory, Controller, and register of the cpu are connected by the internal bus.
Handler: Process Information
Storage: stores information.
Controller: controls various devices
For assembler, the main component of CPU is registers.
For example, the 8086CPU has 14 registers:
Ax, bx, cx, dx, si, di, sp, bp, ip, cs, ss, ds, es, psw
Ax, bx, cx, dx, used to store general data. The size is 16 bits, that is, 2 bytes.
Cs is the code segment address register
The ip address is the instruction pointer register, which stores the offset address.
Ds is a data segment register.
1. General registers
Ax, bx, cx, dx, used to store general data. The size is 16 bits, that is, 2 bytes.
8086CPU to be compatible with the previous generation of 8-bit CPU, ax, bx, cx, dx can be divided into two independent registers
AX can be divided into AH (AX's 8-bit high) and AL (AX's 8-bit low)
Similarly, BX can be divided into BH, BL, CX can be divided into CH, CL, DX can be divided into DH and AL
2. Several Assembly commands
Mov ax, 18 ax = 0018 H
Mov ah, 78 ah = 0078 H
Add ax, 8 ax = ax + 008 H
Mov ax, bx ax = bx
Add ax, bx ax = ax + bx
3. How does the 8086CPU provide the physical address?
There are 20 8086CPU address buses, and 8086 is a 16-bit CPU, which can only process transmission and temporary storage at one time.
8086CPU uses two 16-bit addresses to synthesize a 20-bit physical address:
Physical address = segment address * 16 + offset address
4. segment register
The 8086CPU has four segments: CS, DS, SS, and ES.
(1) cs and ip
Cs is the code segment address register
The ip address is the instruction pointer register, which stores the offset address.
You cannot use mov cs, 1000 H mov ip, 0 to modify the segment register.
Use the jmp Command, as shown in figure
Jmp 2AE3: 3 change cs to 2AE3H change ip address to 003 H
If you only want to change the ip address, use the following command:
Jmp 0 or jmp ax
You can learn about the Register through Wang Shuang's experiment in assembly language.