#3.Details Of The Flag Register(FR) And Bit Fields

  • The flag register is a 16-bit register sometimes referred as the status register. Although the register is 16-bit. Not all the bits are used.
  • Conditional flags: 6 of the flags are called the conditional flags, meaning that they indicate some condition that resulted after an instruction was executed. These 6 are: CF, PF, AF, ZF, SF, and OF.
  • The 16 bits of the flag registers:

CF, the Carry Flag: This flag is set whenever there is a carry out, either from d7 after an 8-bit operation, or from d15 after a 16-bit data operation.

PF, the Parity Flag: After certain operations, the parity of the result’s low-order byte is checked. If the byte has an even number of 1s, the parity flag is set to 1; otherwise, it is cleared.

AF, the Auxiliary Carry Flag: If there is a carry from d3 to d4 (lowest order nibble) of an operation this bit is set to 1, otherwise cleared (set to 0).

ZF, the Zero Flag: The ZF is set to 1 if the result of the arithmetic or logical operation is zero, otherwise, it is cleared (set to 0).

SF, the Sign Flag: MSB is used as the sign bit of the binary representation of the signed numbers. Sometimes it is called negative flag. After arithmetic or logical operations the MSB is copied into SF to indicate the sign of the result. Useful only when dealing with signed numbers.

MSB (Most Significant Bit)  

TF, the Trap Flag: When this flag is set it allows the program to single step, meaning to execute one instruction at a time. Used for debugging purposes.

IF, Interrupt Enable Flag: This bit is set or cleared to enable or disable only the external interrupt requests. External or Hardware Interrupts are asynchronous and can occur any time. e.g. Keyboard, mouse etc.

DF, the Direction Flag: This bit is used to control the direction of the string operations.

OF, the Overflow Flag: This flag is set whenever the result of a signed number operation is too large, causing the high-order bit to overflow into the sign bit. Counterpart of Carry Flag BUT in signed numbers.

Arithmetic Operations and Flag Registers

It is important that, processor does not know the interpretation of signed & unsigned numbers so, it sets carry and overflow for each interpretation in any operation.

Example: Given code is written in DEBUG environment. Control flags will be found after each arithmetic operation.

Notice:

  1. It is possible to write and trace this code in DEBUG to check if results are correct.
  2. In solution, address of related operation is given for reference.

 

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir