当前位置:网站首页>Chapter 3 registers (memory access)

Chapter 3 registers (memory access)

2022-06-12 08:54:00 Pickup Ping

3.1 Storage of words in memory

stay 0 Start storing... At the address 20000(4E20H):
 Insert picture description here

  • Be careful :0 Unit number is the low address unit ,1 Unit number is a high address unit .

3.2 DS and [address]

  • 8086CPU There is one of them. DS register , The segment address usually used to store the data to be accessed .
  • Read 10000H The content of the unit
mov bx,1000H
mov ds,bx
mov al,[0]

mov al,[0]
Known mov Three transfer functions that can be completed by instructions :

  1. Put the data directly into the register ;
  2. Send the contents of one register into another .
  3. besides ,mov Instructions can also put the contents of a memory unit into a register .

mov Command format :
mov Register name , Memory unit address
“[…]” Represents a memory unit ,“[…]” Medium 0 Represents the offset address of the memory unit .

  • When the command is executed ,8086CPU Pick up automatically DS The data in is the segment address of the memory unit .

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

  • How to send data from register to memory unit ?
  • take al The data in is sent to the memory unit 10000H?
  • Conclusion :
MOV BX,1000H
MOV DS,BX
MOV [0],AL

3.3 The transmission of words

  • 8086CPU One word at a time
MOV BX,1000H
MOV DS,BX
MOV AX,[0]
MOV [0],CX   ;cx Medium 16 Bit data is sent to 10000 It's about 

3.4 mov、add、sub Instructions

 Insert picture description here

3.5 Data segment

  • We can make a group of length N(N≤64K)、 Address continuous 、 The starting address is 16 A memory unit that is multiples of a memory unit is used as a memory space dedicated to storing data , This defines a data segment .
  • For example, we use 123B0H~123B9H This space is used to store data :
  • Segment address :123BH
  • length :10 byte

3.1~3.5 Section

  1. When a word is stored in memory , To use two consecutive address memory units to store , The low order byte of a word is stored in a low address unit , The high byte is stored in the high address unit .
  2. use mov Instruction to access memory cells , Can be in mov Only the address given in the instruction unit is offset , here , The segment address defaults to DS In the register .
  3. [address] Represents an offset address of address The memory unit of .
  4. When transferring font data between memory and register , High address units and high 8 Bit register 、 Low address units and low 8 Bit registers correspond to .
  5. mov、add、sub Is an instruction with two operands .jmp Is an instruction that has an operation object .

3.6 Stack

  • Last in, first out
  • Basic operation : Push and pull

3.7 CPU Stack mechanism provided

Push :PUSH
Out of the stack :POP

  • 8086CPU The stack in and out of stack operations are based on words .
  • 8086CPU in , There are two registers :
  • Segment register SS Store the segment address at the top of the stack
  • register SP Store the offset address of the top of the stack
  • Anytime ,SS:SP Point to the top element of the stack .

3.8 The problem of stack top out of bounds

  • SS and SP Only the address at the top of the stack is recorded , Rely only on SS and SP It can ensure to find the top of the stack when entering and exiting the stack .
  • Use when the stack is full PUSH Instruction stack , Use when the stack is empty POP Instructions are out of the stack , There will be stack top supersession problems .
  • It's dangerous to overstep the top of the stack :because Since we arrange a space as a stack , Then the space outside the stack space is likely to store data for other purposes 、 Code etc. , These data 、 The code may be in our own program , It could be from another program .

Stack and memory

  • Stack space, of course, is also part of memory space , It is just a space that can be accessed in a special way

3.9 push、pop Instructions

  • push register : Stack data in a register

  • pop register : Out of the stack , Use a register to receive data from the stack

  • push Segment register : Stack data in a segment register

  • pop Segment register : Out of the stack , Use a segment register to receive data from the stack

  • push Memory unit : Put the word at a memory unit on the stack ( Stack operations are all in words )

  • pop Memory unit : Out of the stack , Use a memory word unit to receive the stack data
    Instruction execution ,CPU To specify the address of the memory unit , Can be in push、pop The instruction gives the offset address of the memory unit , The segment address is when the instruction is executed ,CPU from ds Get in .

3.10 Stack segment

  • We can take the length of N(N<=64K) A set of addresses in succession 、 The starting address is 16 Multiple of memory units , Use as a stack , This defines a stack segment .
  • Treat a piece of memory as a stack segment , It's just an arrangement when we're programming ,CPU Not because of this arrangement , Is executed push、pop When we wait for the stack operation instruction, we will automatically take the stack segment we defined as Make stack space to access .
原网站

版权声明
本文为[Pickup Ping]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120842166095.html