4 2 Arithmetic Instructions Addition instructions ADD ADC

  • Slides: 7
Download presentation
4. 2 Arithmetic Instructions Addition instructions: ADD, ADC, INC , AAA, DAA ADD, ADC

4. 2 Arithmetic Instructions Addition instructions: ADD, ADC, INC , AAA, DAA ADD, ADC INC AAA, DAA Example: BCD addition: 2948+ 69 3017 ADD supposing: DAA MOV BH=29 H MOV BL=48 H ADC AL=69 H DAA MOV AL, BL BL, AL AL, 0 AL, BH BH, AL Initial AL: Initial BL: AL after ADD: 0110 0100 1011 DAA: AL after DAA: 0110 0001 AL after clear: Initial BH: Carry Flag: AL after ADC: DAA: AL after DAA: 0000 0010 0000 0011 CF 0 AF 1 1001+ 1000 Because: 0001 + 1011>1001 AF=1 0110 0111 CF 1 AF 1 0000+ CF 0 1001 AF 0 1 Because: 1010 + CF=0, 0010<1001 0110 0000 1010>1001

4. 2 Arithmetic Instructions Subtraction instructions: SUB, SBB, DEC, NEG, AAS, DAS SUB, SBB,

4. 2 Arithmetic Instructions Subtraction instructions: SUB, SBB, DEC, NEG, AAS, DAS SUB, SBB, CMP DEC, NEG AAS, DAS Example: BCD addition: 294869 2879 SUB supposing: DAS AH=29 H MOV AL=48 H SBB BL=69 H DAS MOV AL, BL BL, AL AL, AH AL, 0 BH, AL Initial AL: Initial BL: AL after SUB: 0100 0110 1101 DAS: AL after DAS: 0110 0111 AL after update: Subtractor: Carry Flag: AL after SBB: DAS: AL after DAS: 0010 0000 0010 SF 1 CF 1 AF 1 10001001 Because: 1111 - CF, 1101>1001 0110 AF, 1111>1001 CF 1 AF 1 1001 CF 0 0000 AF 0 1 Because: 1000 CF=0, 0010<1001 0000 1000 AF=0, 1000<1001

4. 2 Arithmetic Instructions Multiplication instructions: MUL, IMUL, AAM MUL, IMUL additional, 2 operands

4. 2 Arithmetic Instructions Multiplication instructions: MUL, IMUL, AAM MUL, IMUL additional, 2 operands Examples: signed and unsigned multiplication: AAM supposing: AL = FFH = -1(2’s. C) CL = FEH = -2(2’s. C) IMUL additional, 3 operands MUL CL AX FD 02 H IMUL CL AX 0002 H

4. 2 Arithmetic Instructions Division and conversion instructions: DIV, IDIV, AAD, CBW, CWD DIV,

4. 2 Arithmetic Instructions Division and conversion instructions: DIV, IDIV, AAD, CBW, CWD DIV, IDIV CBW CWD AAD CWDE Examples: multiplying AL by CX (signed values): supposing: CBW AL = FFH = -1(2’s. C) CX = FFFEH = -2(2’s. C) IMUL Convert byte FFH to word FFFFH in AX CX Multiplying words AX and CX

4. 3 Logical Instructions AND, OR, XOR, TEST, NOT AND, OR, XOR, TEST NOT

4. 3 Logical Instructions AND, OR, XOR, TEST, NOT AND, OR, XOR, TEST NOT Examples: difference between AND and TEST: AND AL, CL AL 05 H=0000 0101 B SF 0; ZF 0; PF 1; supposing: AL = 25 H = 0010 0101 B CL = 55 H = 0101 B TEST AL, CL AL 25 H=0010 0101 B SF 0; ZF 0; PF 1; BSF, BSR supposing: EAX = 0000 0111 1111 0000 B BSF EBX, EAX BSR EBX, EAX EBX 10 H EBX 16 H

4. 3 Logical Instructions BT, BTC, BTS, BTR Example: MOV AX, 5555 H BT

4. 3 Logical Instructions BT, BTC, BTS, BTR Example: MOV AX, 5555 H BT AX, 10 BT AX, 11 MOV BX, 10 BTC AX, BX INC BX BTS AX, BX BTR AX, 0 ; AX=5555, CF=1 ; AX=5555, CF=0 ; AX=5155, CF=1 ; AX=5955, CF=0 ; AX=5554, CF=1

4. 3 Logical Instructions SETcc The terms “less” and “greater” are used for comparisons

4. 3 Logical Instructions SETcc The terms “less” and “greater” are used for comparisons of signed integers. The terms “above” and “below” are used for comparisons of unsigned integers.