Arithmetic Instructions Flashcards
(20 cards)
What are the key arithmetic instruction categories in 8086?
“1. Addition: ADD, ADC. 2. Subtraction: SUB, SBB. 3. Increment/Decrement: INC, DEC. 4. Multiplication: MUL, IMUL. 5. Division: DIV, IDIV. 6. Convert: CBW, CWD.”
What is the difference between ADD
and ADC
?
“ADD: Adds two operands. ADC: Adds two operands + carry flag (CF). Example: ADC AX, BX
→ AX = AX + BX + CF
. Used for multi-byte addition.”
How does SUB
work in 8086?
“SUB destination, source: Subtracts source from destination using 2’s complement. Example: SUB AL, BH
→ AL = AL - BH
. Affects all flags (CF, ZF, SF, etc.).”
What is the purpose of SBB
?
“Subtract with Borrow: SBB destination, source
→ destination = destination - source - CF
. Used for multi-byte subtraction. Example: SBB BX, CX
.”
How do INC
and DEC
affect flags?
“INC/DEC modify all flags except CF. Example: INC CX
increments CX by 1; DEC [SI]
decrements memory at SI by 1.”
What does CMP
do?
“Compare: Subtracts source from destination and updates flags without storing the result. Example: CMP AX, 18
→ Flags indicate if AX >, <, or = 18.”
How is MUL
different from IMUL
?
“MUL: Unsigned multiplication. IMUL: Signed multiplication. Example: MUL BL
(AL * BL → AX). IMUL BX
(AX * BX → DX:AX).”
What happens during MUL BL
?
“AL (8-bit) * BL (8-bit) → 16-bit result in AX. CF/OF = 1 if upper half (AH) ≠ 0. Example: MUL BL
→ AX = AL * BL.”
How does DIV
handle division?
“DIV divisor: Unsigned division. Byte form: AX / divisor → AL (quotient), AH (remainder). Word form: (DX:AX) / divisor → AX (quotient), DX (remainder). Example: DIV BL
divides AX by BL.”
What is a divide overflow?
“Occurs when the quotient exceeds the capacity of AL/AX. Example: Dividing FFFFH by 1 → quotient FFFFH > AX capacity → program terminates with ‘Divide Overflow’.”
What do CBW
and CWD
do?
“CBW: Converts byte (AL) to word (AX) by sign extension. CWD: Converts word (AX) to double word (DX:AX). Example: CBW
extends AL (80h) to AX (FF80h).”
How do flags behave for MUL
vs. IMUL
?
“MUL: CF/OF = 1 if upper half ≠ 0. IMUL: CF/OF = 1 if upper half ≠ sign extension. Example: IMUL BX
(signed) sets CF/OF based on sign consistency.”
What happens in IDIV BX
with DX:AX = FFFFFFFBh?
“Signed division: FFFFFFFBh (-5) ÷ BX (2) → AX = -2 (FFFEh), DX = -1 (FFFFh). CF/OF = 0 if result fits.”
What is the syntax for MOV AL, 80H
followed by CBW
?
“CBW
converts AL (80h) to AX (FF80h) for signed operations. Example: Prepares AL for division by sign-extending to AX.”
How to evaluate z = x + (y + n)/M
in assembly?
“For unsigned numbers:
1. MOV AL, Y
2. MUL N
3. DIV M
4. ADD AX, X
5. MOV Z, AX
For signed, use CBW
, IMUL
, IDIV
.”
What are the flag results after INC AL
(AL = FFh)?
“AL becomes 00h. Flags: ZF = 1 (result zero), SF = 0 (positive), CF unchanged (remains 0).”
How does IMUL
handle AX=1 and BX=FFFFh?
“IMUL BX: Treats BX as -1 (signed). Result: AX = -1 (FFFFh), DX = FFFFh (sign extension). CF/OF = 0.”
What is the result of DIV BH
if AX=0005h and BH=FFh?
“DIV BH: AL = 00h (quotient 0), AH = 05h (remainder 5). IDIV BH: AL = FBh (-5), AH = 00h (remainder 0).”
Why use CLC
before ADC
?
“Clears CF to avoid unintended carry from previous operations. Example: CLC
→ ADC CX, [BX]
adds CX, [BX], and CF=0.”
What is the purpose of ORG 0010h
?
Origin directive: Sets the next data/code offset to 0010h. Example: ORG 0010h
→ DATA4 starts at 0010h.