0% found this document useful (0 votes)
10 views9 pages

Al - Status Flags

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

Al - Status Flags

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

Assembly Language

Status Flags
Status Flags

There are six flags covered in the syllabus


• O – overflow
• S – sign
• Z – zero
• A – auxiliary
• C – carry
• P – parity
When an arithmetic operation is carried out, certain flags will be set to
1 or 0 to show the result of the operation.

Not all operations will change the value in the flag register.
Overflow flag

• This flag will show whether the result of an arithmetic operation


is a signed number within range.

• Overflow occurs when:

Bit 6 7 Bit 7 8
1 Carry No carry
2 No carry Carry
• Example:

876543210

Mov al, 04 0000 0100 OF = 1


add al, 7F + 0111 1111 there is a carry
1000 0011 from bit 6 to bit 7,
but no carry from
bit 7 to bit 8.

Mov al, FE 876543210 OF = 1


sub al, 7F 1000 0000 there is a carry
+ 1111 1111 from bit 7 to bit 8,
10111 1111 but no carry from
bit 6 to bit 7.
Sign flag
• This flag will show whether an operation will
result in a negative or positive answer.

• Example:

Mov al, 7F 0111 1111 SF = 1


add al, 04 + 0000 0100 the answer is a
1000 0011 negative number

Mov al, 02 0000 0010 SF = 1


sub al, 04 + 1111 1100 the answer is a
1111 1110 negative number
Zero flag

This flag will show whether the result of arithmetic operation


is zero.

Mov al, 07 0000 0111 ZF = 1


sub al, 07 + 1111 1001 the answer is zero
1 0000 0000

Mov al, 02 0000 0010 ZF = 0


sub al, 04 + 1111 1100 the answer is not
1111 1110 zero
Auxiliary flag

• This flag shows if there is carry or a


borrow into from the low order 4 bits.

Mov al, 0F 0000 1111 AF = 1


add al, 09 + 0000 1001 there is a carry
0001 1000 from the low order
4 bits.

Mov al, 02 0000 0010 AF = 0


sub al, 04 + 1111 1100 there is no carry
1111 1110 from the low order
4 bits.
Carry flag

• This flags shows whether the result of an operation


is larger than the size of the register or if there is a
borrow into.

Mov al, 07 0000 0111 CF = 1


sub al, 07 + 1111 1001 the answer is larger
1 0000 0000 than the size of the
register

F 16

Mov al, 02
16
02 CF = 1
sub al, 04 - 04 there is a borrow
FE into
Parity flag
• This flag shows whether the number of bit 1 in the result of
an arithmetic operation is even or odd.

• PF = 1 if the number is even


• PF = 0 if the number is odd.

Mov al, 0F 0000 1111 PF = 1


add al, 09 + 0000 1001 there is an even
0001 1000 number of bit 1.

Mov al, 02 0000 0010 PF = 0


sub al, 04 + 1111 1100 there is an odd
1111 1110 number of bit 1.

You might also like