Miscellaneous > Irvine Book Questions.

Question Regarding How Flags Work

(1/1)

xXZexxMooreXx:

--- Code: ---mov ax, 7FF0h

add al, 10h  ; a) CF = 1, SF = 0, ZF = 1, OF = 0

add ah, 1     ; b) CF = 0, SF = 1, ZF = 0, OF = 1

add ax, 2     ; c) CF = ?, SF = ?, ZF = ?, OF = ?

--- End code ---

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:
Look at the results, perhaps that makes it easier (uppercase=flag set):

--- Code: ---A
flags:          CZso
x:al            00   ; new result is zero, and to reach it, al had to go beyond 255 = carry!

B
flags:          czSO
x:ah            80   ; not beyond 255, but result is negative

C
flags:          czSo
x:ax            8002  ; again, not beyond 65535, but result is negative
--- End code ---

Source:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  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:

--- Quote from: jj2007 on March 01, 2017, 07:57:42 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

--- End quote ---

After reading the text file you linked I now understand.  Thank you for your reply jj2007. 

xXZexxMooreXx:
[deleted] 

Navigation

[0] Message Index

Go to full version