Upload
coleen-byrd
View
247
Download
0
Tags:
Embed Size (px)
Citation preview
Flag Control instructions
CLC clear carry flag CF = 0STC set carry flag CF= 1CMC 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 D Action [D+1] → [D]
DR16
R8
M not in the debugger environment !
Flags affectedSF, ZF ,AF ,PF
ADD immediate to
accumulator0000010W Data Data if W=1
00000100 00100101
04 25
ADD AL,25H
ADD AL, BL
ADD Reg/Mem with Reg
000000DW mod reg r/m Displ-lo
00000010 11000011
02 C3
Displ-hi
00000000 1101100000 D8
Only 1 binary coded decimal digit is placed in 1 byte
2 binary coded decimal digits are packed in 1 byte
Packed BCD
5610 0101 0110
Unpacked BCD
5610 0000 0101 00000110
Assume that AL contains 32H which is the ASCII code for 210 and BL contains 34H which is the ASCII code for 410 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 35H which is the ASCII code for 510 and BL contains 37H which is the ASCII code for 710 and AH has been cleared.
What is the result of executing the following instructions?
ADD AL, BL
AAA
AX = 6C
AX = 01 02Note that CF and AF are set
(Unpacked BCD)
Repeat assuming that AL contains 06H and BL contains 04H 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 08H and BL contains 04H and AH has been cleared.
What is the result of executing the following instructions?
ADD AL, BL
DAA
0C0012 (packed BCD)
0A
0010 (packed BCD)
SUB register/memory with register to either
001010DW
00101011 00000101
2B 05
SUB AX, [DI]
MOV register/memory to/from register
100010DW mod reg r/m Displ-lo
10001001 00000100
89 04
Displ-hi
MOV [SI], AX
mod reg r/m Displ-lo Displ-hi
MOV immediate to
register1011W reg Data Data if W=1
10111110 00000000
BE 00
MOV SI, 200H
MOV DI, 100H
MOV register/memory to/from register
100010DW mod reg r/m Displ-lo
10001011 00000100
8B 04
Displ-hi
00000010
02
10111111 00000000 00000001
BF 00 01
MOV AX,[SI]
MOV AX, [DI] 10001011 000001018B 05
INC register 01000 reg
INC SI
01000110
46
INC DI
01000111
47
SBB register/memory and register to either
000110DW mod reg r/m Displ-lo
00011011 00000101
1B 05
Displ-hi
SBB AX,[DI]
MOV DS,AXMOV AX, 1000
BE 00 02
BF 00 01
8B 04
2B 05
89 04
46
46
8B 04
47
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
Inc si
Mov ax,[si]
Inc di
Inc di
Sbb ax,[di]
Mov [si],ax
Negate instruction:
MOV AX,0060
NEG AX
0000 0000 0110 0000
1111 1111 1010 0000 2’complement
F F A 0
B328 B083
001010DWSubtract m/reg and reg to either Mod reg r/m Disp-lo Disp-hi
00101010 11000011
2A C3
DAS decimal adjust after subtraction 00101111
2F
B83800
Subtract immediate from accumulator
0010110W data data if W=1
2C 39
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 LSByteVF is set because the result cannot fit in 1 Byte
MOV BX,0009MOV AX,0007MUL BLAAM
BCD Arithmetics
AX=003F
MOV AX, 0603AAD AX=003F
Signed COMPARE example
MOV AX, 99 AX=1001 1001 (-10310)MOV BX, 1B BX=0001 1011 (+2710)CMP AX, BX 2’scomplement [1001 1001] = 0110 01112 = 6716 = - 10310
1B16 = 2710
-103 – 27 = -13010 = 2’s complement [ 2816] = 2’s complement [ 0010 1000] = 1101 10002 = D816 1001 1001 - 0001 1011 0111 1110 AF=1 CF=0 OF=0