当前位置:网站首页>Wang Shuang's detailed learning notes of assembly language II: registers
Wang Shuang's detailed learning notes of assembly language II: registers
2022-07-06 14:41:00 【Deteriorate_ Kr】
List of articles
Preface
A typical CPU By solver 、 controller 、 Register and other devices , These devices are connected by an internal bus .
Internal bus implementation CPU The connection between the internal devices .
External bus implementation CPU Connection with other devices on the motherboard .
In short , stay CPU in :
1. The arithmetic unit processes information
2. Register for information storage
3. The controller controls various devices to work
4. The internal bus connects various devices , Transfer data between them
For an assembler ,CPU The main component in is the register . The register is CPU A component that a programmer can read and write with instructions . The programmer changes the contents of various registers to achieve the goal of CPU The control of . Of course it's different CPU, The number of registers 、 The structure is different .
8086CPU Yes 14 A register Their names are :
AX、BX、CX、DX、SI、DI、SP、BP、
IP、CS、SS、DS、ES、PSW.
One 、 General registers
8086CPU All registers are 16 Bit , It can hold two bytes .
AX、BX、CX、DX Commonly used to store general data is called a general-purpose register .
Let's say AX For example , Let's take a look at the logical structure of registers
8086 Previous generation CPU The registers in are 8 Bit ;
To ensure compatibility , These four registers can be divided into two independent 8 Bit register use .
AX Can be divided into AH and AL;
BX Can be divided into BH and BL;
CX Can be divided into CH and CL;
DX Can be divided into DH and DL.
H It's high ,High
L It's low ,Low
High position ← Low position
AX It's low 8 position (0 position ~ 7 position ) Constitute the AL register , high 8 position (8 position ~15 position ) Constitute the AH register .
AH and AL Registers can be used independently 8 Bit register .
Two 、 The storage of words in registers
byte :byte, One byte by 8 individual bit form , Can exist 8 Bit register
word : Write it down as word, A word consists of two bytes , These two bytes are called the high byte and the low byte of the word respectively
stay 8086 Of AX In the register , stay AH Its height is stored in 8 position , stay AL Its low... Is stored in 8 position .AH and AL Data in , It can be regarded as the height of a font data 8 Bit and low 8 position , It can also be regarded as two independent byte data .
Because a memory unit can store 8 Bit data ,CPU The register in the can store n individual 8 Bit data . in other words , Most of the data in the computer is generated by 1~N individual 8 Bit data .
Using hexadecimal to represent data can intuitively see what the data is made of 8 Bit data
3、 ... and . Several assembly instructions
mov ax,18=MOV AX,18
bx=BX…
Originally ax should =1044c, But don't forget AX yes 16 Bit register ,1044c Yes 20 position , So we should discard the high position here 1, leave 044c. therefore AX=044CH.
AL=C5H+93H=158H, but AX yes 16 Bit register .AL Only eight bits of data can be stored , therefore AL We should discard the high position 1, leave 58, therefore AL=18H.AX=0058H
Be careful :1. here al As an independent 8 Bit register , and ah It doesn't matter. ,CPU When executing this instruction, it is considered ah and al Are two unrelated registers .
2. The lost here , It means that the carry system cannot be in 8 Save... In bit register , however CPU It's not really discarded This carry value , This problem will be discussed later in the course .
3. In data transmission or computation , Note that the number of bits of the two operation objects of the instruction should be the same, for example :
mov ax,bx
mov bx,cx
mov ax,18h
mov al,18h
add ax,bx
add ax,20000 And so on are the correct instructions , and :
mov ax,bl ( stay 8 Bit registers and 16 Transfer data between bit registers )
mov bh,ax ( stay 16 Bit registers and 8 Transfer data between bit registers )
mov al,20000 (8 The bit register can store up to 255 The data of )
add al,100H ( Put a higher than 8 Bit data is added to a 8 Bit register )
And so on are all wrong instructions , The reason for the error is that the digits of the two operation objects of the instruction are inconsistent
Four . Address
CPU When accessing the memory unit, give the address of the memory unit . The storage space composed of all memory cells is a one-dimensional linear space . Each memory unit has a unique address in this space , This unique address is called physical address .
CPU Through the address bus into the memory , Must be the physical address of a memory unit . stay CPU Before sending a physical address to the address bus , You have to form this physical address internally . Different CPU There can be different ways to form physical addresses . Let's now discuss 80865CPU How to form the physical address of the memory unit inside .
1. 16 Bit structure CPU
8086CPU yes 16 It's a plane , And its previous generation (8080、8085) Is such as 8 It's a plane .
General speaking ,16 Bit structure describes a CPU It has the following characteristics :
1、 The arithmetic unit can handle at most 16 A data .
2、 The maximum width of the register is 16 position .
3、 The path between the register and the arithmetic unit is 16 Bit .
in other words , stay 8086 Inside , Be able to handle 、 transmission 、 The maximum length of information stored temporarily is 16 position . The address of the memory unit is sent to the address bus , Must be in CPU In dealing with 、 transmission 、 To store temporarily , about 16 position CPU, It can be handled at one time 、 transmission 、 To store temporarily 16 Address of bit .
2. 8086CPU The way to give a physical address
8086 Yes 20 Bit address bus , It's transportable 20 Bit address , Addressing capability is 1M.
8086 For internal 16 Bit structure , It can only transmit 16 Address of bit , The addressing capability shown is only 64K.
8086CPU Take one and use two inside 16 Bit address synthesis method to form a 20 Physical address of bit .
When 8086CPU To read and write memory ,
1.CPU The related components in provide two 16 Address of bit , One is called a segment address , The other is called the offset address
2. The segment address and offset address are sent through the internal bus to a component called an address adder
3. The address adder will have two 16 The bit address is synthesized into a 20 Physical address of bit
4. The address adder will connect 20 Bit physical address into the I / O control circuit
5. The I / O control circuit will 20 Bit physical address sent to address bus
6.20 Bit physical address is transferred to memory by address bus
Method of synthesizing physical address by address adder :
Physical address = Segment address ×16+ offset
“ Segment address x16” A more common term is shift left 4 position . All information in the computer is stored in binary form , Of course, segment addresses are no exception . The machine can only process binary information ,“ Move left 4 position ” In the middle , It refers to binary bits .
Observe the relationship between the number of shifts and various forms of data :
(1) The binary form of a data is shifted left 1 position , It is equivalent to multiplying the data by 2;
(2) The binary form of a data is shifted left N position , It is equivalent to multiplying the data by 2 Of N Power ;
(3) How the address adder completes the segment address ×16 Arithmetic ?
The segment address stored in binary form is shifted to the left 4 position .
law :** The hexadecimal form of a data is shifted left 1 position , It is equivalent to multiplying the decimal form of this data by 16, It is also equivalent to multiplying the hexadecimal form of this data by 10H(10H=10);** The decimal form of a data is shifted left 1 position , It is equivalent to multiplying the corresponding decimal form of this data by 10; One X Hexadecimal data is shifted to the left 1 position , It is equivalent to multiplying the decimal form of this data by X. One X Hexadecimal data is shifted to the left N position , It is equivalent to multiplying the decimal form of this data by X Of N Power . Binary shift left 4 Bit is equal to 16 Shift left by one digit
3.“ Segment address ×16+ offset = Physical address ” The essential meaning of
Its essential meaning is :CPU When accessing memory , Use a base address ( Segment address x16) And an offset address relative to the base address , Gives the physical address of the memory unit .
More generally ,8086CPU This addressing function of is “ Base address + offset = Physical address ” A concrete implementation of addressing mode .8086CPU in , Segment address x16 It can be regarded as the mailing address
Write... On the first sheet of paper 200( Segment address ), Write... On the second sheet of paper 826( offset ). then 200( Segment address )x10+826( offset )=2526( Physical address )
4. The concept of paragraph , Real memory is not segmented , The division of segments comes from CPU
in the future , When programming, you can , Consider several memory units with consecutive addresses as a segment , Use segment address ×16 The starting address of the positioning segment ( Base address ), Locate the memory unit in the segment with the offset address .
5. Memory unit address summary
such as CPU To visit 21F60H unit , Then it gives the segment address SA And offset address EA Satisfy SAX16+EA=21F60H that will do .
exercises :
There's a data store in memory 20000H In the unit , The address of the given segment is SA, If you want to find this unit with offset address . be SA The conditions to be met are : The minimum is ____, The maximum is ____.
First, offset the address EA For the range of 0H~FFFFH
So the biggest SA=(20000H-0H)/10H=2000H
The smallest SA=(20000H-FFFFH)/16(o)=1001H
20000H=131072
FFFFH=65535
(131072-65535)/16=4,096.0625, Have remainder , Rounding up , Fetch 4097
4097=1001H, therefore SA The minimum value of is 1001H
5、 ... and . Segment register
The segment register provides the segment address .
8086CPU Yes 4 Segment registers :
CS( Code segment register )、DS( Segment register )、SS( Stack segment register )、ES( Additional segment register )
When 8086CPU To access memory , From here 4 Segment registers provide the segment address of the memory unit .
1.CS and IP
CS and IP yes 8086CPU The most critical register in , They indicate CPU The address of the current instruction to be read .
CS For code segment register ;
IP Is the instruction pointer register .
8086 In flight , Anytime ,CPU take CS:IP The content pointed to is executed as an instruction , And after finding the address IP It will automatically increment
There is no difference between instructions and data in memory , It's all binary information ,CPU At work, take some information as instructions , Some information is treated as data .
CPU According to what, the information in memory is regarded as instructions ?
CPU take CS:IP The contents of the memory unit pointed to are treated as instructions .
At any time ,CPU take CS、IP The contents of are treated as the segment address and offset address of the instruction , Use them to synthesize the physical address of the instruction , Read instruction code into memory , perform .
if , A piece of information in memory has been CPU If it has been carried out , that , The memory unit it is in must be CS:IP Pointed to .
2. modify CS、IP Instructions
stay CPU in , The only part that programmers can read and write with instructions is registers , The programmer can change the contents of the register to implement the CPU The control of .
CPU Where to execute an instruction is made by CS、IP It's decided by the content in , Programmers can change CS、IP To control the content of CPU Execute the target command .
How do we change CS、IP The value of ?
8086CPU Corresponding instructions must be provided
First think about how we modified AX The value in ? use mov Instructions , Actually 8086CPU Most register values , Both can be used. mov Command to change ,mov Instructions are transmission instructions .
but mov Command cannot be used to set CS、IP Value , because 8086CPU There's no such feature
.
8086CPU by CS、IP Additional instructions are provided to change their values :jmp Transfer order
1. If you want to modify CS、IP The content of :
jmp Segment address : offset
jmp 2AE3:3, After execution :CS=2AE3H,IP=0003H,CPU Will be taken from 2AE33H Read command at
jmp 3:0B16, After execution :CS=0003H,IP=0B16H,CPU Will be taken from 00B46H Read command at
function : Modify with the segment address given in the instruction CS, Offset address modification IP.
2. Modify only IP The content of :
jmp Some legal register
jmp ax ( Be similar to mov IP,ax)
jmp bx
jmp The function of a legal register instruction is : Modify with the value in the register IP.
such as :jmp ax, Before the command is executed :ax=1000H,CS=2000H,IP=0003H
After the command is executed :ax=1000H,CS=2000H,IP=1000H
jmp bx, Before the command is executed :bx=0B16H,CS=2000H,IP=0003H
After the command is executed :bx=0B16H,CS=2000H,IP=0B16H
3. Problem analysis
In the initial state CS=2000H,IP=0000H, Physical address =CSx16+IP=20000H.
1. First, execute mov ax,6622H
2.IP Self increasing , perform jmp 1000:3
3. here CS=1000H,IP=0003H, go to 1000x16+0003=10003H To execute
mov ax,0000
4.IP Self increasing ,mov bx,ax . here bx=ax=0000H,
5.jmp bx , here IP=0000H,CS=1000H
6. go to 10000H To execute mov ax,0123H
7. Go to step three
So in conclusion , The result is :
(1)mov ax,6622
(2)jmp 1000:3
(3)mov ax,0000
(4)mov bx,ax
(5)jmp bx
(6)mov ax,0123H
(7) Turn to the first (3) Step by step
4. Code segment
about 8086PC machine , In programming , As needed , Define a set of memory units as a segment .
The length can be N( N≤64KB ) A set of code for , There is a set of consecutive addresses 、 The starting address is 16 Multiple of the memory unit , This memory is used to store code , This defines a code segment
mov ax,0000 (B8 00 00)
add ax,0123H (05 23 01)
mov bx,ax (8B D8)
jmp bx (FF E3)
The length of this segment is 10 Byte instruction , Existence comes from 123B0H~ 123B9H In a set of memory cells , We can think of ,123B0H~123B9H This memory unit is used to store code , It's a code snippet , Its segment address is 123BH, The length is 10 byte .
How to make the instructions in the code segment be executed ?
Think of a piece of memory as a code segment , It's just an arrangement when we're programming ,CPU Not because of this arrangement , We will automatically execute the instructions in our defined code segment as instructions .
CPU I don't know who I am CS:IP The contents of the memory unit pointed to are instructions .
So will CS:IP Points to the first address of the first instruction in the defined code segment .
CS = 123BH,IP = 0000H.
5. Summary
1、 Segment address in 8086CPU In the register of . When 8086CPU To access memory , The segment address of the memory unit is provided by the segment register .8086CPU Yes 4 Segment registers , among CS The address of the segment used to store instructions .
2、CS The address of the segment where the instruction is stored ,IP The offset address where the instruction is stored .
8086 In flight , Anytime ,CPU take CS:IP The point is executed as an instruction .
3、8086CPU Working process of :
(1) from CS:IP Read instructions to memory units , The read instruction enters the instruction buffer ;
(2)IP Point to the next instruction ;
(3) Execution instruction .( Go to step (1), Repeat the process .)
4、8086CPU Provide jmp Transfer instruction modification CS、IP The content of .
边栏推荐
- 【指针】查找最大的字符串
- 【指针】求解最后留下的人
- Transplant hummingbird e203 core to Da Vinci pro35t [Jichuang xinlai risc-v Cup] (I)
- Realize applet payment function with applet cloud development (including source code)
- Always of SystemVerilog usage_ comb 、always_ iff
- . Net6: develop modern 3D industrial software based on WPF (2)
- 王爽汇编语言详细学习笔记二:寄存器
- Fundamentals of digital circuit (IV) data distributor, data selector and numerical comparator
- 数字电路基础(二)逻辑代数
- SystemVerilog discusses loop loop structure and built-in loop variable I
猜你喜欢
ES全文索引
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
Lintcode logo queries the two nearest saplings
图书管理系统
《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案
1. Payment system
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
How to earn the first pot of gold in CSDN (we are all creators)
随机推荐
{1,2,3,2,5}查重问题
【指针】查找最大的字符串
图书管理系统
flask实现强制登陆
Web vulnerability - File Inclusion Vulnerability of file operation
移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
[pointer] find the length of the string
JDBC transactions, batch processing, and connection pooling (super detailed)
王爽汇编语言学习详细笔记一:基础知识
数字电路基础(一)数制与码制
Function: find 1-1/2+1/3-1/4+1/5-1/6+1/7-... +1/n
链队实现(C语言)
【指针】求解最后留下的人
JDBC看这篇就够了
Proceedingjoinpoint API use
《统计学》第八版贾俊平第四章总结及课后习题答案
Library management system
函数:求两个正数的最大公约数和最小公倍
Statistics, 8th Edition, Jia Junping, Chapter 6 Summary of knowledge points of statistics and sampling distribution and answers to exercises after class
ES全文索引