flat assembler
Message board for the users of flat assembler.

 Index > Tutorials and Examples > Newbie - Overflow Flag
Author
 Thread
SC0U7

Joined: 20 Feb 2018
Posts: 23
SC0U7 02 Nov 2019, 18:26
Hello guys i am learning assembly language im currently on Flags.
I thinking about Overflow Flag

when i have somethink like this:

Code:
```mov al,7fh
mov cl,1h
add al,cl

;al = 0x80
;Overflow flag is set    ```

But my question is how cpu know how is number negative or positive?
It may be both i am right?
But why is Overflow flag set after this?

Thanks for any reply

02 Nov 2019, 18:26
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 8250
Location: Kraków, Poland
Tomasz Grysztar 02 Nov 2019, 18:51
As a fortunate coincidence, you can find this topic discussed in two of my recent videos.

I explained the basic ideas of the signed encoding and SF/OF in the part 6 of my ongoing x86 tutorial.

And then I also started a new semi-advanced mini-series about using 2-adic numbers to explain these things in detail. There I derive some actual formulas for the value of OF after addition/subtraction operation.
02 Nov 2019, 18:51
SC0U7

Joined: 20 Feb 2018
Posts: 23
SC0U7 02 Nov 2019, 19:50
Thank you Tomasz but if i am right then the reason why is Overflow flag set in 8bit register is fact the 128 in complement method not exist ? the last bit make a error for computer 8bit register then set OF. because for make OF on Zero it must be in range −128 and 127 right? Cuz my AL register cannot hold 128 then it only change it on EAX last byte 000DFF80 like 80 iam right? Thanks
02 Nov 2019, 19:50
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 8250
Location: Kraków, Poland
Tomasz Grysztar 02 Nov 2019, 19:58
In signed interpretation the highest bit is the sign bit. In this case you add two numbers that have the sign bit 0, so they are positive numbers, but the result has the highest bit 1 and therefore would be interpreted as negative number, even though the result of adding two positive numbers should also be positive. This discrepancy is an indication that an overflow occurred - the result of addition was too large to be correctly encoded as a positive number in 8 bits with sign bit.
02 Nov 2019, 19:58
SC0U7

Joined: 20 Feb 2018
Posts: 23
SC0U7 02 Nov 2019, 20:10
so when i try this

mov al,7fh
mov cl,-1h
add al,cl

The Overflow Flag will be not set
02 Nov 2019, 20:10
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 8250
Location: Kraków, Poland
Tomasz Grysztar 02 Nov 2019, 20:14
Yes. You can also see a similar example (-1 + 3) analyzed near the end of my aforementioned 2-adic video.
02 Nov 2019, 20:14
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum

Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.