Definitions


First some boring basics.

For all examples mentioned in here, we are using 8 Bit signed values.

The uppermost Bit indicates the sign:
0 = positive,
1 = negative.

With 8 Bit, we have a range of -128 to +127:

  binary   hex  decimal
^ 01111111 0x7f +127   
| 01111110 0x7e +126   
| ...
| 00000010 0x02   +2   
| 00000001 0x01   +1   
0 00000000 0x00    0   
| 11111111 0xff   -1   
| 11111110 0xfe   -2   
| ...
| 10000010 0x82 -126   
| 10000001 0x81 -127   
v 10000000 0x80 -128   

Problem is, when subtracting 1 fom -128, we won't have -129.
The result won't fit into 8 Bit, so the value would roll over to +127.

Also, when adding 1 to +127, it won't fit into 8 Bit,
giving us -128 as a result.

The main purpose of the V_Flag is, to indicate that such an overflow had happened:
The signed result from add/subtract did not fit into 8 Bit (for our example),
and the sign Bit became corrupted.

Strange thing is, that the flag, indicating this Overflow
is called V in some microprocessor's datasheets, instead of O.
Don't know, why... beats me.

Now some examples for the 6502:
'.' means V_Flag cleared,
'*' means V_Flag set.


Hexadecimal values, carry inactive.
Column + row, Bit 0..3 always zero.
Example: 0x70+0x10 would corrupt the sign Bit and set the V_Flag.

A+B, D_Flag=0, C_Flag=0:                                                                   

 +0123456789ABCDEF
+ 0000000000000000
00................
10.......*........
20......**........
30.....***........
40....****........
50...*****........
60..******........
70.*******........
80........********
90........*******.
A0........******..
B0........*****...
C0........****....
D0........***.....
E0........**......
F0........*.......

Hexadecimal values, borrow inactive.
Column - row, Bit 0..3 always zero.
Example: 0x80-0x10 would corrupt the sign Bit and set the V_Flag.

A-B, D_Flag=0, C_Flag=1:

 +0123456789ABCDEF
- 0000000000000000
00................
10........*.......
20........**......
30........***.....
40........****....
50........*****...
60........******..
70........*******.
80********........
90.*******........
A0..******........
B0...*****........
C0....****........
D0.....***........
E0......**........
F0.......*........

Note, that CMP does not affect the V_Flag on the 6502.

For the NMOS 6502, it looks like the V_Flag seems to ignore
the BCD_correction, so it won't work well in decimal mode.


[HOME] [UP]/ [BACK] [1] [2] [3] [4] [NEXT]

(c) Dieter Mueller 2005