+ All Categories
Home > Documents > ADD Instruction ADD destination,source destination = destination + source ADD AX,BX ADD SUM,EAX ADD...

ADD Instruction ADD destination,source destination = destination + source ADD AX,BX ADD SUM,EAX ADD...

Date post: 17-Dec-2015
Category:
Upload: sophie-gray
View: 236 times
Download: 5 times
Share this document with a friend
45
ADD Instruction ADD destination,source destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]
Transcript
Page 1: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

ADD Instruction ADD destination,source

destination = destination + source

ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Page 2: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

ADC Instruction ADC destination,source

destination = destination + source + carry

ADC DX,BX ADC COUNT,ECX ADC EAX,ARRAY[EBX][ESI]

Page 3: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

XADD Instruction XADD destination,source

destination = destination + source Source = original destination

Assume: BX = 0AH DX = 11H

After XADD BX,DX is executed: BX = 1BH DX = 0AH

80486 and Pentium instruction.

Page 4: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

INC Instruction INC operand

operand = operand + 1

INC BX INC COUNT INC DWORD PTR [EBX]

Page 5: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

SUB Instruction SUB destination,source

destination = destination - source

SUB AX,BX SUB SUM,EAX SUB EDX,ARRAY[EBX][ESI] SUB CL,5 SUB DL,[BX]

Page 6: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

SBB Instruction SBB destination,source

destination = destination - source - carry

SBB DX,BX SBB COUNT,ECX SBB EAX,ARRAY[EBX][ESI]

Page 7: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

DEC Instruction DEC operand

operand = operand - 1

DEC BX DEC COUNT DEC DWORD PTR [EBX]

Page 8: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

CMP Instruction CMP operand1,operand2

operand1 - operand2 Flags are updated and the result is discarded.

CMP AL,BL CMP BX,0ABCH CMP DL,[BX]

Page 9: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

CMPXCHG Instruction CMPXCHG operand1,operand2

If operand1 = accumulator then accumulator = operand2

Else accumulator = operand1

CMPXCHG BL,CL CMPXCHG DATA,EDX

CMPXCHG8B allows the comparison of quad words

Page 10: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

MUL and IMUL Instructions MUL operand (unsigned product) IMUL operand (signed product)

accumulator = accumulator * operand

MUL BL AX = AL * BL

MUL CX <DX>:<AX> = AX * CX

MUL EBX <EDX>:<EAX> = EAX * EBX

Page 11: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

MUL and IMUL Instructions MUL BYTE PTR TEMP

AX = AL * TEMP MUL WORD PTR [DI]

<DX>:<AX> = AX * [DI] MUL DWORD PTR [EBX]

<EDX>:<EAX> = EAX * [EBX]

Page 12: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Special Immediate 16 bit Product IMUL reg,imm IMUL reg,reg,imm IMUL reg,mem,imm

IMUL CX,16 CX = CX * 16

IMUL DX,DATA,2 DX = DATA * 2

Page 13: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

DIV and IDIV Instructions DIV operand (unsigned division) IDIV operand (signed division) DIV BL

AL (quotient) = AX / BL AH (remainder) = AX / BL

DIV CX AX (quotient) = <DX>:<AX> / CX DX (remainder) = <DX>:<AX> / CX

Page 14: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

DIV and IDIV Instructions DIV EBX

EAX (quotient) = <EDX>:<EAX> / EBX EDX (remainder) = <EDX>:<EAX> / EBX

DIV BYTE PTR TEMP DIV WORD PTR [DI] DIV DWORD PTR [EBX]

Page 15: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

BCD Arithmetic Instructions that use packed BCD

operands. DAA - Decimal adjust after addition. DAS - Decimal adjust after subtraction.

MOV BL,14H MOV AL,47H ADD AL,BL DAA

Page 16: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

ASCII Arithmetic Instructions that use unpacked BCD operands. AAM – Adjust after multiplication.

MOV AL,5 MOV BL,8 MUL BL AAM

AAD – Adjust before division. MOV AL,12 MOV BL,3 AAD DIV BL

Page 17: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

ASCII Arithmetic Instructions that use ASCII operands. AAA – Adjust after addition. AAS – Adjust after subtraction.

MOX AX,31H ADD AL,39H AAA ADD AX,3030H

Page 18: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

AND Instruction

AND destination,source destination = destination ∙ source

AND AX,BX AND SUM,EAX AND EDX,ARRAY[EBX][ESI] AND CL,5 AND DL,[BX]

Page 19: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

OR Instruction

OR destination,source destination = destination + source

OR AX,BX OR SUM,EAX OR EDX,ARRAY[EBX][ESI] OR CL,5 OR DL,[BX]

Page 20: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

XOR Instruction

XOR destination,source destination = destination source⊕

XOR AX,BX XOR SUM,EAX XOR EDX,ARRAY[EBX][ESI] XOR CL,5 XOR DL,[BX]

Page 21: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

NOT and NEG Instructions NOT operand – 1’s complement NEG operand – 2’s complement

operand = operand’

NOT BX NEG SUM NOT ECX NEG CL

Page 22: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

TEST Instruction TEST operand1, operand2

operand1 ∙ operand2 Flags are updated and the result is discarded.

TEST AX,BX TEST SUM,EAX TEST CL,5 TEST DL,[BX]

Page 23: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Shift Instructions These instructions

perform the logical and arithmetic shifts.

SHL destination,count SAL destination,count SHR destination,count SAR destination,count

Count can be an immediate value or the CX register. SHL AX,CX SAR DL,1

Page 24: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Rotate Instructions These instructions

perform the logical and arithmetic shifts.

RCL destination,count ROL destination,count RCR destination,count ROR destination,count

Count can be an immediate value or the CX register. ROL EDX,16 RCR BH,CL

Page 25: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Conditional Transfers These 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 SUM SUB EAX,EBX . . SUM:

Page 26: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Conditional Transfers Used with unsigned integers

JA/JNBE – Jump if above – Z=0 and C=0 JAE/JNB – Jump if above or equal – C=0 JB/JNA – Jump if below – C=1 JBE/JNA – Jump if below or equal – Z=1 and C=1

CMP AL,BL JA NEXT MOV CL,0 . . NEXT:

Page 27: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Conditional Transfers Used with signed integers

JG/JNLE – Jump if greater – Z=0 and S=0 JGE/JNL – Jump if greater or equal – S=0 JL/JNGE – Jump if less – S<>0 JLE/JNG – Jump if less or equal – Z=1 and S<>0

CMP AL,BL JLE NEXT MOV CL,0 . . NEXT:

Page 28: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Conditional Transfers Other conditions

JE/JZ – Jump if equal – Z=1 JNE/JNZ – Jump if not equal – Z=0 JC – Jump if carry - C=1 JNC – Jump if not carry – C=0 JS – Jump if sign – S=1 JNS – Jump if not sign – S=0 JO – Jump if overflow – O=1 JNO – Jump if not overflow – O=0

Page 29: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Conditional Transfers JP/JPE – Jump if parity/parity even – P=1 JNP/JPO – Jump if not parity/parity odd – P=0 JCXZ – Jump if CX is zero JECXZ – Jump if ECX is zero

Page 30: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

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

Page 31: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Conditional Set Used with unsigned integers

SETA – Set if above – Z=0 and C=0 SETAE – Set if above or equal – C=0 SETB – Set if below – C=1 SETBE – Set if below or equal – Z=1 and C=1

Used with signed integers SETG – Set if greater – Z=0 and S=0 SETGE – Set if greater or equal – S=0 SETL – Set if less – S<>0 SETLE – Set if less or equal – Z=1 and S<>0

Page 32: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Conditional Set Other conditions

SETE/SETZ – Set if equal – Z=1 SETNE/SETNZ – Set if not equal – Z=0 SETC – Set if carry - C=1 SETNC – Set if not carry – C=0 SETS – Set if sign – S=1 SETNS – Set if not sign – S=0 SETO – Set if overflow – O=1 SETNO – Set if not overflow – O=0

Page 33: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Conditional Set SETP/JPE – Set if parity/parity even – P=1 SETNP/SETPO – Set if not parity/parity odd – P=0

Page 34: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

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.

Page 35: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Controlling the Flow of the Program Using Dot Commands Commands:

.IF, .ELSE, .ELSEIF, and .ENDIF .WHILE, .BREAK, .CONTINUE and .ENDW .REPEAT, .UNTIL, and .UNTILCXZ

Page 36: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

.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

Page 37: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

.IF, .ELSE, .ELSEIF, and .ENDIF INC BL .IF BL >= 205 || BL<= 2 ADD BL,CL .ENDIF MOV DX,1

INC BL .IF BL >= 205 || BL<= 2 CMP BL,205 JAE @C001 CMP BL,2 JA @C002 @C001: ADD BL,CL .ENDIF @C002: MOV DX,1

Page 38: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

.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.

Page 39: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

.WHILE, .BREAK, .CONTINUE and .ENDW .WHILE BL >= 1 MOV BL, DATA[SI] MOV COPY[SI],BL INC SI .ENDW MOV AX,DX

.WHILE BL >= 1 JMP @C001 @C002: MOV BL, DATA[SI] MOV COPY[SI],BL INC SI .ENDW @C001: CMP BL,1 JAE @C002 MOV AX,DX

Page 40: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

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.

Page 41: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Procedures Format

Name PROC [NEAR or FAR] Subroutine code RET

ENDP

Global procedures are defined as FAR. Local procedures are defined as NEAR.

Page 42: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Procedures CALL destination

Calls a subroutine at location destination. Different addressing modes may be used for

destination. CALL DELAY CALL EBX CALL ARRAY[BX]

RET Returns execution of program to location

stored in stack. NEAR or FAR is dependent on procedure

definition.

Page 43: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Interrupts INT type INTO – Interrupt if overflow IRET These 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.

Page 44: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

Miscellaneous Control Instructions WAIT – 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.

Page 45: ADD Instruction ADD destination,source  destination = destination + source ADD AX,BX ADD SUM,EAX ADD EDX,ARRAY[EBX][ESI] ADD CL,5 ADD DL,[BX]

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.


Recommended