4.2 Arithmetic Instructions Addition instructions: ADD, ADC, INC ,AAA, DAA ADD, ADC INC CF 0 Initial AL: 0110 1001+ AF1 Initial BL: 0100 1000 Because: 1011>1001 AF=1 AL after ADD: 1011 0001 + AAA,DAA DAA: 0110 0110 CF 1 AL after DAA: 0001 0111 AF1 Example: BCD addition: ADD AL, BL AL after clear: 0000 0000+ CF 0 supposing: BH=29H BL=48H AL=69H DAA Initial BH: 0010 1001 AF 0 MOV BL, AL Carry Flag: 1 MOV AL, 0 Because: CF=0,0010<1001 1010>1001 2948+ 69 + ADC AL, BH AL after ADC: 0010 1010 DAA DAA: 0000 0110 3017 MOV BH, AL AL after DAA: 0011 0000
4.2 Arithmetic Instructions Subtraction instructions: SUB, SBB, DEC, NEG, AAS, DAS SUB, SBB, CMP SF 1 DEC, NEG CF 1 Initial AL: 0100 1000- AF1 Initial BL: 0110 1001 Because: CF,1101>1001 AF,1111>1001 AL after SUB: 1101 1111 - AAS,DAS DAS: 0110 0110 CF 1 AL after DAS: 0111 1001 AF 1 Example: BCD addition: SUB AL, BL AL after update: 0010 1001- CF 0 supposing: AH=29H AL=48H BL=69H DAS Subtractor: 0000 0000 AF 0 MOV BL, AL Carry Flag: 1 MOV AL, AH Because: CF=0,0010<1001 AF=0,1000<1001 2948- 69 - SBB AL, 0 AL after SBB: 0010 1000 DAS DAS: 0000 0000 2879 MOV BH, AL AL after DAS: 0010 1000
4.2 Arithmetic Instructions Multiplication instructions: MUL, IMUL, AAM MUL, IMUL IMUL additional, 2 operands Examples: signed and unsigned multiplication: AAM supposing: AL = FFH = -1(2’sC) CL = FEH = -2(2’sC) IMUL additional, 3 operands MUL CL IMUL CL AXFD02H AX0002H
4.2 Arithmetic Instructions Division and conversion instructions: DIV, IDIV, AAD, CBW, CWD DIV, IDIV CBW AAD CWD CWD CWDE Examples: multiplying AL by CX (signed values): supposing: AL = FFH = -1(2’sC) CX = FFFEH = -2(2’sC) CBW Convert byte FFH to word FFFFH in AX IMUL CX Multiplying words AX and CX
4.3 Logical Instructions AND, OR, XOR, TEST, NOT BSF, BSR Examples: difference between AND and TEST: AND, OR, XOR, TEST NOT supposing: AL = 25H = 0010 0101B CL = 55H = 0101 0101B AND AL,CL TEST AL,CL AL05H=0000 0101B SF0; ZF0; PF1; AL25H=0010 0101B SF0; ZF0; PF1; BSF, BSR supposing: EAX = 0000 0000 0111 1111 0000 0000 0000 0000B BSF, BSR BSF EBX, EAX BSR EBX, EAX EBX 10H EBX 16H
4.3 Logical Instructions BT, BTC, BTS, BTR BT, BTC, BTS, BTR Example: MOV AX,5555H ;AX=5555,CF=0 BT AX,10 ;AX=5555,CF=1 BT AX,11 ;AX=5555,CF=0 MOV BX,10 BTC AX,BX ;AX=5155,CF=1 INC BX BTS AX,BX ;AX=5955,CF=0 BTR AX,0 ;AX=5554,CF=1
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.