hi,can some one explain me pleas the idea of overflow flag with example(i am new in Microcontroller) thanks
Hi,thanks, for the overflow flag its written in my book that if we add or subbtract any 2 number, the result of this 2 number will decide wether the OV will be set or not, under the condition -128<result>127, take this example
0FH + 7FH = 8E (I REALLY DON'T KNOW HOW HE GOT 8EH) also indecimal it will be 15 + 127 = 124
the idea isn't clear to me please can you make it easy for me
thanks
Well, if you start with zero and subtract one then you end up with minus 1 which is 255 decimal or 0xff.mr. Mike, how did you get -114, and in my book its written for the same example 8EH responses -116 how i get this responses
Hi,thanks man but still its not clear for me how we got it -114 can you please explain in more details, (this is my firs time in micro controller )
BEST REGARD
hi,thanks a lot every body
i have seen the table and i have some questions about it:
1- here we added 0F + 7F, in the table why we start from 7F,
..Thats one of the numbers you wanted to add
what about 0F?
2- why we start with 0 digit directly after 7F why not 81 and then continue?
Because 7Fh is a positive number.
If you add "1" to 7Fh you get 80h, not 81h
3- in the notes its written that (as a signed number,8EH represent -114,
In the 8Eh value, bit 7 [ the sign bit ] is SET, so it represents a negative value.
which is clearly not the correct result of 142; therefor, the OV bit is set) can you explain me this please
thanks
can we take another example 55H + AAHIf we consider the value of '142' which you have quoted and subtract 128 we get 14 [ 0Eh].
Using 8bit signed values you cannot have a positive value of greater than 127.
Using UNSIGNED values 7Fh + 0Eh = 8Dh [141 decimal]
IIUC your book does say that is a maths 'error' condition that should be tested for.???
the idea of signed number and unsigned number is not clear to me yet, in theIf you add unsigned numbers then
0x55 + 0xAA = 85 + 170 = 255
Doing the same with signed numbers,
0x55 + 0xAA = 85 + -86 = -1
Both of these are correct.
However,
0xff + 0x0f = 255 + 15 = 270
This result will not fit in a 8 bit register and so you end up with 14 in your register which is wrong. But when we do it signed,
0xff + 0x0f = -1 + 15 = 14
Which is correct.
Mike.