70 likes | 278 Views
4.2 Arithmetic Instructions. ADD, ADC. INC. AAA,DAA. Addition instructions: ADD, ADC, INC ,AAA, DAA. CF 0. AF 1. Initial AL: 0110 1001+. Initial BL: 0100 1000. Because: 1011>1001 AF=1. +. AL after ADD: 1011 0001. DAA: 0110 0110. CF 1. AL after DAA: 0001 0111. AF 1.
E N D
4.2 Arithmetic Instructions ADD, ADC INC AAA,DAA Addition instructions: ADD, ADC, INC ,AAA, DAA CF 0 AF1 Initial AL: 0110 1001+ Initial BL: 0100 1000 Because: 1011>1001 AF=1 + AL after ADD: 1011 0001 DAA: 0110 0110 CF 1 AL after DAA: 0001 0111 AF1 ADD AL, BL AL after clear: 0000 0000+ Example: BCD addition: CF 0 DAA supposing: BH=29H BL=48H AL=69H Initial BH: 0010 1001 AF 0 MOV BL, AL Carry Flag: 1 MOV AL, 0 Because: CF=0,0010<1001 1010>1001 + 2948+ 69 AL after ADC: 0010 1010 ADC AL, BH DAA: 0000 0110 DAA AL after DAA: 0011 0000 3017 MOV BH, AL
4.2 Arithmetic Instructions SUB, SBB, CMP DEC, NEG AAS,DAS Subtraction instructions: SUB, SBB, DEC, NEG, AAS, DAS SF 1 CF 1 AF1 Initial AL: 0100 1000- Initial BL: 0110 1001 Because: CF,1101>1001 AF,1111>1001 - AL after SUB: 1101 1111 DAS: 0110 0110 CF 1 AL after DAS: 0111 1001 AF 1 SUB AL, BL AL after update: 0010 1001- Example: BCD addition: CF 0 DAS supposing: AH=29H AL=48H BL=69H 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 AL after SBB: 0010 1000 SBB AL, 0 DAS: 0000 0000 DAS AL after DAS: 0010 1000 2879 MOV BH, AL
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 AND, OR, XOR, TEST, NOT Examples: difference between AND and TEST: 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.