当前位置:网站首页>Assembly learning Chapter III of assembly language (Third Edition) written by Wang Shuang
Assembly learning Chapter III of assembly language (Third Edition) written by Wang Shuang
2022-04-23 02:57:00 【starmultiple】
List of articles
The third chapter register
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 Bit stores the position byte . When stored in memory , Since the memory unit is a byte unit ( A unit holds a byte ), Then a word needs two memory units with continuous addresses to store , The low order byte of this word is stored in the low address unit , The high-order byte is stored in the high-order address unit .
( from 0 The address begins to store 20000)20000 The hexadecimal number of is 4E20H

For this word unit ,0 Unit number is the low address unit 1 Bit high address

Let's understand 2,3 Unit No .0012H(18), Read the high byte first 00H read 12H
( in the future , Set the starting address to N Word unit of , For example, a word unit consists of 2、3 If it is composed of two memory units, the starting address of this word unit is 2, We can say this is 2 Address word unit )
When stored in a memory unit ,
- A unit holds a byte , A word needs two memory units with consecutive addresses to store
- Two consecutive memory cells store a font data (16 position )
- 0 Byte data stored in an address unit :20H
- 0 Font data stored in address word unit :4E20H
- 2 Byte data stored in an address unit :12H
- 2 Font data stored in address word unit :0012H
3.2 DS and [address]
CPU To read and write to a memory unit , The address of this memory unit must be given first , stay 8086PC in , Memory address consists of segment address and offset address .
Read 10000H unit (1000:0) The content of
mov bx,1000H // take 10000H(1000:0) The data in read bx in .
mov ds,bx //ds To be an assignment bx
mov al,[0] //[...] Represents a memory unit , among 0 Represents the offset address of the memory unit
3.3 The transmission of words
We use mov Instruction transfers byte data between register and memory , because 8086CPU yes 16 Bit structure , Yes 16 Data line . stay mov The instructions give 16 Bit register can be used for 16 Bit data transfer .
Let's implement the following figure ( use debug)

3.4mov、add、sub Instructions
We used mov、add、sub Instructions , They all have two operands .
Up to now , We know ,mov Instructions can take the following forms
| mov | register , data | such as :mov ax,8 |
|---|---|---|
| mov | register , register | such as :mov ax,bx |
| mov | register , Memory unit | such as :mov ax,[0] |
| mov | Memory unit register | such as :mov [0],ax |
| mov | Segment register , register | such as :mov ds,sx |
Here are two examples
(1) So let's try that “mov Segment register , register ” Usage of . Here's the picture , Get into debug use A command
Use the A The command is at the preset address 0740:0100 It's about , use mov ax,ds After the command is written, use T Command execution .
(2)“mov Memory unit , register ” The demonstration is as follows

take ax assignment 1000, In exchange for ds and ax after
mov [0],cs, Register cs Put the contents of into memory 10000H
When CS:IP Point to 0740:0105,Debug Show command mov [0000],cs Because this is an instruction to access memory , Of Debug In the lower right corner, you need to display the contents of the accessed memory unit . Due to... In the instruction CS It's a 16 Bit register , So to access a word unit , Its offset address is 0, Segment address in ds in , So it shows “DS:0000=0000” We can know that the content of this word unit is 0.
mov [0000],cs After execution CS Data in (0740H) Written 1000:0 It's about ,1000:0 Unit storage 40H,1000:1 Unit storage 7H, Last use D Command display
3.5 Data segment
about 8086PC machine , When programming, you can , Define a set of memory units · For a paragraph . We can make a group of length N(N<=64KB)、 Address continuous 、 The starting address is 16 A memory unit that is a multiple of is used as a memory space dedicated to storing data , This defines a data segment . For example, use 123BOH~123B9H This memory space is used to store data , You can think of this memory as a data segment , Segment address is 123BH, The length is 10 Bytes .
So how do we access the data in the data segment ? Treat a piece of memory as a data segment , use ds The segment address where the data segment is stored , When accessing specific units of data with relevant instructions as needed .
You can understand it by giving examples directly here 


send CS:IP Point to the address of the first instruction in the assembly

t Step by step debugging (… A little )
| mov ax,1 | ||
|---|---|---|
| mov ds,ax | AX=DS=0001H | ds:[0000] The physical address of is 0010H( Physical address =0001*16+0000=0010H |
| mov ax,[0000] | AX=2662H | ax=ds:[0000]=2262H |
| mov bx,[0001] | BX=E626H | bx=ds:[0001]=E626H |
| mov ax,bx | AX=E626H | ax=bx=E626H |
| mov ax,[0000] | AX=2662H | ax=ds:[0000]=2262H |
| mov bx,[0002] | BX=D6E6 | bx=ds:[0002]=D6E6H |
| add ax,bx | AX=FD48H | ax=ax+bx=2662H+D6E6H=FD48H |
| add ax,[0004] | AX=2C14H | ax=ax+ds:[0004]=FD48H+2ECC=2C14 |
| mov ax,0 | AX=0000H | ax=0000H |
| mov al,[0002] | AX=00E6H | al=ds:[0002]=E6H,ax=ah+al=00E6H |
| mov bx,0 | BX=0000H | bx=0000H |
| mov bl,[000C] | BX=0026H | bl=ds:[000C]=26H;bx=bh+bl=0026H |
| add al,bl | AX=000CH | al=al+bl=E6+26=10CH=0CH,ax=ah+al=000CH |
3.6 Stack
We can compare a stack to a box , Stacking is to put a new element at the bottom of the box ( To the top of the stack ), Take out the top element of the stack . This rule is also called LIFO( Last in, first out )
3.7 CPU Stack mechanism provided
8086CPU Provides stack in and out instructions , The basic two are PUSH( Push ) and POP( Out of the stack ).
push ax Indicates that register ax Data in the stack
pop ax It means to take data from the top of the stack and send it to ax
8086CPU In and out of the stack are carried out in word units

It's going on push and pop Command, we need to know the position of the top of the stack , So all we know now is CS、IP Is the segment address and offset address . So in 8086CPU There are two registers in the ,SS and SP, The segment address at the top of the stack is stored in SS in , The offset address is stored in SP in ,SS:SP Point to the top element of the stack .

- The stack is empty

- pop Command function
for example pop ax
pop ax The implementation process and push ax Just the opposite
(1) take SS:SP The data at the memory unit pointed to is sent to ax in
(2)SP=SP+2,SS:SP The cell pointing below the current stack top is the new stack top

After leaving the stack SS:SP Point to the new top of the stack 1000EH,pop Top of stack elements before operation ,1000CH Situated 2266H Ren existential , But it's no longer on the stack , If executed again push After the stack instruction ,SS:SP transplant 1000CH, And write new data in it .
3.8 The problem of stack top out of bounds
perform push The back stack top exceeds the stack space
perform pop follow-up

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 and pop Data can also be transferred between memory units and memory units
push Memory unit ; Put the word at a memory unit on the stack
pop Memory unit ; Out of the stack , Use a memory word unit to receive the stack data
such as
mov ax,1000H
mov ds,ax ; The segment address of the memory unit should be placed in ds in
push [0] ; take 1000:0 The word at is pushed into the stack
pop [2]; Out of the stack , The data out of the stack is sent into 1000:2 It's about

For example
(1) take 10000H~1000FH This space is used as a stack , The initial state stack is empty ;
(2) Set up AX=001AH,BX=001BH
(3) Utilization stack , In exchange for AX and BX Data in

3.10 Stack segment
We can take the length of N(N<=64KB) A set of addresses in succession , The starting address is 16 Multiple of memory units , Use it as stack space . such as , We will 10010H~1001FH This length is 16 Bytes of memory space is used as a stack , Access as a stack . This space can be called a stack segment , Segment address is 1001H, The size is 16 byte .
We treat memory as a stack segment , It's just an arrangement when we're programming ,CPU The stack segment we define will not be automatically accessed as stack space .
If you will 10000H~1FFFFH This space is treated as a stack segment , The initial state stack is empty , here ,SS=1000H,SP=0
( We put 10000H~1FFFFH This space is treated as a stack segment ,SS=1000H, Stack space is 64KB, The address of the word unit at the bottom of the stack is 1000:FFFF.SS:PP Point to the top of the stack , There is only one element in the stack ,SS=1000H,SP=FFFEH. The stack is empty. , It's like going out of the stack , After leaving the stack SP=SP+2, be FFFE+2=0
therefore sp Final =0)
版权声明
本文为[starmultiple]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220644544674.html
边栏推荐
- Kubernetes study notes
- Error installing Mongo service 'mongodb server' on win10 failed to start
- Source code and some understanding of employee management system based on polymorphism
- tf. keras. layers. Conv? D function
- ele之Table表格的封装
- Codeforces Round #784 (Div. 4) (A - H)题解
- ROP Emporium x86_64 7~8题
- The interface request takes too long. Jstack observes the lock holding
- Innovation and management based on Scrum
- Mosaic Routing: implement / home / news
猜你喜欢

LeetCode 1450 - 1453

JS learning notes

基于多态的职工管理系统源码与一些理解

Sonic cloud real machine tutorial

tf. keras. layers. Timedistributed function

Actual combat of industrial defect detection project (IV) -- ceramic defect detection based on hrnet

First knowledge of C language ~ branch statements

Source code and some understanding of employee management system based on polymorphism

Modification du contenu de la recherche dans la boîte déroulante par PHP + MySQL

php+mysql對下拉框搜索的內容修改
随机推荐
REINFORCE
php+mysql對下拉框搜索的內容修改
《信息系统项目管理师总结》第四章 项目成本管理
Android 高阶面试必问:全局业务和项目的架构设计与重构
grain rain
Machine learning (Zhou Zhihua) Chapter 14 probability graph model
L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)
Traversée de l'arbre L2 - 006
The usage of case when and select case when is very easy to use
Sonic cloud real machine tutorial
tf. keras. layers. Embedding function
Linux Redis——Redis 数据库缓存服务
进阶上将程序员必备素质
tf. keras. layers. Inputlayer function
Guangcheng cloud service can fill in a daily report regularly every day
Traversal of l2-006 tree (middle and later order determination binary tree & sequence traversal)
Kubernetes - Introduction to actual combat
tf. keras. layers. MaxPooling? D function
Redis data server / database / cache (2022)
OCR recognition PDF file