Upload
hoanghanh
View
243
Download
5
Embed Size (px)
Citation preview
ADD InstructionADD destination,source
destination = destination + source
ADD AX,BXADD SUM,EAXADD EDX,ARRAY[EBX][ESI]ADD CL,5ADD DL,[BX]
ADC InstructionADC destination,source
destination = destination + source + carry
ADC DX,BXADC COUNT,ECXADC EAX,ARRAY[EBX][ESI]
XADD InstructionXADD destination,source
destination = destination + sourceSource = original destination
Assume:BX = 0AHDX = 11H
After XADD BX,DX is executed:BX = 1BHDX = 0AH
80486 and Pentium instruction.
INC Instruction
INC operandoperand = operand + 1
INC BXINC COUNTINC DWORD PTR [EBX]
SUB InstructionSUB destination,source
destination = destination - source
SUB AX,BXSUB SUM,EAXSUB EDX,ARRAY[EBX][ESI]SUB CL,5SUB DL,[BX]
SBB InstructionSBB destination,source
destination = destination - source - carry
SBB DX,BXSBB COUNT,ECXSBB EAX,ARRAY[EBX][ESI]
DEC InstructionDEC operand
operand = operand - 1
DEC BXDEC COUNTDEC DWORD PTR [EBX]
CMP InstructionCMP operand1,operand2
operand1 - operand2Flags are updated and the result is discarded.
CMP AL,BLCMP BX,0ABCHCMP DL,[BX]
CMPXCHG InstructionCMPXCHG operand1,operand2
If operand1 = accumulator thenaccumulator = operand2
Elseaccumulator = operand1
CMPXCHG BL,CLCMPXCHG DATA,EDX
CMPXCHG8B allows the comparison of quad words
MUL and IMUL InstructionsMUL operand (unsigned product)IMUL operand (signed product)
accumulator = accumulator * operand
MUL BLAX = AL * BL
MUL CX<DX>:<AX> = AX * CX
MUL EBX<EDX>:<EAX> = EAX * EBX
MUL and IMUL InstructionsMUL BYTE PTR TEMP
AX = AL * TEMPMUL WORD PTR [DI]
<DX>:<AX> = AX * [DI]MUL DWORD PTR [EBX]
<EDX>:<EAX> = EAX * [EBX]
Special Immediate 16 bit Product
IMUL reg,immIMUL reg,reg,immIMUL reg,mem,imm
IMUL CX,16CX = CX * 16
IMUL DX,DATA,2DX = DATA * 2
DIV and IDIV InstructionsDIV operand (unsigned division)IDIV operand (signed division)DIV BL
AL (quotient) = AX / BLAH (remainder) = AX / BL
DIV CXAX (quotient) = <DX>:<AX> / CXDX (remainder) = <DX>:<AX> / CX
DIV and IDIV InstructionsDIV EBX
EAX (quotient) = <EDX>:<EAX> / EBXEDX (remainder) = <EDX>:<EAX> / EBX
DIV BYTE PTR TEMPDIV WORD PTR [DI]DIV DWORD PTR [EBX]
BCD ArithmeticInstructions that use packed BCD operands.DAA - Decimal adjust after addition.DAS - Decimal adjust after subtraction.
MOV BL,14HMOV AL,47HADD AL,BLDAA
ASCII ArithmeticInstructions that use unpacked BCD operands.AAM – Adjust after multiplication.
MOV AL,5MOV BL,8MUL BLAAM
AAD – Adjust before division.MOV AL,12MOV BL,3AADDIV BL
ASCII Arithmetic
Instructions that use ASCII operands.AAA – Adjust after addition.AAS – Adjust after subtraction.
MOX AX,31HADD AL,39HAAAADD AX,3030H
AND Instruction
AND destination,sourcedestination = destination · source
AND AX,BXAND SUM,EAXAND EDX,ARRAY[EBX][ESI]AND CL,5AND DL,[BX]
OR Instruction
OR destination,sourcedestination = destination + source
OR AX,BXOR SUM,EAXOR EDX,ARRAY[EBX][ESI]OR CL,5OR DL,[BX]
XOR Instruction
XOR destination,sourcedestination = destination ⊕ source
XOR AX,BXXOR SUM,EAXXOR EDX,ARRAY[EBX][ESI]XOR CL,5XOR DL,[BX]
NOT and NEG Instructions
NOT operand – 1’s complementNEG operand – 2’s complement
operand = operand’
NOT BXNEG SUMNOT ECXNEG CL
TEST InstructionTEST operand1, operand2
operand1 · operand2Flags are updated and the result is discarded.
TEST AX,BXTEST SUM,EAXTEST CL,5TEST DL,[BX]
Shift InstructionsThese instructions perform the logical and arithmetic shifts.SHL destination,countSAL destination,countSHR destination,countSAR destination,count
Count can be an immediate value or the CX register.
SHL AX,CXSAR DL,1
Rotate InstructionsThese instructions perform the logical and arithmetic shifts.RCL destination,countROL destination,countRCR destination,countROR destination,count
Count can be an immediate value or the CX register.
ROL EDX,16RCR BH,CL
Conditional TransfersThese instructions conditionally modify the EIP register to be one of two addresses defined as follows:
An address or displacement following the instruction (label);The address of the instruction following the conditional jump.
Ex:JE SUMSUB EAX,EBX
.
.SUM:
Conditional TransfersUsed with unsigned integers
JA/JNBE – Jump if above – Z=0 and C=0JAE/JNB – Jump if above or equal – C=0JB/JNA – Jump if below – C=1JBE/JNA – Jump if below or equal – Z=1 and C=1
CMP AL,BLJA NEXTMOV CL,0
.
.NEXT:
Conditional TransfersUsed with signed integers
JG/JNLE – Jump if greater – Z=0 and S=0JGE/JNL – Jump if greater or equal – S=0JL/JNGE – Jump if less – S<>0JLE/JNG – Jump if less or equal – Z=1 and S<>0
CMP AL,BLJLE NEXTMOV CL,0
.
.NEXT:
Conditional TransfersOther conditions
JE/JZ – Jump if equal – Z=1JNE/JNZ – Jump if not equal – Z=0JC – Jump if carry - C=1JNC – Jump if not carry – C=0JS – Jump if sign – S=1JNS – Jump if not sign – S=0JO – Jump if overflow – O=1JNO – Jump if not overflow – O=0
Conditional TransfersJP/JPE – Jump if parity/parity even – P=1JNP/JPO – Jump if not parity/parity odd – P=0JCXZ – Jump if CX is zeroJECXZ – Jump if ECX is zero
Conditional Set
The 80386 and above processors have conditional set instructions. These instructions set a byte to 01H or 00H depending on the value of the flag or condition under test.Example:
SETZ COUNT_ZERO
Conditional SetUsed with unsigned integers
SETA – Set if above – Z=0 and C=0SETAE – Set if above or equal – C=0SETB – Set if below – C=1SETBE – Set if below or equal – Z=1 and C=1
Used with signed integersSETG – Set if greater – Z=0 and S=0SETGE – Set if greater or equal – S=0SETL – Set if less – S<>0SETLE – Set if less or equal – Z=1 and S<>0
Conditional SetOther conditions
SETE/SETZ – Set if equal – Z=1SETNE/SETNZ – Set if not equal – Z=0SETC – Set if carry - C=1SETNC – Set if not carry – C=0SETS – Set if sign – S=1SETNS – Set if not sign – S=0SETO – Set if overflow – O=1SETNO – Set if not overflow – O=0
Conditional SetSETP/JPE – Set if parity/parity even – P=1SETNP/SETPO – Set if not parity/parity odd – P=0
Controlling the Flow of the Program Using Dot Commands
Dot commands are available for MASM version 6.xx and above.They do not work with Visual C++ inline assembler.When these directives are found the assembler inserts the appropriate instructions that will perform what the directives indicate.
Controlling the Flow of the Program Using Dot Commands
Commands:.IF, .ELSE, .ELSEIF, and .ENDIF.WHILE, .BREAK, .CONTINUE and .ENDW.REPEAT, .UNTIL, and .UNTILCXZ
.IF, .ELSE, .ELSEIF, and .ENDIF
Relational operators used with .IF statements
Operator Function== Equal!= Not equal> Greater than
>= Greater than or equal< Less than
<= Less than or equal& Bit test! Logical inversion
&& Logical AND|| Logical OR| OR
.IF, .ELSE, .ELSEIF, and .ENDIF
INC BL.IF BL >= 205 || BL<= 2ADD BL,CL.ENDIFMOV DX,1
INC BL.IF BL >= 205 || BL<= 2CMP BL,205JAE @C001CMP BL,2JA @C002@C001:ADD BL,CL.ENDIF@C002:MOV DX,1
.WHILE, .BREAK, .CONTINUE and
.ENDW
The .BREAK statement allows for unconditional exit from loop. The .BREAK statement may be followed by an .IF statement thus allowing for conditional exit from the loop.The .CONTINUE statement behaves in the reverse way as the .BREAK statement. It is always conditional.
.WHILE, .BREAK, .CONTINUE and
.ENDW.WHILE BL >= 1MOV BL, DATA[SI]MOV COPY[SI],BLINC SI.ENDWMOV AX,DX
.WHILE BL >= 1JMP @C001@C002:MOV BL, DATA[SI]MOV COPY[SI],BLINC SI.ENDW@C001:CMP BL,1JAE @C002MOV AX,DX
Procedures
Also known as subroutines, these sets of instructions usually perform a single task.They are reusable code, that can be executed as often as needed by calling it.Procedures save memory, but the calling of a procedure takes a small amount of time.
ProceduresFormat
Name PROC [NEAR or FAR]Subroutine codeRET
ENDP
Global procedures are defined as FAR.Local procedures are defined as NEAR.
ProceduresCALL destination
Calls a subroutine at location destination.Different addressing modes may be used for destination.
CALL DELAYCALL EBXCALL ARRAY[BX]
RETReturns execution of program to location stored in stack.NEAR or FAR is dependent on procedure definition.
InterruptsINT typeINTO – Interrupt if overflowIRETThese instructions modify the EIP register to be the address stored at:
The IDT. The interrupt type or number is used to identify which element of the IDT holds the addresses of the desired interrupt service subroutines;The stack. The address stored in the stack by the INT or INTO instruction. This address identifies the return point after the interrupts execution.
Miscellaneous Control InstructionsWAIT – Delays the execution of the program conditionally to the BUSY’ pin.HLT – It stops execution of software. There are three way to exit a halt instruction:
Interrupt;Hardware reset;DMA operation.
NOP – No operation.LOCK’ Prefix – Causes LOCK’ pin to become logic 0.
Miscellaneous Control Instructions
ESC – Passes information to the numerical co-processor.BOUND – Comparison that may generate an interrupt call. The comparison is between the contents of two words or double words, an upper and a lower boundary.ENTER and LEAVE – Allow the creation and use of stack frames.