logical instructions Flashcards

(20 cards)

1
Q

What are the three categories of 8086 bit manipulation instructions?

A

“1. Logical Instructions: AND, OR, XOR, NOT, NEG, TEST. 2. Shift Instructions: SHL, SHR, SAL, SAR. 3. Rotate Instructions: ROL, RCL, ROR, RCR.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does AND modify bits?

A

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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the purpose of OR?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does XOR work?

A

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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the effect of NOT?

A

NOT destination: Inverts all bits (1’s complement). Example: NOT AL changes 55H to AAH. Does not affect flags.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does NEG work?

A

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).”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does TEST do?

A

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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between SHL and SAL?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does SHR differ from SAR?

A

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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens in ROL vs. RCL?

A

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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the result of ROR BH, 2 if BH=88H?

A

“BH=22H. ROR: Rotates right; LSB → MSB and CF. Example: ROR 88H (10001000b) twice → 00100010b (22H). CF=1 after first shift.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to reverse bits in AL using shifts?

A

“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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What flags are affected by logical instructions?

A

“CF=0, OF=0. SF/ZF/PF reflect result. Example: AND BL, 0FH → ZF=1 if lower nibble is 0.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to convert lowercase to uppercase with AND?

A

“Clear bit 5: AND DL, 0DFH. Example: ‘a’ (61H) → ‘A’ (41H). Mask: 11011111b.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What happens in NEG AX if AX=8000H?

A

“Result: AX=8000H (no change). Flags: OF=1 (overflow), CF=1, SF=1. 8000H is its own 2’s complement in 16-bit.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to test if AL is even?

A

“Use TEST AL, 1. If ZF=1, AL is even. Example: TEST AL, 1 → ZF=1 if bit 0 is 0.”

17
Q

What is the result of SAR AL, 3 if AL=9AH?

A

“AL=EDH (11101101b). SAR preserves sign: 9AH (-102) → shifted right 3 times → -13 (EDH).”

18
Q

How does RCR differ from ROR?

A

RCR: Rotates right through CF. LSB → CF, CF → MSB. Example: RCR AH,1 → CF becomes new MSB. Used for multi-byte rotations.”

19
Q

What is the effect of SHL AL, CL if CL=3 and AL=8AH?

A

“AL=50H (01010000b). CF=1 (last shifted bit). Example: SHL 8AH (10001010b) 3 times → 01010000b.”

20
Q

How to count 1s in BX using ROL?

A
  1. XOR AL,AL (counter).
  2. ROL BX,1 → CF=1 if bit was 1.
  3. JNC NEXT; else INC AL.
  4. Loop 16 times. Result in AL.