### Author Topic: Question Regarding How Flags Work  (Read 2606 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: 9514
• Assembler 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

•
{"ft_lang_label":"__label__en","ft_lang_prob":0.95174325,"math_prob":0.9646509,"size":550,"snap":"2019-26-2019-30","text_gpt3_token_len":199,"char_repetition_ratio":0.13553114,"word_repetition_ratio":0.0,"special_character_ratio":0.40545455,"punctuation_ratio":0.19565217,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95354104,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-07-18T18:28:23Z\",\"WARC-Record-ID\":\"<urn:uuid:07fd3f9d-db36-4873-ba88-e47c187a2caf>\",\"Content-Length\":\"26913\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:654547fd-ef1f-4716-8271-9e1fafff4087>\",\"WARC-Concurrent-To\":\"<urn:uuid:c046c36e-b114-4ad3-a1fc-e080f4c20525>\",\"WARC-IP-Address\":\"182.160.153.17\",\"WARC-Target-URI\":\"http://masm32.com/board/index.php?topic=6043.0\",\"WARC-Payload-Digest\":\"sha1:NQWDKJXSWO7IGDVHU2TPYA3GR7ANH2RZ\",\"WARC-Block-Digest\":\"sha1:DQ4R7AHLNYQHXB3WNGLLST2FD53XQVX3\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-30/CC-MAIN-2019-30_segments_1563195525699.51_warc_CC-MAIN-20190718170249-20190718192249-00147.warc.gz\"}"}