This paper mainly explains the logical structure of 8086CPU, the method of forming physical address, the related registers and some instructions from the angle of how the CPU executes the instruction.
This article address: http://www.cnblogs.com/archimedes/p/assembly-register-memory.html, reprint please indicate source address.
Storage of in-memory words
In the CPU, 16 bits are used to store a word, high 8 bits hold high byte, low 8 bits hold lower byte. in memory, because the memory unit is a byte unit, just one word to use 2 address contiguous memory unit to store, the low byte of the word has a lower address cell.
Word Unit-A memory unit that holds a font data (16 bits), consists of two contiguous memory units, high-byte in the high Address memory unit, and a low-bit byte in the storage unit of the lower address memory unit that holds the font data.
0 The byte data stored in the Address cell is the font data stored in the 20h,0 address cell for the 4e20h,2 address cell, the byte-type data stored in the 12h,2 address unit is 0012H,
DS and [address]
There is a DS register in 8086CPU that is typically used to store the segment address to access the data. For example, if we want to read the contents of the 10000H unit, we can do it with the following program sections:
mov bx,1000h mov DS,BX mov al,[0]
[......] Represents a memory unit, 0 represents the offset address of a memory cell
Transmission of Word
8086CPU is a 16-bit structure that can transmit 16 bits of data at once, i.e. one word at a time. For example:
mov bx,1000h mov DS,BX mov ax,[0] ; 1000:0 font data fed into AX mov [0],cx ; 16-bit data in CX sent to 1000:0
Question 1
In-memory scenarios such as,
Write the values in the Register AX,BX,CX after executing the following instruction
mov ax,1000h mov Ds,ax mov ax,[0]mov bx,[2]mov cx,[1] Add bx,[1]add cx,[2]
mov ax,1000h after execution, ax=1000h
mov ds,ax after execution, ds=1000h
mov ax,[0] After execution, ax=1123h
mov bx,[2] After execution, bx=6622h
mov cx,[1] After execution, cx=2211h
Add bx,[1] after execution, bx=bx+[1]=6622h+2211h=8833h
Add cx,[2] After execution, cx=6622h+2211h=8833h
Question 2
In-memory scenarios such as,
Write the values in the Register AX,BX,CX after executing the following instruction
mov ax,1000h mov Ds,ax mov ax,11316mov [0],axmov bx,[0] Sub bx,[2]mov [2],BX
mov ax,1000h after execution, ax=1000h
mov ds,ax after execution, ds=1000h
mov ax,11316 after execution, ax=2c34h
mov [0],ax after execution, 1000:1 storage 2c,1000:0 Storage
mov bx,[0] After execution, bx=2c34
Sub bx,[2] After execution, BX=2C34-1122=1B12
mov [2],bx after execution, 1000:2 storage 1b12
The command execution results are as follows:
MOV, add, sub instructions
MOV instructions are available in the following ways:
MOV registers, data
MOV registers, registers
MOV register, Memory unit
MOV memory Unit, register
MOV memory unit, Segment register
MOV segment register, register
MOV register, Segment register
The following debug to verify the "MOV register, Segment register" command:
Verify "MOV memory unit, Segment register" instruction:
mov ax,1000h mov Ds,ax mov [0],cs
The Add and sub directives, like MOV, have two operands, and can have several forms:
Add register, data
Add Register, register
Add register, Memory unit
Add Memory Unit, register
Sub Register, data
Sub Register, register
Sub Register, Memory unit
Sub Memory Unit, register
Data segment
Related conclusions:
1, the word in memory storage, to use two contiguous memory units to store, the low byte of the word placed in the low address unit, high-byte placed in the High address unit
2, with the MOV instruction to access the memory unit, you can only give the unit offset address in the MOV instruction, at this time, the segment address by default in the DS register
3. [Address] means a memory unit with an address that is offset
4. When transferring font data between memory and register, high address unit and high 8 bit register, low address unit and low 8 bit register correspond
5, MOV, Sub, add is an instruction with two operands, jmp is an instruction with an Action object
CPU-provided stack mechanism
In 8086CPU programming, a piece of memory can be used as a stack to use, 8086CPU provides 2 kinds of stack operation: Push and pop, are all in Word units to operate
In 8086CPU, there are 2 registers in the stack top address: Segment register SS and register SP, at any moment, Ss:sp point to the top of the stack element. The top of the stack grows from a high address to a low address
First look at a piece of code:
mov Ax, 0123H Push Ax mov BX, 2266H Push BX mov CX, 1122H Push CX Pop Ax Pop BX Pop CX
The execution process is as follows:
Note: Font data is stored in two units, high address cell storage high 8 bits, low address cell storage low 8 bits
In 8086CPU, there are 2 registers, the segment register SS and the register SP, the segment address of the top of the stack is stored in the SS, and the offset address is stored in the SP. At any moment, ss:sp points to the top element of the stack
8086CPU does not guarantee that our operations on the stack will not be super-bounded, we have to worry about the top of the stack when programming problems
Push, pop instructions
Push and pop instructions can transfer data between registers and memory, and the push and pop instructions can be in the following form:
Push ; to stack the data in a register Pop ; out of the stack, with a register to receive the data from the stack Push ; data in a segment register into the stack Pop ; out of the stack, using a segment register to receive the data from the stack ; Push and pop instructions can also transfer data between memory units and memory units, and can: Push ; Place the word in the stack at a memory cell (the operation of the stack is in words) Pop ; out of the stack, using a memory word unit to receive the data from the stack
For example, the following code:
mov Ax, 1000H mov ; The segment address of the memory unit is to be placed in the DS Push [0; Place 1000:0 words into the stack Pop [2] ; out of the stack, the data from the stack is fed into 1000:2 places
Resources
"Assembly Language"--Wang Shuang
Assembly language--register (Memory Access)