 # Flag Control instructions CLC clear carry flag CF = 0 STC set carry flag CF= 1 CMC complement carry flag [CF] CF.

## Presentation on theme: "Flag Control instructions CLC clear carry flag CF = 0 STC set carry flag CF= 1 CMC complement carry flag [CF] CF."— Presentation transcript:

Flag Control instructions CLC clear carry flag CF = 0 STC set carry flag CF= 1 CMC complement carry flag [CF] CF

ADD action Add ADD D,S [S] + [D]] [D] [carry] [CF] flags affected: OF, SF, ZF, AF, PF, CF ADC action Add with carry ADC D,S [S] + [D] + [CF] [D] [carry] [CF] flags affected: OF, SF, ZF, AF, PF, CF Destination Source Register Register Register Memory Memory Register Register Immediate Memory Immediate Accumulator Immediate

DH

Format INC DAction[D+1] → [D] D R 16 R 8 M not in the debugger environment ! Flags affected SF, ZF,AF,PF

Only 1 binary coded decimal digit is placed in 1 byte 2 binary coded decimal digits are packed in 1 byte Packed BCD 56 10 0101 0110 Unpacked BCD 56 10 0000 0101 00000110

Assume that AL contains 32 H which is the ASCII code for 2 10 and BL contains 34 H which is the ASCII code for 4 10 and AH has been cleared. What is the result of executing the following instructions? ADD AL, BL AAA AAA = ASCII adjust after addition 00110110 36 Note that the CF and AF remain cleared AX = 66 AX = 6 machine code Assume that AL contains 35 H which is the ASCII code for 5 10 and BL contains 37 H which is the ASCII code for 7 10 and AH has been cleared. What is the result of executing the following instructions? ADD AL, BL AAA AX = 6C AX = 01 02 Note that CF and AF are set (Unpacked BCD)

Repeat assuming that AL contains 06 H and BL contains 04 H and AH has been cleared. What is the result of executing the following instructions? ADD AL, BL DAA DAA = decimal adjust after addition 00100111 27 Assume that AL contains 08 H and BL contains 04 H and AH has been cleared. What is the result of executing the following instructions? ADD AL, BL DAA 0C 0012 (packed BCD) 0A 0010 (packed BCD)

SUB register/memory with register to either 001010DW 00101011 00000101 2B05 SUB AX, [DI] MOV register/memory to/from register 100010DWmod reg r/mDispl-lo 1000100100000100 8904 Displ-hi MOV [SI], AX mod reg r/mDispl-loDispl-hi

MOV immediate to register 1011W regDataData if W=1 10111110 00000000 BE00 MOV SI, 200H MOV DI, 100H MOV register/memory to/from register 100010DWmod reg r/mDispl-lo 1000101100000100 8B04 Displ-hi 00000010 02 10111111 0000000000000001 BF 0001 MOV AX,[SI] MOV AX, [DI]1000101100000101 8B05

INC register 01000 reg INC SI 01000110 46 INC DI 01000111 47 SBB register/memory and register to either 000110DWmod reg r/mDispl-lo 0001101100000101 1B05 Displ-hi SBB AX,[DI]

MOV DS,AX MOV AX, 1000

BE 00 02 BF 00 01 8B 04 2B 05 89 04 46 8B 04 47 1B 05 89 04 EDS:200 78 56 34 12 EDS:100 89 67 45 23 DDS:200 EF EE EE EE Mov si,0200 Mov di,0100 Mov ax,[si] Sub ax,[di] Mov [si],ax Inc si Mov ax,[si] Inc di Sbb ax,[di] Mov [si],ax

Negate instruction : MOV AX,0060 NEG AX 0000 0000 0110 0000 1111 1111 1010 00002’complement F F A 0

B328 B083 001010DW Subtract m/reg and reg to either Mod reg r/mDisp-loDisp-hi 00101010 11000011 2AC3 DAS decimal adjust after subtraction 00101111 2F

B83800 Subtract immediate from accumulator 0010110Wdatadata if W=1 2C39 AAS ASCII adjust for subtraction 00111111 3F

If AL=-1 and CL=-2 MUL CL If AL=-1 and CL=-2 IMUL CL AL=FF CL= FE Unsigned multiplication Result AX= FD02 Result AX= 2 Signed multiplication CF is set because there is a carry from the LSByte VF is set because the result cannot fit in 1 Byte

MOV BX,0009 MOV AX,0007 MUL BL AAM BCD Arithmetics AX=003F MOV AX, 0603 AAD AX=003F

Signed COMPARE example MOV AX, 99 AX=1001 1001 (-103 10 ) MOV BX, 1B BX=0001 1011 (+27 10 ) CMP AX, BX 2’scomplement [1001 1001] = 0110 0111 2 = 67 16 = - 103 10 1B 16 = 27 10 -103 – 27 = -130 10 = 2’s complement [ 28 16 ] = 2’s complement [ 0010 1000] = 1101 1000 2 = D8 16 1001 1001 - 0001 1011 0111 1110 AF=1 CF=0 OF=0

Download ppt "Flag Control instructions CLC clear carry flag CF = 0 STC set carry flag CF= 1 CMC complement carry flag [CF] CF."

Similar presentations