How does the TEST command work?
It is clear that this is boolean and . Flags are set. How many of them are there and by what principle are they established, if as a result of applying a logical function to two numbers, a number is obtained?
mov ax, 5878h
mov bx, 6B36h
mov cx, 5CFDh
P: mov al, bl
Q: test bh, cl
jpe E
mul ch
shl ax, 3
jmp F
E: imul cl
xor cl, ah
F: sub ah, cl
Here’s another example, in it when applying the test – the result is True , how did it happen?
Answer 1, authority 100%
TEST
sets the PF, SF and ZF flags.
- Parity Flag – 1 if AND results in an even number of (1) bits set.
- Sign Flag – 1 if the AND result is negative (most significant – signed – bit = 1)
- Zero Flag – 1 if the result is AND = 0
and resets CF and OF. Here’s a general outline:
Operation
TEMP ← SRC1 AND SRC2;
SF ← MSB (TEMP);
IF TEMP = 0
THEN ZF ← 1;
ELSE ZF ← 0;
FI:
PF ← BitwiseXNOR (TEMP [0: 7]);
CF ← 0;
OF ← 0;
The AND result itself is discarded. In your example:
6Bh AND FDh = 69h = 01101001b
PF will be set to 1. jpe
will jump.