当前位置:网站首页>Assembly - getting started

Assembly - getting started

2022-07-05 03:37:00 X?

List of articles

1、 Basic knowledge of

In the computer , Usually a number followed by an English letter is used to represent the decimal number

For decimal D, The binary system uses B, Octal uses O, Hexadecimal use H

such as :115D,1010B,0754O,0075H

1#、 The steps for the computer to run the assembler

  1. Use an editor to create ASM Source file
  2. use MASM Program ( assembler ) hold ASM File conversion to OBJ file
    • assembler : Convert the source file into the object file represented by binary code . In the process of conversion, the assembler will scan the source program , If there is a grammatical error, it will point out . You can also expand macros
    • You can use the editor to change the error
  3. use LINK The program put OBJ File conversion to EXE file
    • The linker connects the object file with the library file or other object files to form an executable file
  4. use DOS The program can be executed by typing the file name directly with the command

1.1、 Hexadecimal conversion

1.1.1、 Decimal to other bases
#  Integral part 
 Decimal to other bases : Divide decimal numbers by decimal numbers , Until the quotient is zero , End of reverse remainder 
 for example :9D->1001B
9/2=4...1
4/2=2...0
2/2=1...0
1/2=0...1 
# End with zero quotient , Reverse remainder , So turn binary to 1001B

#  The fractional part 
 Decimal to other bases : Multiply to make the whole , Sequential output 
 for example :0.68D-> precision 5 Binary system 
0.68*2=1.36->1
0.36*2=0.72->0
0.72*2=1.44->1
0.44*2=0.88->0
0.88*2=1.76->1
#  Achieve the required accuracy of the topic , Output the integer parts in sequence 
# 0.68D->0.10101B
1.1.2、 Other decimal system to decimal system
#  Other decimal system to decimal system : Number of digits multiplied by bit weight , Bit weight starts from zero 
#  The same goes for decimals , Decimal from -1 Start 
 for example :1011B:1*2^0+1*2^1+0*2^2+1*2^3=1+2+0+8=11D
 for example :101O:1*8^0+0*8^1+1*8^2=17D
 for example :0.11B->1*2^-1+1*2^-2=0.75D
1.1.3、 Other base conversion
#  Binary to octal : Three in one , Three binary numbers are combined into one octal number 
#  Binary to hexadecimal : Four in one 
#  If the integer is not enough, fill zero forward , If the decimal is not enough, fill in the zero 
 for example :1011B:011->3 001( Fill zero forward if insufficient )->1 
#  therefore 1011B->13O

#  Other binary to binary is the reverse 

1.2、 Presentation of data

The smallest unit of information stored by a computer is called the smallest bit , In most systems, it can only represent 0 and 1 Two transitions

The computer system uses binary to represent numerical data

Binary encoding is also used to represent non numeric data and instructions

1.2.1、 The complement of a number indicates

The representation of a number and its symbol in the machine is numerically , Such numbers are called machine numbers

The most significant bit is generally used to represent the symbol of a number . For positive numbers 0 Express , Use negative numbers 1 Express

The number of machines can be represented by different code systems , Common original code , Complement and inverse notation

#  The complement represents a positive number and uses the symbol - Absolute value means : That is, the most significant bit of the number is 0 Indicates that the symbol is positive , The rest of the number represents the absolute value of the number 
 Assume that the machine word length is 8, be :[+1]_ repair =00000001

#  When the complement represents a negative number, use 2^n-|x| Express ,n Is the word length of the machine 
 Such as :[-1]_ repair =2^8-1=11111111

#  There is also a relatively simple way to find the complement : First write the complement of the positive number relative to the negative number , Then reverse it by bit , Finally add... At the end 1, This method is called complement operation 
 for example : Write -117D Complement 
+117D Expressed as 	0000 0000 0111 0101
 After bitwise inversion 	   1111 1111 1000 1010
 Last place plus 1		1111 1111 1000 1011
 In hexadecimal notation     F   F     8    B
#  therefore [-117]_ repair :0FF8BH

 Therefore, it can be proved that the number represented by complement has the following characteristics :
[x]_ repair - Make up >[-x]_ repair - Make up >[x]
1.2.2、 Addition and subtraction of complement
  • Addition rules of complement :[x+y]_ repair =[x]_ repair +[y]_ repair
  • Subtraction rule of complement :[x-y]_ repair =[x]_ repair +[-y]_ repair

1.3、 Basic data type

  1. byte : One byte by 8 Binary bits make up

  2. word : Two bytes make up a word , low 8 Bits are called low bytes , high 8 Bits are called high bytes

  3. Two words : low 16 The bit is called the bottom word , high 16 Bit is called high word

  4. Four words : Four words , Can be expressed with higher accuracy

  5. The cross :10 Byte composition

  6. character string : The group string of assembly language is a linear array composed of characters . Usually each character is represented by a byte , But sometimes each character can also be represented by a word or a double word

2、80x86

  • 80x86 Register group
Register name Register classification effect
AH|AL AX Data register As an accumulator , So it is the main register of arithmetic operation . On the way , Specified in the divide instruction to store operands . in addition , be-all I/O Instructions are to transfer information between this register and external devices
BH|BL BX Data register Use as a general register . In addition, when the computer memory address , It is often used as a base register
CH|CL CX Data register It can be used as a general-purpose register . In addition, it is often used to save the count value , As in a shift instruction , Used as an implicit counter in loop instructions and string processing instructions
DH|DL DX Data register Can be used as a general purpose register . Generally, when doing double word length operation, put DX and AX Put together a double word length number ,DX Used to store high-order words . Besides , For some I/O operation ,DX Can be used to store I/O Port address of
SP Stack pointer Pointer register It can be used to indicate the offset address of the segment top ,BP It can be used as a base address in the stack area to access the information in the stack
BP Base pointer Pointer register It can be done with ss It is used to determine the address of a storage unit in the stack segment
SI source address Index register SI and DI Generally used with DS In combination with , Used to determine the address of a storage unit in a data segment . Both index registers have the functions of automatic increment and automatic decrement , So it's very convenient to use it as an index
DI Destination address Index register In a string processing instruction ,SI and DI As an implicit source index and destination index register , here SI and DS In combination with ,DI and ES In combination with , The purpose of addressing in data segment and additional segment is achieved respectively
IP Instruction pointer Control register It is used to store the offset address in the code segment . In the process of running the program , It always points to the first address of the next instruction , It is associated with CS Determine the physical address of the next instruction by combining
FLAG Flag register Control register Storage condition code mark , Register of control flag and system flag
CS Code segment Segment register Segment registers are dedicated to memory addressing , Used to store segment addresses directly or indirectly
DS Data segment Segment register
SS stack segment Segment register
ES Additional segment Segment register
  • General registers

    • Data register , Pointer registers and index registers are collectively referred to as general purpose registers , These registers are for special purposes only , They can be used to transfer and temporarily store data , It can save operands and operation results in arithmetic and logic operations
  • Data register

    • It is mainly used to save information such as operands or operation results , Their existence saves the time required to occupy the bus and access memory for accessing operands
  • Index and pointer registers

    • It is mainly used to store the offset of a storage unit address , Or the offset of the starting address of a group of storage units , That is, it is used as a memory pointer . As a general register , They can also save 16 Operands and operation results in bit arithmetic logic operators , The result of the calculation is the offset of the required storage unit address
  • Special register

    • IP,SP,FLAGS, Segment register
  • Flag register FLAGS

    • Condition code symbol
      • When there is an operation result
      • The condition code flag is used to record the status information of the running results in the program , According to the operation results of relevant instructions, it is determined by cpu Automatically set .
      • OF: Overflow sign . In the process of calculation , If the operand exceeds the range that the machine can represent, it is called overflow . here OF Location 1, Otherwise, set 0
      • SF: sign indicator . A symbol that records the result of an operation , When the result is negative, it is 1, Otherwise, set 0
      • ZF: The result of operation is 0 when ,ZF Location 1. Otherwise, set 0
      • CF: Carry mark . Record the carry value generated from the most significant bit during the operation . for example , When the addition instruction is executed , Set when the most significant bit has carry 1, Otherwise, set 0
      • AF: Auxiliary carry flag . Record the carry value generated by the third bit during the operation . for example : When the third bit of the addition instruction is carried, it is set to 1, Otherwise, set 0
      • PF: Parity mark . It is used to provide inspection conditions for code errors that may occur when transmitting information in the machine . When the least significant bit of the result 1 Set when the number of is even 1, Otherwise, set 0
    • Control flag bit
      • DF: Direction signs . Controlling the direction of processing information in a string processing instruction . When DF by 1 when , After each operation, the index register SI and Di Reduce , This makes the string processing from high address to low address .
    • System flag bit
      • Can be used for I/O, Maskable interrupt , Program debugging , Control of task switching and system working mode
      • TF: Trap sign . Used for single step method operation during debugging . When TF Position as 1 when , Traps are generated after each instruction is executed , The computer is controlled by the system . When it comes to 0 when CUP Normal work , No traps
      • IF: Interrupt flag . When IF Position as 1 Time allowed CPU Respond to masked interrupt requests , otherwise , Turn off interrupt
      • IOPL:I/o Privilege level . In protected mode , Used to control pair I/O Access to address space

3、 Memory

The basic unit in which a computer stores information is a binary bit , One bit can store a binary number

Storing information in bytes in memory . Each byte unit is given a unique memory address , It's called the physical address . The address starts from zero , Add one at a time in sequence

The address is also expressed in binary numbers . It is an unsigned integer . The writing format is hexadecimal number

The information stored in a storage unit is called the content of the storage unit

Can be expressed as :(0004)=78H

A word into memory takes two consecutive bytes , When storing, the lower byte is stored in the lower address , The high byte is stored in the high address , The address of a word unit is represented by its low address

4、 Register addressing

4.1、 Addressing mode in real mode

stay 1mb In my memory , Each memory cell has a unique 20 Bit address , Called the physical address of the storage unit

CPU When accessing memory , The physical address of the storage unit to be accessed must be determined before the contents of the unit can be operated

20 The bit physical address consists of 16 Bit segment address and 16 Bit offset address composition

The logical address of the storage unit is determined by : Segment value and offset are two parts

A logical address indicates : Segment value : The offset

Segment address refers to the starting address of each segment ( Also known as segment base address )

The offset address refers to the offset value within the segment relative to the starting address of the segment

Physical address calculation : Move segment address left 4 Bit plus the offset address value to form the physical address . Or written as :

16d* Segment address + offset = Physical address

4.2、 Segment register

  • Each segment register can determine the starting address of a segment
  • Code segment CS
    • Used to store the currently running program
  • Data segment DS
    • Store the data required by the current running program
    • If the program uses string processing instructions , The source operand is also stored in the data segment
  • stack segment
    • Defines the area where the stack is located , The stack is a data structure , It opens up a special storage area
  • Additional segment
    • Is an additional data segment , It is an auxiliary data area , It is also the destination operand storage area of string processing instructions
paragraph The offset
csIP
SSSP or BP
DSBX,DI,SI Or a 16 digit
ESDI( For string instructions )

4.3、80x86 The addressing mode of

Computers solve problems by executing a sequence of instructions

Therefore, each computer has a set of instruction sets provided and used by users

This set of instructions is called the instruction system of the computer

The instructions in the computer are written by Opcode fields and Operand field Two parts

The operand field can have a 、 Two 、 Three . Usually called an address , 2. Address , Three addresses

When there are two operands , They are called source and destination operands, respectively

When the instruction is executed, the operation result is stored in the address of the destination operand

Assembly language is a symbolic language , It uses mnemonics to represent opcodes , Use symbols or symbolic addresses to represent operands or operand addresses . It corresponds to machine instructions one by one

Addressing mode : Represents the method used in the instruction to specify the address of the operand

4.3.1、 Immediate addressing mode

Stored directly in the operand , Immediately after the opcode , It is stored as part of the instruction in the code segment , Such operands are called immediate numbers .

The immediate number can be 8 Bit can also be 16 Bit

Immediate addressing is used to represent constants , It is often used to assign initial values to registers , And can only be used in the source operand field , Cannot be used to manipulate numeric fields for purposes

MOV AX,1234H
 The result is :(AX)=1234H
#  The immediate number is 8 Bits can only be passed to 8 Bit register ,16 Bits can only be passed to 16 Bit register 
4.3.2、 Register addressing

The operand is in the register , Instruction specifies the register number

about 16 Bit operands , The register can be :

AX,BX,CX,DX,SI,DI,SP,BP etc.

about 8 Bit operands , The register can be :

AL,AH,BL,BH,CL,CH,DL,DH

This addressing method because the operand is in the register

There is no need to access memory to obtain operands , Therefore, a high degree of operation can be obtained

MOV AX,BX
 Such as before the instruction is executed (AX)=3064H,(BX)=1234H, Then after executing the instruction :
(AX)=1234H,(BX) remain unchanged 
4.3.3、 Valid address

In addition to the above two addressing modes , The operands of the following addressing modes are in the storage area except for the code segment , Obtain the address of the operand through different addressing methods , So as to obtain the operand

stay 80x86 in , The offset address of the operand is called the effective address (EA)

Composition of valid addresses :

  1. Displacement : Is stored in an instruction 8 position 、16 position 、32 The number of bits , But it's not an immediate number , It's an address
  2. Base address : The contents stored in the base register . Is the base part of a valid address , Usually used to point to the first address of an array or string in a data segment
  3. Address : Is the content stored in the index register . Usually used to access an element in an array or a character of a string
  4. The scaling factor : yes 386 And a term for the addressing mode added by subsequent models . Its value can be 1,2,4,8. In addressing , The index value obtained by multiplying the contents of the index register by the scale factor

Valid address :EA= Base address +( Address * The scaling factor )+ Displacement

80x86 Only use 16 Bit addressing

Displacement :0,8,16 position

Base register :BX,BP

Index register :SI,DI

The scaling factor : nothing

In some cases ,80x86 Allows the programmer to change the default segment designated by the system by using the segment spanning prefix

But in the following cases , Segment spanning prefix... Is not allowed :

  1. The destination string of the string processing instruction must be ES paragraph
  2. PUSH The purpose and purpose of the instruction POP The source of the instruction must be SS paragraph
  3. Instructions must be stored in CS In the paragraph
  • Default segment selection rule
Access type Register and segment Default selection rule
Instructions Code segment cs register For addressing
Stack stack segment ss register All the stack in and out , Any use ESP or EBP Memory access as a base register
Local data Data segment DS register All data access except the destination string relative to the stack and string processing instructions
Target string Additional data segments ES register The destination string of the string processing instruction
4.3.4、 Direct addressing mode

The valid address of the operand contains only one component of the displacement , Its value is stored after the opcode of the instruction in the broken code segment . The value of the displacement is the effective address of the operand

Find the physical address through the effective address to obtain the content

80x86 In order to make the instruction bytes not too long , Specifies one of the two operands of a double operand instruction , Only one memory addressing mode can be used , This is also why a variable is often sent to the register first

Direct addressing is usually used to deal with a single memory variable . It can be implemented in 64K Look for operands in byte segments . Directly addressed operands are usually variables used by programs

  • for example :MOV AX,[8085H]

    • After execution (AX)=3035H

    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-L2L1kWRi-1656749854790)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE8c27d7e0f8ddaaf26c77965c61ed90d4/309)]

  • In assembly language instructions , You can use symbolic addresses instead of numeric addresses

    • MOV AX,VALUE perhaps MOV AX,[VALUE]
    • Such as VALUE In the additional paragraph , The segment override prefix should be specified as follows :
      • MOV AX,ES:VALUE or MOV AX,ES:[VALUE]
4.3.5、 Register indirection

The operand is in memory , The valid address of the operand is SI,DI,BX,BP In one of the four registers .

In general , If the valid address is SI,DI,BX in , with DS The contents of the segment register are segment values

The valid address is BP In the middle of the day , with SS The contents of the segment register are segment values

This addressing method can be used for table processing , After executing an instruction , Just modify the contents of the register to get the next item of the table

  • for example :MOV AX,[SI], If (DS)=5000H,(SI)=1234H

    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-e4Kj67EP-1656749854794)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE59ab4ac68632fb9b9a52125e045ed8a4/312)]

  • The instruction can also specify the segment override prefix to obtain the data in other segments

    • MOV AX,ES:[BX]
4.3.6、 Register Relative Addressing

The valid address of the operand is the base register (BX,BP) Or index register (SI,DI) As specified in the instructions 8 Bit or 16 Sum of displacement quantities

EA=((BX),(BP),(SI)(DI))+(8 Bit displacement or 16 Bit displacement )

In general, if SI,DI,BX As part of a valid address , Then the segment register is DS

If BP The content of is part of a valid address , Then the referenced segment register is SS

Given in an instruction 8 Bit or 16 The bit displacement is expressed in the form of complement

This addressing method can also handle tables , The first address of the table can be set as displacement , Get the value of the table by modifying the contents of the base address or index register

  • for example :MOV AX,COUNT[DI] or MOV AX,[DI+COUNT]

4.3.7、 Base index addressing mode

The effective address of the operand is the sum of the contents of a base register and an index register

EA=((BX),(BP))+((SI),(DI))

The segment value is the same as before

Used for array or table processing , The first address can be placed in the base register , The index register is used to access the elements of the array . Since both registers can be modified , So it is more flexible than direct indexing

  • for example :MOV AX,[BX] [DI] or MOV AX,[BX+DI]

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-QBatG0OQ-1656749854796)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE41addc8f05c0cc0c0602d006c9e87b68/316)]

4.3.8、 Relative base addressing

The effective address of the operand is the sum of the contents of a base register and an index register and the displacement specified in the instruction

EA=((BS),(BP))+((SI),(DI))+(8 Bit displacement or 16 Bit displacement )

The default segment is the same as before

  • for example :MOV AX,MASK[BX] [SI] or MOV AX,[MAXK+BX+SI]

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-4EfUYVD1-1656749854797)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEd24429924d26f99c7777f586a64a6b86/318)]

4.4、 Addressing mode related to transfer address

  • This addressing method is used to determine the transfer instruction and CALL The steering address of the command
  • It's for telling CPU How to modify CS and IP Value , To achieve the purpose of controlling program transfer
4.4.1、 Intra segment direct addressing

The valid address of the turn is the current IP The contents of the register are the same as those specified in the instruction 8 Bit or 16 Sum of displacement quantities

5、80x86 Command system

80x86 Most instruction skills deal with word data , It can also process byte data

Arithmetic and logic operations are not limited to accumulators

Memory operands can also directly participate in arithmetic and logic operations

80x86 Command system :

  1. Data transfer
  2. Arithmetic operations
  3. Logical operations
  4. String operation
  5. Program control
  6. Processor control

Assembly language instruction statement format :[ label :] Instruction mnemonics [ Operands 1 [, Operands 2]] [; notes ]

The label is only recognized by the assembler , It has nothing to do with instructions

5.1、 Data transfer instructions

  • The data transfer command is responsible for the data 、 An address or immediate number is transferred to a register or storage unit
5.1.1、 General data transfer instruction
Instructions effect
MOV delivery
MOVSX Extended transport with symbols
MOVZX With zero extension transmission
POSH Into the stack
POP Out of the stack
PUSHA/PUSHAD Stack all registers
POPA/POPAD All registers are out of stack
XCHG In exchange for
  • MOV Send instructions

The format is :MOV DST,SRC

operation :(DST)<----(SRC)

among DST For destination operands ,SRC Is the source operand

The source operand can be an accumulator 、 Registers and storage units . The transfer does not change the source operand

MOV The instruction does not affect the flag bit

Be careful : The source operand and destination operand cannot be both segment registers ; Code segment register CS Cannot be used as destination operand ; Instruction pointer IP Not as a source , Nor can it be used as an end . Double operands cannot use memory for both operands , So there must be a register . Destination operand cannot be immediate

  • CPU Internal register direct data transfer

    MOV AH,AL
    MOV DL,DH
    MOV BP,SP
    MOV AX,CS
    
  • The immediate number is sent to a general-purpose register or storage unit

    The immediate cannot be passed directly to the segment register

    An immediate can never be used as a destination operand

    MOV AL,3
    MOV SL,-5
    MOV VARB,-1 ;VARB It's a variable name , Represents a storage space 
    MOV VARW,3456H;VARW Is a word variable 
    
  • Data transfer between register and memory

    The type of source operand and destination operand should be consistent

    In addition to string operation instructions , The source operand and destination operand cannot be both memory operands

    MOV AX,VARW;VARW Is a word variable , Memory operands are direct addressing 
    MOV BH,[DI]; Memory operands are register indirect addressing 
    MOV VARB,DL;VARB Is a byte variable 
    
#  The segment mechanism must be sent to... Through registers DS register 
MOV AX,DATA_SEG
MOV DS,AX
  • XCHG Exchange instructions

Format :SCHG OPRD1,OPRD2

operation :( OPRD1)<---->(OPRD2)

It can easily realize the data exchange between general registers and general registers or storage units

Registers and memory cells can be two general-purpose operands . But excluding segment registers , Nor can it be a storage unit at the same time , There can't be an immediate number yet , Various memory addressing methods can be used to specify the storage unit

XCHG BX,[BP+SI]
(BX)=6F30H (BP)=0200H (SI)=0046H (SS)=2F00H (2F246)=4154H
 Physical address =2F000+0200+0046=2F246H
 After execution :(BX)=4154H (2F246H)=6F30H
  • MOVSX Signed extension instruction

Format :MOVSX DST,SRC

operation :(DST)<---- Extended with symbols (SRC)

== The instruction source operand can be 8 Bit or 16 The contents of a register or storage unit of bits , The destination operand must be 16 Bit or 32 Bit register

Does not affect the flag bit

  • MOVZX Transmit command with zero extension

And MOVSX Agreement

  • pop Stack instruction and push Stack in command

Access to the stack must be in words

80x86 Don't allow PUSH Use immediate addressing

POP When the instruction destination is a segment register , Do not use CS register

The segment value of the stack is in the stack register SS in

Stack pointer register SP Always point to the top of the stack

You can use addressing methods other than immediate numbers

  • PUSH Stack in command

Format :PUSH SRC

Perform the operation :(SP)<-----(sp)-2

Restructured the source operand SRC Push into the stack . It first puts the stack pointer register Sp The value of the reduction 2, Then put the source operand SRC Fed by SP The top of the stack

SRC It can be a general-purpose value register and a segment register, or it can be a word storage unit

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-w1BF5MtN-1656749854798)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEb1ce1cb339543c8ed9e3b3a4249e1c65/324)]

  • POP Stack out instruction

Format :POP DST

Perform the operation :(SP)<------(SP)+2

This instruction pops a word data from the top of the stack to the destination operand DST

DST It can be general register and segment register (CS exception ), It can also be a word storage unit

5.1.2、 Accumulator special transfer instruction

Can only be used with accumulators AX,EAX,AL Send messages

Instructions effect
IN Input
OUT Output
XLAT Change the code
  • IN Input instructions and OUT Output instruction

80x86 in , be-all I/O Port and port CPU All communications between them use IN and OUT complete

CPU You can only use the accumulator to receive and send information

External devices can have up to 65536 individual I/O port

The top 256 A port can be specified directly in the instruction , Long format PORT, At this time, the machine is represented by two bytes , The second byte is the port number

256 After the port number, you can only put the port number in DX In the register , Then send the message

IN And OUT Bytes are provided , word , Double word three modes , Depending on the peripheral port width

#  The long format is :
IN AL,PORT( byte )
#  The execution action is : (AL)<----(PORT)

#  The short format is 
IN AL,DX( byte )
#  Perform the operation :(AL)<----(DX)
5.1.3、 Address transfer instructions
Instructions effect
LEA The valid address is sent to the register
LDS Pointer to register and DS
LES Pointer to register and ES
LFS Pointer to register and FS
LGS Pointer to register and GS
LSS Pointer to register and SS
  • LEA The valid address is sent to the register instruction

Format :LEA REG,OPRD

This instruction converts the operands OPRD The valid address of is passed to the operand REG

Operands OPRD Memory must be an operand

Operands REG Must be a 16 Bit general register

SRC Any memory addressing method other than immediate operand and register operand can be used

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-bJpY4wXS-1656749854799)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE1751b3e3b959fab610c82488b39fecf6/320)]

  • LDS,LFS,LES,LGS,LSS

Format :LDS REG,SRC

Other instruction formats are the same as LDS Same format , The specified segment register is different

Perform the operation :16 position :(REG)<-------(SRC),(DS)<-----(SRC+2)

32 position :(REG)<-------(SRC),(DS)<-----(SRC+4)

This instruction converts the operands SRC One contained in 32 The segment value part of the bit address pointer is sent to the data register DS

Send the offset part to the general register given by the instruction REG

The directive SRC Only memory addressing mode can be used

REG Segment registers cannot be used , Index registers or pointer registers are often used

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-GiPb6uLI-1656749854801)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE350276ea4d7884dd2c40b222cbd92451/322)]

5.1.4、 Flag register transfer instruction
Instructions effect
LAHF Sign send AF
SAHFAH Send flag register
PUSHF/PUSHFD Mark the stack
POPF/POPFD Sign out of the stack
  • LAFH Sign send AF

Adopt fixed addressing mode

Format :LAFH

This instruction marks the bottom of the register 8 position ( Include SF、ZF、AF、PF and CF) Transfer to register AH Point positioning of

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-zL1HC8mC-1656749854802)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEbcc70465da72ce89df2b29f8a3e0d9f7/326)]

  • SAHF AH Send flag register

And LAHF contrary

5.1.5、 Flag bit operation instructions

All formats : Direct instructions

Such as :CLC

Instructions name effect
CLC Clear carry flag instruction This command causes the carry flag to be 0
STC Carry flag instruction This flag makes the carry flag 1
CMC Carry flag reverse instruction Invert the carry flag
CLD Clear the direction sign
STD Set the direction sign
CLI Clear interrupt permission flag
STI Set interrupt permission flag
5.1.6、 Type conversion instructions

Because the division instruction implicitly uses word divisor or double word divisor

So when the divisor is a byte , Or when both divisor and dividend are words

You need to extend the divisor before the divide operation

Instructions effect
CBW Byte to word
CWD Word to double
CDQ Double word to quadword
BSWAP Byte swapping

All formats : Direct instructions

for example :CBW

CBW: Put the register AL The symbols in are extended to registers AH

CBD: Put the register AX The symbols in are extended to registers DX

5.2、 Arithmetic instruction

5.2.1、 Add instruction
Instructions usage
ADD Add
ADC Add with carry
INC Add 1
XADD Swap and add
  • Add instruction

ADD Format :ADD DST SRC

operation :(DST)<------SRC+DST

Overflow flag judgment skills , If the symbols of two operands are opposite, set 1, Otherwise 0

OF Can be used to represent overflow of signed numbers ,CF It can represent the overflow of unsigned numbers

ADC And INC And ADD identical , however INC Instructions do not affect CF Sign a

INC Format :INC DST

DST It can be either a general-purpose register or a storage unit

It is mainly used to adjust the address pointer and counter

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Y1tALIFy-1656749854804)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE047ee7b1a346168172e6530b82ed68d3/328)]

5.2.2、 Subtraction instructions
Instructions usage
SUB Subtraction
SBB Subtraction with borrow
DEC Minus one
NEG Make up
CMP Compare
CMPXCHG Compare and exchange
CMPXCHG8B Compare and exchange 8 byte
  • Subtraction instructions

SUB Format :SUB DST,SRC

Actions performed (DST)<—(DST)-(SRC)

SBB Format :SBB DST,SRC

Actions performed :(DST)<----(DST)-(SRC)-CF

As long as it is used for subtracting multiple bytes

DEC Format :DEC OPR

Perform the operation :(OPR)<------(OPR)-1

ENG Format : And DEC equally

Yes -128 and -32768 Take complement ,OF by 1, For the other 0

The operands are 0 The result of time complement operation makes CF=0, Everything else is 1

CMP Format :CMP OPR1,OPR2

Actions performed :(OPR1)-(OPR)

Perform subtraction , But don't save the results , Change the condition flag bit only according to the result

If two numbers are unsigned , According to CF Judge the size

If both are signed numbers , According to SF and OF Judge the size

When subtraction has carry CF=0, When two numbers have opposite signs and the sign of the result is the same as the minus, then OF=1, Otherwise 0

  • Examples of operations

    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-SZaQ5w1c-1656749854805)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE3aa780f02e8dad4161fadcbbf130ed76/330)]

    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-utT1k4wi-1656749854807)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE4e32d29a50ae8dfd31a50efbc0a0e834/332)]

5.2.3、 Multiplication instructions
Instructions usage
MUL Unsigned multiplication
IMUL Signed multiplication
  • Multiplication instructions

MUL Format :MUL SRC

Actions performed : Byte operation :(AX)<—(AL)*(SRC)

Word operation :(DX,AX)<----(AX)*(SRC)

Double word operation :(EDX,EAX)<—(EAX)*(SRC)

In multiplication instructions, an operand is always implied in the register AL perhaps AX in , Another operand can be addressed in any way other than immediate

In the multiplication instruction , Destination operand must be an accumulator

If the upper half of the product result is not 0, be CF=1,OF=1, otherwise CF=0,OF=0

This instruction has no definition for other flag bits

IMUL Format :IMUL OPRD

Both the multiplier and the multiplier of this instruction are signed numbers

In addition, with instructions MUL It's exactly like

If the upper half of the product result is not the sign extension of the bottom half, the flag CF=1,OF=1, otherwise CF=0,OF=0

  • Example

    Signed multiplication :

    Make up the negative number , Change it to a positive number and multiply it , Then fill the result according to the number of times

    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-8PP50i1G-1656749854808)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEbb56e967ff2162830157a97bbb682d72/334)]

5.2.4、 Division instructions
Instructions usage
DIV Signed Division
IDIV Signed Division
  • Division instructions

In the division instruction , The dividend is always implied in the register AX( Divisor is 8 position ) perhaps DX and AX in ( Divisor is 16 position ),, Another operand can be addressed in any way other than immediate

Signed Division DIV Format :DIV OPRD

Byte operation is :(AL)<-----(AX)/(OPRD) The business of ;(AH)<----(AX)/(OPRD) The remainder of

Word manipulation as :(AX)<-----(DX,AX)/(OPRD) The business of ;(DX)<----(DX,AX)(OPRD) The remainder of

If the divisor is 0, Or in 8 The number is divided by the quotient 8 position . Or in 16 Bit division time quotient exceeds 16 position , Is considered to be except overflow , cause 0 Interrupt number

There is no definition of the effect of division instructions on flag bits

Signed division IDIV Format and DIV Agreement

Quotient and remainder must be signed , And the sign of the remainder is consistent with the sign of the divisor

== When the divisor is 0, Or the business is too big ( Byte division exceeds 127, Word division exceeds 32767), Or the quotient is too small ( Byte division is less than -127, Word division is less than -32767), cause 0 Interrupt number

  • Example

    Division is calculated in the same way as multiplication

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-yIMpjMjB-1656749854810)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEd6896a0157ef895c00471232c62f7309/336)]

5.2.5、 General example

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-OBf3ZOh8-1656749854811)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE68c22175d8b71d76282607f4eaf19f19/340)]

5.3、 Logical instruction

5.3.1、 Logical operation instructions
Instructions usage
AND Logic and
OR Logic or
NOT Logic is not
XOR Exclusive or
TEST test

Logical operation instructions can perform logical operations on words or bytes , Because logical operations are bitwise , So in general , Its operand should be a bit string, not a number

AND Logic and operation format :AND OPR1,OPRD2

This instruction performs bitwise logical and operations on two operands , The result is sent to the destination operand

If an operand matches itself , The value remains the same ,CF by 0

And instructions are mainly used to keep several bits of an operand unchanged , And the other digits are 0 The occasion of , Compare these bits that are to remain unchanged with 1 Meet each other , And please 0 And 0 Just meet each other

OR Logic or operation :OR DST,SRC

(DST)<----(DST)∨(SRC)

A value is relative to itself or , The value remains the same ,CF=0

It is mainly used to keep several bits of an operand unchanged , And some other positions are 1 The occasion of . Keep the same with 0 or , And become and 1 or

NOT Logic is not an operation :NOT OPRD

This instruction negates the operand , Then send the result to the operand

Operands can be general purpose registers , It can also be a memory operand .

This command has no effect on the flag

XOR Exclusive or operation :XOR DST,SRC

(DST)<----(OPR)⊕(SRC)

If a value is different from itself, or the value is 0,CF=0

== XOR is mainly used when several bits of an operand remain unchanged , And several other positions are reversed . Keep the same with 0 Exclusive or , Compare the opposite with 1 Exclusive or

TEST Test instruction :TEST OPRD1,OPRD2

(OPRD1)∧(OPRD2)

The result of the sum of two operands is not saved , Just set the condition code according to its characteristics

This instruction is usually used to detect whether some bits are 1, But do not want to change the source operation value

The above instructions ,NOT Immediate is not allowed , The other four instructions, unless the source operand is immediate , At least one operand must be stored in a register , Another operand can use any addressing method .NOT Does not affect the flag bit , Other instructions make CF and OF Set up 0,AF No definition ,SF,ZF,PF Set according to the calculation result

  • Example :

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-sQw8oLvc-1656749854812)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE209024077cf605b4e46b0aa88ccef736/344)]

5.3.2、 Bit test and modify instructions
Instructions usage
BT Bit test
BTS Test juxtaposition 1
BTR Test juxtaposition 0
BTC Bit test and reverse

The format is the same : Instructions DST,SRC

BT Instructions : Sends the value of the destination operand located by the source operand to CF

BTS Instructions : Sends the value of the destination operand located by the source operand to CF, And the position in the destination operand 1

BTR Instructions : Sends the value of the destination operand located by the source operand to CF, And the position in the destination operand 0

BTC Instructions : Sends the value of the destination operand located by the source operand to CF, And invert the bit in the destination operand

5.3.3、 Bit scan instruction
Instructions usage
BSF Forward scanning
BSR Reverse scanning

The format is the same : Instructions REG,SRC

BSF Instructions : Instruction slave bit 0 Start scanning source operands from right to left , The purpose is to retrieve the first one for 1 Bit 、 Meet the first for 1 The bit of will ZF Set up 0, And load the bit position of this bit into the destination register ; If the source operand is 0, be ZF=1, Destination operand undefined

The source operand of the instruction can specify word or doubleword in any addressing mode other than immediate , The destination operand must be a word or doubleword register

BSR Instructions : The instruction starts from the most significant bit and scans the source operand from left to right , The purpose is to retrieve the first one for 1 Bit 、 Meet the first for 1 The bit of will ZF Set up 0, And load the bit position of this bit into the destination register ; If the source operand is 0, be ZF=1, Destination operand undefined

5.3.4、 Shift instructions
Instructions usage
SHL Logic shift left
SAL Arithmetic shift left
SHR Logical shift right
SAR Arithmetic shift right
ROL Cyclic shift to the left
ROR Cycle moves to the right
RCL Shift left with carry cycle
RCR Shift right with carry cycle
SHLD Double precision left shift
SHRD Double precision shift right
  • Shift instructions

The format is the same : Instructions OPR,CNT

SHL Instructions : among OPR Use any addressing method other than immediate number . The number of displacements is determined by CNT decision , It can be 1 or CL. if CNT Greater than 1, First put the number of shifts to CL In the register .OPR And CNT The provisions apply to all of the following shift instructions

SAL Instructions : And SHL identical

The shift left command shifts every left shift , Right side use 0 Fill a , Move out of the highest position into the flag bit CF,OF Only one shift is 1, Others are undefined

A result that is not expressed by more than one byte to the left , Every time you move left , Double the weight of the source operand , That is, the original number times 2

Generally speaking, arithmetic shift left is regarded as a signed number , Logical shift left as unsigned number

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-UUAP5sXB-1656749854813)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEca093b10330579be530a35621d8f5c00/347)]

SHR Instructions : Use... On the left 0 Make up , The lowest bit moved out enters the flag bit CF

SAR Instructions : The highest position here moves to the right , At the same time, fill in... With its own value , It turns out to be 0 Still 0. The lowest bit moved out enters the flag bit

For signed or unsigned numbers , Shifting arithmetic one bit to the right is equivalent to dividing by 2

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-tY0cm6ey-1656749854815)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEbbc26eb377bea829d3a4249671543de3/349)]

  • Cyclic shift instruction

The format is the same : Instructions OPR,CNT

ROL

ROR

RCL

RCR

For cyclic shift instructions without carry , The number of operation bits can be restored . For circular instructions with carry , If the operand is 8 Bit , displacement 9 Recovery times , If the operand is 16 Bit , displacement 7 Recovery times

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-vU3IvL23-1656749854816)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE4856fb8a2b7a960d678f821d3086b0f9/351)]

  • The above two sets of instructions can operate on words or bytes . Their effect on condition codes is :CF Set... According to the results .OF Only when CNT=0 Only when effective , Otherwise, there is no definition . When CNT=1 when , When the value of the most significant bit changes after the shift ( Originally for 1, After shift 0; Originally for 0, After shift 1),OF by 1, Otherwise 0. The cyclic shift instruction is only for CF and OF Have an impact on . The shift instruction is only for AF No definition .

  • Double precision shift instruction

The format is the same : Instructions DST,REG,CNT

The instruction is a three operand instruction ,DST You can use any addressing method except immediate number . The source operand can only specify words or doublewords of the same length as the destination operand in register mode , The third number specifies the number of shifts

This set of instructions can take two words for shift operation and get the result of one word ; You can also go to two double words to get a double word result . In shifting , The register as the source operand provides the shift value , To compensate for the displacement of the operand vacancy , And after the instruction is completed , Only the destination operand is taken as the result of the shift , The value of the source operand unchanged

Instruction is mainly used in bit string transmission with boundary misalignment

The impact on the flag is consistent with the above

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-180uSisH-1656749854817)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEcf3cb3cfb5911c7cc75f36bb04cf84a1/353)]

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Myzpqn1o-1656749854818)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE0b83fbaebd0f8818d48a4b466b3060e0/355)]

5.3.5、 String processing instructions
Instructions usage
MOVS Serial transmission
CMPS String comparison
SCAS String scan
LODS Take... From the string
STOS Save string
INS String input
OUTS String output
Instruction prefix effect
REP repeat
REPE/REPZ equal / by 0 Then repeat
REPNE/REPNZ It's not equal / If it is not zero, repeat
5.3.6、 Control transfer instructions
  • Unconditional transfer instructions -JMP

JMP Jump instruction

Unconditionally transfer to the address specified by the instruction to execute the instruction starting from that address .JMP The instruction must specify the destination address of the transfer

Transfer is divided into intra segment transfer and inter segment transfer .

Intra segment transfer refers to the transfer within the same segment , At this point, just change IP or EIP The contents of the register , That is, the new transfer target address is used to replace the original IP or EIP The value of can achieve the purpose of transfer .

Inter segment transfer is to go to another segment to execute the program , At this point, you should not only modify IP and EIP The contents of the register , It needs to be revised CS The contents of the register can achieve the purpose . therefore , At this time, the transfer target address shall be composed of a new segment address and an offset address

  • Direct transfer instruction in unconditional segment

Format :JMP label ( opcode Address difference )

Address difference : From the start address of the next instruction of the unconditional transfer instruction in the program to the transfer target address ( The start address of the instruction specified by the label ) Difference value

Label for IP+ Address difference :IP=IP+ Address difference

So the actual action of the instruction is to add the address difference in the instruction to the instruction pointer IP On

This instruction transfers control unconditionally to the label address

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-b6aQXxIs-1656749854819)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEe34360b4054860b5c08181a7864a8a87/357)]

The address difference can be a byte or a word

If the address difference is one byte, it is called short transfer :

​ JMP NEAR PTR PROG

If the address difference is one word, it is called near transfer :

​ JMP SHORT QUEST

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-HPQap71V-1656749854820)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEea9fbfc5a1236804cb0daf1fce154cc4/359)]

  • An indirect transfer instruction within an unconditional segment

Format :JMP OPRD

This instruction unconditionally transfers control to the destination address given by the content of the operand

OPRD It can be a general register , It can also be a word storage unit

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-PVfJIk1Y-1656749854821)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEbbe301c73b6658bbc5e9d2eed182cc56/361)]

  • Unconditional inter segment direct transfer instruction

Format :JMP FAR PTR label

This instruction unconditionally transfers control to the address corresponding to the label

FAR PTR Indicates that this is an inter segment transfer

for example :JMP FAR PTR EXIT(EXIT Is a label in another code segment )

The specific action of unconditional inter segment direct transfer instruction is to put the segment value and offset of the target address contained in the instruction into CS and IP

This transfer method, which directly contains the transfer target address in the instruction, is called absolute transfer

  • Unconditional inter segment indirect transfer instruction

Format :JMP OPRD

This instruction causes the unconditional transfer of control to the operand OPRD At the given destination address .OPRD Must be a doubleword storage unit

for example :JMP DWORD PTR [1234H]; The bottom word content of the double word storage unit is sent to IP

​ ; The high word content of the double word storage unit is sent to CS

  • Unconditional example

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-qzMli3kX-1656749854822)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEe0f7e33dff1321853b4542c793a6f57e/363)]

5.3.7、 Conditional transfer instructions
  • The conditional transfer instruction determines whether the condition is true according to the logical operation of a flag bit or some flag bits , If established, transfer , Otherwise, continue to execute in sequence
  • All conditional transfers are just intra segment transfers
  • Conditional transfer does not affect the flag bit

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-oXunep54-1656749854822)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE7d66795caee1eb75bb480bf892d119b8/365)]

  • Transfer according to the setting of single condition flag

==JZ(JE)== The result is zero ( equal ) Then transfer

Format :JZ(JZ) OPR

Testing conditions ZF=1

==JNZ(JNE)== The result is not zero ( It's not equal ) Just transfer

Format :JNZ(JNE) OPR

Testing conditions :ZF=1

JS If the result is negative, it will be transferred JNS

Format :JS OPR

Conditions :SF=1

JO Overflow transfers JNO

Format :JO OPR

Conditions :OF=1

JP(JPE) The odd and even bits are 1 Then transfer JNP(JPO)

Format :JP OPR

Conditions :PF=1

==JB(JNAE,JC)== lower than , Or not higher than or equal to , Or carry to 1 Then transfer

==JNB(JAE,JNC)== No less than , Or higher than or equal to , Or carry to 0 Then transfer

Format :JB(JNAE,JC) OPR

Conditions :CF=1

  • Compare two unsigned numbers

JB(JNAE,JC)

JNB(JAE,JNC)

And 1 The last two are the same

==JBE(JNA)== Below or equal to , Or not higher than, then transfer

==JNBE(JA)== Not less than or equal to , Or not higher than, then transfer

Format :JBE(JNA)OPR

Conditions :CF∨ZF=1

  • Compare two signed numbers

==JL(JNGE)== Less than , Or not greater than or equal to, transfer

==JNL(JGE)== Not less than , Or greater than or equal to transfer

Format :JL(JNGE) OPR

Conditions :SF⊕OF=1

==JLE(JNG)== Less than or equal to , Or no more than, transfer

==JNLE(JG)== Not less than or equal to , Or greater than, transfer

Format :JLE(JNG)OPR

Conditions :(SF⊕OF)∨ZF=1

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-0xxU8gSv-1656749854823)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEdc6fe92c636238d5a45bdd7e8689e2f0/375)]

  • Whether the two numbers are equal can be determined by ZF reflect ,CF Reflect the size relationship after the comparison of two unsigned numbers , Two signed numbers consist of SF and OF Reflect together

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-0LZGoyNu-1656749854824)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE683821674d82515509a12aab408b096f/367)]

  • test CX or ECX The value of is 0 Then the transfer instruction

JCXZ cx The contents of the register are 0 Then transfer

JECXZ

Format :JCXZ OPR

Conditions :(CX)=0

Instructions can only provide 8 Bit displacement , That is, only short transfers can be made

Usually used before the beginning of the cycle , So that when the number of cycles is 0 Skip loop body

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-bpO0IDwd-1656749854825)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE51224002a68cdbe96023637c63165a3d/381)]

  • Example

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-u4CXoMaE-1656749854826)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEa6e396c5cfcde2331fcc12ce5bdea5f8/369)]

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-5VBxFgTJ-1656749854826)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE48ae35e974ef6c91289159e03450314d/371)]

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-big6nUyD-1656749854827)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEb7319ef4cdfc051e891900cbe1e9b2fd/373)]

5.3.8、 Condition setting instruction
5.3.9、 Cyclic instruction
Instructions effect
LOOP loop
LOOPZ/LOOPE When it is zero or equal, the loop
LOOPNZ/LOOPNE Loop when not zero or equal

The format is the same : Instructions OPR

LOOP Count loop command

Conditions :(Count Reg)!=0

This instruction makes the register CX The value of the reduction 1, If the result doesn't equal 0, Then transfer the label , Otherwise, execute in sequence

Usually in use LOOP When instructions form a loop , First set the counter CX Disposal of , The number of cycles

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-yy0dRYau-1656749854828)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE63ad5b67ec528ce42f19a65bc4ba32de/377)]

LOOPZ/LOOPE When it is zero or equal, the loop instruction

Conditions :ZF=1 And (Count Reg)!=0

The order makes CX The value of the reduction 1, When it comes to 0 Or equal ( And ZF=1), Then move to label , Otherwise, execute in sequence

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-J45fFBNl-1656749854829)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE1da8305f154881fe5fc22d2829de1bcb/379)]

LOOPNZ/LOOPNE Loop instruction when not zero or equal

Conditions :ZF=0 And (Count Reg)!=0

The execution steps of the above instructions are :

  1. (Count Reg)<-----(Count Reg)-1
  2. Check whether the test conditions are met , If satisfied and the length of the operand is 16 position , be (IP)<----(IP)+D8 The symbol extension of ; If satisfied and the length of the operand is 32 When a , be (EIP)<----(EIP)+D8 The symbol extension of

The circular instruction also adopts the method of relative transfer , That is to say, through IP Add an address difference to realize the transfer , Circular instructions also use only one byte to represent the address difference

If we take the loop instruction itself as the benchmark , Then the scope of circular transfer is -126 To +129 Between

The loop instruction does not affect the flag

  • Example

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-MHAgcOb8-1656749854830)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE4e08d6d399f27be6cbbeb85259ab8478/383)]

6、 Pseudo instruction statement

  • Assembly language statements
    1. Instruction statement
    2. Pseudo instruction statement
    3. Macro instructions
  • Pseudo instruction statement There is no corresponding machine instruction , Just tell the assembler how to assemble the source program , Including the definition of symbols 、 Definition of variables 、 Definition of the segment 、 The choice of processor 、 Define program patterns 、 Defining data 、 Allocate store 、 Indicate the end of the program, etc .
  • Pseudo instruction an operation handled by the assembler during the assembly of the source program by the assembler
  • Pseudo instruction statement format

( name ) Action items ( Parameters , Parameters )(; notes )

The pseudo instruction definer specifies the function of the pseudo instruction

The difference between label and name : The label is followed by a colon , Name no

Label and name naming rules : Generally by 31 Letters 、 Numbers and specified special characters ([email protected]_$) Other components , And it cannot be composed of numbers

Pseudo instruction Parameters It can be a general symbol 、 Symbols of special significance 、 Constant or expression

6#、 Address expression, variable and label
  • Represents the address of the memory operand

  • Single label 、 Variable ( Corresponding to the direct addressing mode ) And a base or index register enclosed in square brackets ( Corresponding register indirect addressing ) Is a special case of address expression

  • A storage address can be added or subtracted

    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-b4WtmgJE-1656749854831)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE6a6dbf75bb08c356b9a57ae48955658f/395)]

  • Variables and labels represent storage units

    • The value is stored in the storage unit represented by the variable
    • The storage unit indicated by the label stores the instruction code
    • All have the following three properties :
      1. Segment value : The variable or label corresponds to the segment value of the segment where the storage unit is located
      2. The offset : The variable or label corresponds to the intra segment offset of the starting address of the storage unit
      3. type : The main types of variables are BYTE etc. , The main types of labels are NEAR and FAR, Near indicates the label in the segment , Far indicates the inter segment label
6.1、 constant
  • Decimal constant

    • In general, the constants of assembler are represented by decimal numbers , Therefore, the suffix letter is generally not added D, But assembly language provides Pseudo instructions that change cardinality RADIX

      [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-iPTY0VDN-1656749854833)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE8ede8982c0cc6a4a59cb4f87346d0fda/385)]

  • Hexadecimal constant

    • It has to be made up of letters H ending , Hexadecimal must start with a number , So what starts with a letter 16 Hexadecimal numbers need to be preceded by 0
  • Binary number

    • It has to be made up of letters B ending
  • Octal constant

    • It has to be made up of letters Q ending
  • String constant

    • One or more characters enclosed in quotation marks
    • The value of the string constant is the character enclosed in quotation marks ASCLL Code value
     for example :'A' by 41H
    'ab' by 6162H
    
6.2、 Action items
6.2.1、 Arithmetic operators
  • Include + just 、- negative 、+、-、*、/ and MOD model

    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-6XH3RO8V-1656749854834)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEa9be609058fac5a6963a0cc93d6227bf/387)]

6…2.2、 Relational operator
  • Including equality (EQ), Unequal (NE), Less than (LT), Greater than (GT), Less than or equal to (LE), Greater than or equal to (CE)
  • The result of the operation is a numeric value
    • The result of the establishment of the relationship is 0
    • If not, it is 0FFFFH

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-zrT8pzOs-1656749854835)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEc966ef183688a163aaaa4101b0387235/389)]

6.2.3、 Logic and shift operators
  • Include and (AND)、 or (OR)、 Exclusive or (XOR)、 Not (NOT)、 Left displacement (SHL)、 Right displacement (SHR)

  • The result of logical operation is also numerical

    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-VOMEZzaY-1656749854836)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEfe3b58cf38f8c8274cd892dc85f13ee0/391)]

6.2.4、 Byte separation operator
The operator Use format Calculation results
HIGHHIGH expression The height of a numeric expression 8 position
LOWLOW expression The bottom of a numeric expression 8 position

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-lJ9FIBWb-1656749854837)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCE33a797a0a8dbe83f45fff457bbe0efbd/393)]

6.2.5、 Numeric loopback operator
  • These operators transfer some features or part of the memory address as numeric values
  • It mainly includes TYPE,LENGTH,SIZE,OFFSET,SEG etc.
  1. TYPE

Format :TYPE Operand

DB by 1,DW by 2,DD by 4,DF by 6,DQ by 8,DT by 10

for example : ARRAY DW 1,2,3

​ ADD SI,TYPE ARRAY

Equate to :ADD SI,2

  1. LENGTH

Format :LENGTH Operand

Echo for operand items by DUP Number of space units allocated , For other cases, answer 1

LENGTH FEES DW 100 DUP(?)

Equate to 100

  1. SIZE

The format is consistent

Echo the number of bytes allocated to this variable , But this value is LENGTH and TYPE The product of the

SIZE FEES

Equate to 200

  1. SEG

The format is consistent

Echo segment address value of variable or label

If FEES The segment address is 05000H Data section of , be SEG FEES The echo is 05000H

  1. OFFSET

The format is consistent

The assembler will return the offset address of the variable or label

6.2.6、 Property operators

It mainly includes PTR、 Segment operator 、SHORT、THIS、HIGH、LOW、HIGHWORD、LOWWORD

  1. PTR

Format :type PTR expression

PTR Used to create a symbolic address , But it does not allocate memory itself , Just give another attribute to the allocated memory address , Make the address have another attribute

tow_byte DW ?

ONE_byte EQU BYTE PTR two_byte

tow_byte And ONE_byte Have the same segment address and offset address , But the type attribute of the former is 2, The latter is 1

  1. Segment operator

Used to represent a scalar 、 Segment attribute of variable or address expression

for example :MOV AV,ES:[BX+SI]

So we use name plus address expression to express its attribute

  1. SHORT

To embellish JMP The attribute of the steering address in the instruction , Point out that the steering address is at the address of the next instruction +127 Within bytes

  1. THIS

Be similar to PTR, But it is the same as the segment address and offset address of the next storage space

for example :first EQU THIS BYTE

​ second DW 100 DUP(?)

first And second The segment address of is the same as the offset address , But the types are different

  1. HIGH and LOW: Byte separation operator

  2. HIGHWORD and LOWWORD: Word separation operator

6.2#、 Priority of operation items
  1. Items in parentheses , Items in square brackets 、 Structural variables 、LENGTH、SIZE、WIDTH、MASK
  2. name :( Segment substitution )
  3. PTR,OFFSET,SEG,TYPE,THIS And segment operators
  4. HIGH,LOW
  5. Multiplication and division :*,/,MOD,SHL,SHR
  6. Add and subtract
  7. Relational operator
  8. Logical operators :NOT
  9. Logical operators :AND
  10. Logical operators :OR,XOR
  11. SHORT
6.3、 Program start and end pseudo instructions

In the process of Start It can be used NAME or TITLE As the name of the module

NAME The format is :NAME module_name

TITLE The format is :TITLE text

The assembler will put module_name As the module name . Will be able to text The first six characters of are used as the module name ,text There can be 60 Characters ,TITLE You can specify the print title of each page of the list file .

If neither NAME either TITLE Will take the source program name as the module name

Represents the source program end The operation of :END [label]

label label Indicates the starting address at which the program starts execution

6.4、 Data definition
  • Data items can be allocated storage units through data definition statements , And set its initial value as needed . Symbols can also be used to represent data items , At this point, the symbol is associated with the allocated storage unit , At this point, the symbol is called a variable

  • Format

    [ Variable name ] Data definer expression [, expression , expression ]; notes

    [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-fAOHTnxK-1656749854838)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEcb00d728646ce6ce455429ab0c73d869/397)]

  • Data definer

    Data definer effect example
    DB Define a byte , Each subsequent operand occupies a byte [ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-6axZcx9C-1656749854839)(https://note.youdao.com/yws/public/resource/92933d878935240680c00793fc3e404c/xmlnote/WEBRESOURCEe1aa73a83383ec369cf84534cdd49f1e/400)]
    DW Definition words , You can store addresses
    DD Define doubleword , You can store addresses
    DF Definition 6 A byte word , Can be stored by 16 Bit segment address and 32 Far address pointer composed of bit offset address
    DQ Define four words
    DT Definition 10 Bytes
  • ? Operands

    • Operands ? You can reserve storage space without storing data
     for example :ABC DB 0,?,?,1
    
  • Copy operator (DUP)

Format :repeat_count DUP ( expression , expression )

repeat_count Represents the number of times to copy

The expression represents the number to copy

for example :A DB 2 DUP(0,1,2,3)

hold 0,1,2,3 Copy 2 Time , therefore A All together 8 Bytes

  • Type attribute of operand

Define data with data definer and endow data with implicit type attributes

But it can be used in assembly PTR Attribute operators to define data type attributes :

type PTR Address expressions

type:DB----->BYTE

​ DW----->WORD

​ DD----->DWORD

​ DF----->FWORD

​ DQ----->QWORD

​ DT----->TBYTE

PTR Attribute operators take precedence over implicit type attributes

for example :MOV AL BYTE PTR OPE

​ MOV AX WORD PTR OPE

The first sentence means to OPE The content of the first byte in is transmitted to AL

The second sentence is ba OPE The first word is sent to AX

6.4、LABEL Pseudo instruction

From above PTR The example of attribute operator shows that the same variable can have different types of attributes

In addition to defining with attribute operators , You can also use LABEL Pseudo instruction

Format

For data items :name LABEL type

For executable code :name LABEL type

For executable code type It can be for NEAR and FAR

about 16 position NEAR by 2 position ,FAR by 4 position

about 32 position NEAR by 4 position ,FAR by 6 position

for example :BYTE_ARRAY LABEL BYTE

​ WORD_ARRAY DW 50 DUP(?)

This way 100 The first address of an array is given BYTE_ARRAY and WORD_ARRAY Two variable names

6.5、 Expression assignment pseudo instruction EQU

When the expression appears repeatedly in the program , You can use EQU Give the expression a name

Format :name EQU expression

for example DATA EQU HEIGHT+2

Assign the following expression to a DATA、 name , But if there is a variable in the expression , The assignment can only be performed after the variable is defined , Otherwise, the report will be wrong

in addition := And EQU It's about the same , however = It can be assigned repeatedly ,EQU no way

for example :e=2

​ e=e+1

6.6、 Address counter and alignment pseudo instruction
6.6.1、 Address counter $

Use the address counter to save the offset address of the instruction currently being assembled . When starting compilation or at the beginning of each paragraph , Initialize the address counter to zero , Every instruction processed in the future , The address counter is incremented by a value

$ stay Instructions The middle time represents the first address of the instruction

$ stay Pseudo instruction Indicates the current value of the segment address counter

6.6.2、ORG Pseudo instruction

ORG Used to set the value of the current address counter

The format is :ORG expression

It can be used to modify the address of the next byte

6.6.3、EVEN Pseudo instruction

Make the next variable or instruction start at an even byte address

Format :EVEN

6.6.4、ALIGN Pseudo instruction

It is used to ensure that the boundary of the doubleword array is from 4 Multiples of begin to create conditions

The format is :ALIGN boundary

Parameter must be 2 The power of

6.7、 Segment definition directives
  • ? Operands

    • Operands ? You can reserve storage space without storing data
     for example :ABC DB 0,?,?,1
    
  • Copy operator (DUP)

Format :repeat_count DUP ( expression , expression )

repeat_count Represents the number of times to copy

The expression represents the number to copy

for example :A DB 2 DUP(0,1,2,3)

hold 0,1,2,3 Copy 2 Time , therefore A All together 8 Bytes

  • Type attribute of operand

Define data with data definer and endow data with implicit type attributes

But it can be used in assembly PTR Attribute operators to define data type attributes :

type PTR Address expressions

type:DB----->BYTE

​ DW----->WORD

​ DD----->DWORD

​ DF----->FWORD

​ DQ----->QWORD

​ DT----->TBYTE

PTR Attribute operators take precedence over implicit type attributes

for example :MOV AL BYTE PTR OPE

​ MOV AX WORD PTR OPE

The first sentence means to OPE The content of the first byte in is transmitted to AL

The second sentence is ba OPE The first word is sent to AX

6.4、LABEL Pseudo instruction

From above PTR The example of attribute operator shows that the same variable can have different types of attributes

In addition to defining with attribute operators , You can also use LABEL Pseudo instruction

Format

For data items :name LABEL type

For executable code :name LABEL type

For executable code type It can be for NEAR and FAR

about 16 position NEAR by 2 position ,FAR by 4 position

about 32 position NEAR by 4 position ,FAR by 6 position

for example :BYTE_ARRAY LABEL BYTE

​ WORD_ARRAY DW 50 DUP(?)

This way 100 The first address of an array is given BYTE_ARRAY and WORD_ARRAY Two variable names

6.5、 Expression assignment pseudo instruction EQU

When the expression appears repeatedly in the program , You can use EQU Give the expression a name

Format :name EQU expression

for example DATA EQU HEIGHT+2

Assign the following expression to a DATA、 name , But if there is a variable in the expression , The assignment can only be performed after the variable is defined , Otherwise, the report will be wrong

in addition := And EQU It's about the same , however = It can be assigned repeatedly ,EQU no way

for example :e=2

​ e=e+1

6.6、 Address counter and alignment pseudo instruction
6.6.1、 Address counter $

Use the address counter to save the offset address of the instruction currently being assembled . When starting compilation or at the beginning of each paragraph , Initialize the address counter to zero , Every instruction processed in the future , The address counter is incremented by a value

$ stay Instructions The middle time represents the first address of the instruction

$ stay Pseudo instruction Indicates the current value of the segment address counter

6.6.2、ORG Pseudo instruction

ORG Used to set the value of the current address counter

The format is :ORG expression

It can be used to modify the address of the next byte

6.6.3、EVEN Pseudo instruction

Make the next variable or instruction start at an even byte address

Format :EVEN

6.6.4、ALIGN Pseudo instruction

It is used to ensure that the boundary of the doubleword array is from 4 Multiples of begin to create conditions

The format is :ALIGN boundary

Parameter must be 2 The power of

原网站

版权声明
本文为[X?]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050303492356.html