Arithmetic/Logic Instructions: Basic Mathematical Operations
Arithmetic/Logic Instructions: Basic Mathematical Operations
• Logic Instructions
– Bit Level
– Word Level
– Computes Results AND Modifies Flags
1
Addition Instruction Types
add ax, bx ;ax<-ax+bx and set flags
adc ax, bx ;ax<-ax+bx+CF(lsb) and set flags
inc ax ;ax<-ax+1 and set flags
aaa ;ASCII Adjust after Addition
daa ;Decimal (BCD) Adjust after Addition
Increment Examples
00ffh → 0000h
00ffh → 0100h
2
Add with Carry
BX 1 1 AX
DX 0 1 CX
CF=1
CF BX AX
• “Corrects” Result
0110 6
+0111 7
1101 13→should be 0001 0011
3
Decimal Adjust after Addition Example
31 ‘1’
+39 ‘9’
6a ‘10’→should be 3130h
4
Subtraction Instruction Types
Gen Reg
+
Gen Reg Mem Loc
-
Immediate
Destination Source
Gen Reg
+
Mem Loc
-
Immediate
5
Subtract with Borrow, sbb
CF
BX AX
SI DI
CF BX AX
Multiplication
• 8086/8088 One of First to Include mul/div Instruction
6
Multiply Instructions
• Product can be Twice the Size
2 × 3 = 6(same size)
2 × 8 = 16 (double size, EXT)
•OF=CF=0 means product is same size as result (faster)
•OF=CF=1 means EXT product size (slower)
•AF, PF, ZF, SF Contents Unpredictable
7
Division
• 8, 16, 32 bit Operands (32 bit is 386+)
• No Immediate Addressing Mode
• No Flag Bits Change Predictably
• Can Cause Two Types of Error:
1) Divide by 0 (Mathematically Undefined)
2) Divide Overflow (Wordlength Problem)
• Operands: Divisor is Programmer Specified
• Dividend is Implied
• Quotient, Remainder Implied
Size Dividend Quotient Remainder
8 bits ax al ah
16 bits dx:ax ax dx
32 bits edx:eax eax edx