当前位置:网站首页>Assembly language - Wang Shuang Chapter 3 notes and experiments

Assembly language - Wang Shuang Chapter 3 notes and experiments

2022-06-27 05:52:00 Holding hands to listen to falling flowers

The first 3 Chapter register ( Memory access )
3.1 Storage of words in memory
CPU in , use 16 Bit register to store a word . high 8 Bits hold the high byte , low 8 Bits hold the lower bytes .
When stored in memory , Since the memory unit is a byte unit ( A unit holds a byte ), Then a word should be stored in memory units with two consecutive addresses , The lower byte of this word is placed in the lower address unit , The high byte is stored in the high address unit .

3.2 DS and [address]
mov The transfer of instructions that can be completed :
(1) Put the data directly into the register ;
mov bx, 1000H
(2) Send the contents of one register to another ;
mov ds, bx
(3) Put the contents of a memory unit into a register .
Register is indicated by register name , The address of the memory unit is used to indicate
"[…]" Represents a memory unit ,“[…]” Medium 0 Represents the offset address of the memory unit .
for example mov [0], ax Instruction execution ,8086CPU Pick up automatically ds The data in is the segment address of the memory unit .
[address] Represents an offset address of address The memory unit of .
use mov Instructions access memory units , Can be in mov Only the address given in the instruction unit is offset , here , The segment address defaults to DS In the register .

8086CPU It is not allowed to send data directly into the segment register .

3.6 Stack
The stack has two basic operations : Push and pull . Putting a new element on the top of the stack , Out of the stack is to take an element from the top of the stack . The top of the stack element is always the last on the stack , When you need to be out of the stack , It's first removed from the stack . This rule of operation of the stack is called LIFO(Last In First Out, First in, then out ).

3.7 CPU Stack mechanism provided
8086CPU The stack in and out of stack operations are based on words .
Anytime ,SS:SP Point to the top element of the stack .push Instructions and pop Instruction execution ,CPU from SS and SP Get the address of the top of the stack .

push ax Implementation , Completed by the following two departments .
(1)SP=SP-2,SS:SP Point to the cell in front of the current top of the stack , Take the unit in front of the current stack top as the new stack top ;
(2) take ax Send the content of SS:SP Point to the memory unit ,SS:SP Now point to the top of the new stack .

8086CPU in , When entering the stack , The top of the stack grows from high address to low address .
The stack is empty ,SS:SP Points to the next unit of the highest address unit in stack space .

pop ax The implementation process and push ax Just the opposite , Completed by the following two departments .
(1) take SS:SP The data at the memory unit pointed to is sent to ax in ;
(2)SP=SP+2,SS:SP Point to the cell below the top of the current stack , Take the cell below the current top of the stack as the new top of the stack .
Be careful :push,pop Wait for stack operation instructions , It's just SP. That is to say, the maximum variation range of the stack top is 0-FFFFH. The maximum capacity of a stack segment is 64KB.

Summary of paragraph
We can define a segment of memory as a segment , Use a segment address to indicate a segment , Access the unit in the segment with offset address , It's entirely our own arrangement .
We can define a segment to store data , Define it as a data segment ;
We can define a segment to store code , Define it as a code snippet ;
We can define a segment as a stack , Define it as a stack segment ;

We can arrange this , But to make CPU Follow our schedule to visit these paragraphs , Will be :
For data segments , Put its segment address in DS in , use mov、add、sub Wait for instructions to access the memory unit ,CPU Access the content of the data segment we defined as data .
For code snippets , Put its segment address in CS in , Place the offset address of the first instruction in the segment in IP in , such CPU It will execute the instructions in our defined code segment .
For stack segments , Put its segment address in SS in , Put the offset address of the top unit of the stack in SP in , such CPU When stack operations are needed , Such as execution push、pop Instruction, etc , We use the stack segment we defined as stack space .

so , No matter how arranged ,CPU Treat a segment of memory as code , It's because of CS:IP It points there ;CPU Treat a segment of memory as a stack , Because SS:SP It points there . We have to be clear , What is our arrangement , And how to make CPU According to our arrangement . Be very clear CPU How it works , It's in control CPU According to our arrangement, we can run with ease .

原网站

版权声明
本文为[Holding hands to listen to falling flowers]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270545089123.html