Understanding the Flag Register in x86 Assembly Language
Ismiel Abir
Posted on April 17, 2024
In assembly language, understanding the processor status and flags register is very crucial part. Flag register is the special purpose of register. There are total 9 flags register. In this article, we will describe all this status flag registers. So, lets start….
.
We can divided the 9 flags into two category, those are
Status Flags
There are 6 flag registers in 8086 microprocessor which become set (1) or reset (0) depending upon condition after either 8-bit or 16-bit operation. These flags are conditional/status flags.
The 6 status flags are:
a. Sign Flag (SF)
b. Zero Flag (ZF)
c. Carry Flag (CF)
d. Auxiliary Carry Flag (AF)
e. Parity Flag (PF)
f. Overflow Flag (OF)
.
Control Flags
The control flags enable or disable certain operations of the microprocessor.
There are 3 control flags…
a. Directional Flag (DF)
b. Interrupt Flag (IF)
c. Trap Flag (TF)
.
.
Sign Flag (SF): If the MSB of a result is 1 than the sign flag will be 1. If the MSB of the result is 0 than the sign flag will be 0.
Zero Flag (ZF): For zero result, it will be 1. For non-zero result it will be 0.
Carry Flag (CF): If there is a carry out from the most significant bit (MSB) on addition, or there is a borrow into the MSB on subtraction, CF will be 1. Otherwise, CF will be 0.
Auxiliary Carry Flag (AF): If there is a carry out from bit 3 on addition, or a borrow into bit 3 on subtraction, AF will be 1. Otherwise, AF will be 0.
Parity Flag (PF): If the low byte of a result has an even number, PF will be 1. Otherwise, PF will be 0.
Overflow Flag (OF): If signed overflow occurred, OF will be 1. Otherwise OF will be 0.
Effect of Instructions on Flags
Different instructions in assembly language may affect the flags differently. For example, arithmetic instructions like ADD and SUB directly affect all flags. INC and DEC flag affects all except CF. On the other hand, MOV and XCHG affects no flags.
References:
Y. Y. Yu and C. Marut, Assembly Language Programming and Organization of the IBM PC, illustrated ed. Mitchell McGraw-Hill, 1992
Posted on April 17, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.