当前位置:网站首页>Assembly learning register
Assembly learning register
2022-06-30 07:22:00 【Yangxiaomeng】
List of articles
Two 、 register ( With 8086 As a prototype )
1. General registers
With 8086cpu For example , All of its registers are 16 Bit , It can be stored 2 Bytes .
AX BX CX DX It's called a general-purpose register , Used to store general data
AX Can be divided into AH and AL ( according to 16 The height of the bit )
BX Can be divided into BH and BL
CX Can be divided into CH and CL
DX Can be divided into DH and DL
With AX For example Look at the picture below

2. The storage of words in registers
8086cpu The following can be handled at one time 2 Data of three sizes :
1. byte (byte),1byte = 8bit, Can exist 8 Bit register
2. word , A word consists of two bytes , The two bytes are called the upper byte and the position byte of the word respectively , Stored separately in AH and AL in
3. Preliminary knowledge of assembly instructions
Assembly instructions or register names are not case sensitive
| Assembly instruction format | control cpu Completed operation | Use the syntax of high-level language to describe |
|---|---|---|
| mov ax( Register name ),18( data ) | take 18 Into the register AX | AX=18 |
| mov ax( Register name ),bx( Register name ) | take bx The data in is sent to ax in | ax=bx |
| add ax( Register name ),18( data ) | Register ax The value of plus 18 | ax = ax + 18 |
| add ax( Register name ),bx( Register name ) | take ax and bx Add the data in | ax = ax + bx |
4. 16 Bit structure cpu
8086cpu yes 16 Bit structure ,16 Bit structure means :
1. The arithmetic unit can handle at most 16 Bit data
2. The maximum width of the register is 16 position
3. The path between the register and the arithmetic unit is 16 position
5. 8086cpu The way to give a physical address
8086cpu There is... On the outside 20 Bit address bus , The addressing capability reaches 1mb(2^20B = 1MB)
8086cpu The internal is 16 Bit structure , Addressing capability is 64KB(2^16B)
8086cpu Use... Internally 2 individual 16 A bit address is synthesized by an address adder 20 For physical address
The workflow is as follows :

Principle of address adder : Physical address = Segment address *16( Move left 4 position )+ offset
1. A binary shift of data to the left n position , Equivalent to this data 2 Of n Power ,16 A into 20 position (2^16 * 2^4 = 2^20)
2.20 position +16 position = 20 position analogy Ten + hundred The high position is still 100
6. The concept of paragraph

cpu The physical address is formed in this way
Due to the physical address = Segment address *16 + offset
The starting address of the segment = Segment address *16 ( by 16 Multiple )
The offset address is 16 position (64KB), So the maximum length of a segment is 64KB( Left offset or right offset )
7. cs and ip
The segment register stores the segment address ,8086 There is CS DS SS ES 4 Segment registers , With cs For example
cs: Code segment register
ip: Instruction pointer register
8086cpu Will be with M(cs The content of )*16+N(ip The content of ) Is the starting physical address , Read instructions and execute

8086cpu General workflow :
1. Through the address adder cs:ip Turn into 20 Bit address .
2. ip = ip + The length of the read instruction ( action register , data 3 byte , action register register 2 byte )
3. Execution instruction repeat 1
8086cpu Initial value setting during startup or reset cs=FFFFH IP=0000H
8. modify cs and ip Instructions
Programmer pairs cpu Only by modifying the value of the register
mov Instructions : Send instructions mov ax ,123 take 123 The value is placed in ax in , Most registers can be modified by this instruction
jmp Instructions : Format => jmp Segment address : offset jmp Some legal register
Such as : 1. ax = 1000H
2. perform jmp 2000H:0003H here : cs=2000H ip=0003H ( Directly modifying cs ip Value )
3. Re execution jmp ax here ip The value of is 2000H ( Modify with the value of the register ip Value )

Execute the process : Memory value =cs*16 + ip ip = ip + Memory unit ( byte )
1. Initial value cs=2000H IP=0000H, cs*16 + ip = 20000H, perform B8 22 66(mov ax,6622H), ip=ip+3=0003H
2. cs*16 + ip = 20003H, perform EA 03 00 00 10(jmp 1000:3) ip=ip+5=0008H
3. 2 take cs,ip Reset cs=1000H ip=0003H cs*16 + ip = 10003H, perform B8 00 00(mov ax,0000),ip=ip+3=0006H
4. cs*16 + ip = 10006H perform 8B D8(mov bx,ax), ip=ip+2=0008H
5. cs*16 + ip = 10008H perform FF E3(jmp bx) , ip=ip+2=000AH
6. 5 take ip=bx value , 4 take ax Value is assigned to bx,3 take ax Set up 0000 therefore ip by 0000 cpu from 10000H Start reading
9. Code segment
A code segment is a contiguous segment of a defined memory , Used to store code , You can set the cs and ip value , Enable code snippets to execute , If the code segment is 123B0H~123B9H Set up cs=123BH IP=0000H, You can make cpu Execute the code snippet 
边栏推荐
猜你喜欢

Class templates and friends

JS widget wave JS implementation of wave progress bar animation style

I graduated this year, but I don't know what I want to do

Can introduction

Linux server installation redis

Merge: extension click the El table table data to expand

Introduction to ecostruxure (1) IEC61499 new scheme

FreeRTOS timer group

Use of ecostruxure (2) IEC61499 to establish function blocks

Pit stepping record: Supervisor log return information: redis extension is not installed
随机推荐
Linux服务器安装Redis
1、 Output debugging information: makefile file debugging information $(warning "tests" $(mkfile\u path)); makefile file path
線程池——C語言
网络安全-ARP协议和防御
FreeRTOS timer group
uniapp图片下方加标签标图片
RT thread kernel application development message queue experiment
Stm32g0 and FreeRTOS learning summary
How to determine the size of the platform byte order?
Install go language development tools
对占用多字节和位的报文信号解析详解
01 - embedded learning route and career planning: embedded basic knowledge and development process
The class imported by idea import clearly exists, but it is red?
02 - bare metal and RTOS development modes: five development modes of bare metal and the introduction of RTOS
QT signal slot alarm QObject:: connect:cannot connect (null)
The most convenient serial port screen chip scheme designed at the charging pile in China
03 - programming framework: Division of application layer, middle layer and driver layer in bare metal programming
Record the problem that the system file cannot be modified as an administrator during the development process
JS create PDF file
Minecraft 1.16.5 module development (50) guide book