### Author Topic: Question Regarding How Flags Work  (Read 5254 times)

#### xXZexxMooreXx

• Regular Member
• • Posts: 5 ##### Question Regarding How Flags Work
« on: March 01, 2017, 07:14:55 PM »
Code: [Select]
`mov ax, 7FF0hadd al, 10h  ; a) CF = 1, SF = 0, ZF = 1, OF = 0 add ah, 1     ; b) CF = 0, SF = 1, ZF = 0, OF = 1add ax, 2     ; c) CF = ?, SF = ?, ZF = ?, OF = ?`
a) F0 + 10 = 00 so the the ZF throws, but why the Carry (unsigned) over the the Overflow(signed)?   I'd like to guess that it's because the result of "00" isn't signed given the high bit is 0 and not 1.

b) 7F + 01 = 80, and that's -128 signed, so why does it Overflow if it's within bounds of a signed byte?

Flags are probably so easy that asking this question could be considered an embarrassment.

#### jj2007

• Member
•     • • Posts: 13661
• Assembly is fun ;-) ##### Re: Question Regarding How Flags Work
« Reply #1 on: March 01, 2017, 07:57:42 PM »
Look at the results, perhaps that makes it easier (uppercase=flag set):
Code: [Select]
`Aflags:          CZsox:al            00   ; new result is zero, and to reach it, al had to go beyond 255 = carry!Bflags:          czSOx:ah            80   ; not beyond 255, but result is negativeCflags:          czSox:ax            8002  ; again, not beyond 65535, but result is negative`
Source:

Init
mov ax, 7FF0h
add al, 10h            ; a) CF = 1, SF = 0, ZF = 1, OF = 0
deb 4, "A", flags, x:al
add ah, 1            ; b) CF = 0, SF = 1, ZF = 0, OF = 1
deb 4, "B", flags, x:ah
add ax, 2            ; c) CF = ?, SF = ?, ZF = ?, OF = ?
deb 4, "C", flags, x:ax
Inkey
EndOfCode

Re overflow flag: the signed two's-complement result would not fit in the number of bits used for the operation or (much more detailed) http://teaching.idallen.com/dat2343/10f/notes/040_overflow.txt

#### xXZexxMooreXx

• Regular Member
• • Posts: 5 ##### Re: Question Regarding How Flags Work
« Reply #2 on: March 01, 2017, 08:55:01 PM »
Re overflow flag: the signed two's-complement result would not fit in the number of bits used for the operation or (much more detailed) http://teaching.idallen.com/dat2343/10f/notes/040_overflow.txt

•  