logical instructions Flashcards
(20 cards)
What are the three categories of 8086 bit manipulation instructions?
“1. Logical Instructions: AND, OR, XOR, NOT, NEG, TEST. 2. Shift Instructions: SHL, SHR, SAL, SAR. 3. Rotate Instructions: ROL, RCL, ROR, RCR.”
How does AND
modify bits?
“AND destination, source: Clears specific bits using a mask (0s clear, 1s preserve). Example: AND BL, 0FH
clears upper nibble of BL. Flags: CF=0, OF=0; ZF/SF reflect result.”
What is the purpose of OR
?
“OR destination, source: Sets specific bits using a mask (1s set, 0s preserve). Example: OR AL, 80H
sets the MSB of AL. Flags: CF=0, OF=0; ZF=1 if result is zero.”
How does XOR
work?
“XOR destination, source: Toggles bits where the mask is 1. Example: XOR AL, 04H
toggles bit 2 of AL. Also used to clear registers: XOR AX, AX
zeros AX. Flags: CF=0, OF=0.”
What is the effect of NOT
?
“NOT destination: Inverts all bits (1’s complement). Example: NOT AL
changes 55H to AAH. Does not affect flags.”
How does NEG
work?
“NEG destination: Computes 2’s complement (subtracts operand from 0). Example: NEG AX
turns 5 into -5. Flags: CF=1 if result ≠ 0, OF=1 for overflow (e.g., NEG 8000H
→ OF=1).”
What does TEST
do?
“TEST destination, source: Performs AND without altering operands. Sets flags to test bits. Example: TEST AL, 1
→ ZF=1 if AL is even. Flags: CF=0, OF=0; ZF/SF reflect result.”
What is the difference between SHL
and SAL
?
“SHL/SAL: Both shift left. SHL for unsigned, SAL for signed (identical operation). Example: SHL AL, 1
doubles AL. Flags: CF=last bit shifted out; OF=1 if sign changes.”
How does SHR
differ from SAR
?
“SHR: Fills MSB with 0 (unsigned). SAR: Fills MSB with sign bit (signed). Example: SAR AL, 1
halves -15 (F1H) → -8 (F8H). Flags: CF=last bit shifted out.”
What happens in ROL
vs. RCL
?
“ROL: Rotates left; MSB → LSB and CF. RCL: Rotates left through CF; MSB → CF, CF → LSB. Example: ROL AH, 1
shifts AH left with wrap-around.”
What is the result of ROR BH, 2
if BH=88H?
“BH=22H. ROR: Rotates right; LSB → MSB and CF. Example: ROR 88H (10001000b)
twice → 00100010b (22H). CF=1 after first shift.”
How to reverse bits in AL using shifts?
“Use SHL AL,1
and RCR BL,1
in a loop:
1. MOV CX,8
2. Shift AL left → CF
3. Rotate CF into BL right
4. Loop until CX=0. Result in BL.”
What flags are affected by logical instructions?
“CF=0, OF=0. SF/ZF/PF reflect result. Example: AND BL, 0FH
→ ZF=1 if lower nibble is 0.”
How to convert lowercase to uppercase with AND
?
“Clear bit 5: AND DL, 0DFH
. Example: ‘a’ (61H) → ‘A’ (41H). Mask: 11011111b.”
What happens in NEG AX
if AX=8000H?
“Result: AX=8000H (no change). Flags: OF=1 (overflow), CF=1, SF=1. 8000H is its own 2’s complement in 16-bit.”
How to test if AL is even?
“Use TEST AL, 1
. If ZF=1, AL is even. Example: TEST AL, 1
→ ZF=1 if bit 0 is 0.”
What is the result of SAR AL, 3
if AL=9AH?
“AL=EDH (11101101b). SAR preserves sign: 9AH (-102) → shifted right 3 times → -13 (EDH).”
How does RCR
differ from ROR
?
“RCR: Rotates right through CF. LSB → CF, CF → MSB. Example: RCR AH,1
→ CF becomes new MSB. Used for multi-byte rotations.”
What is the effect of SHL AL, CL
if CL=3 and AL=8AH?
“AL=50H (01010000b). CF=1 (last shifted bit). Example: SHL 8AH (10001010b) 3 times
→ 01010000b.”
How to count 1s in BX using ROL
?
-
XOR AL,AL
(counter). -
ROL BX,1
→ CF=1 if bit was 1. -
JNC NEXT
; elseINC AL
. - Loop 16 times. Result in AL.