Google-apper
Hovedmeny

Post a Comment On: Ken Shirriff's blog

"The 6502 CPU's overflow flag explained at the silicon level"

16 Comments -

1 – 16 of 16
Blogger David Sands said...

The 6502 was an absolutely awesome breakthrough by just a few engineers. It was the inspiration behind ARM.

January 14, 2013 at 5:06 AM

Blogger Ed said...

Excellent walkthrough! Posted to http://forum.6502.org

January 14, 2013 at 8:32 AM

Anonymous Anonymous said...

Awesome article ! Brings back the memories few decades old.

I absolutely loved working on 6502.

It was the only CPU, that I ever learnt all combinations of hexa codes for all instructions and operands, thus being able to save a lot of memory by typing instructions directly in hexa code, instead of wasting precious memory on overinflated syntax like LDA, LDX, STX...

I will be processing this article over next few days.

January 14, 2013 at 9:25 AM

Anonymous PJBlue said...

I did love working with the 6502 and 6510. I even had it multi-tasking on the C128

January 15, 2013 at 5:16 AM

Anonymous Anonymous said...

Pah, the Zilog Z80 was a far superior chip!

January 15, 2013 at 5:47 AM

Anonymous JS said...

I don't see a reason why it couldn't be understood by people, when it was designed by people..

Or they had some sort of routing software to create the chip?

January 15, 2013 at 8:46 AM

Anonymous Anonymous said...

LDA, LDX doesn't take more memory - they just correspond to opcodes...

January 15, 2013 at 10:09 AM

Anonymous Rolf Andreassen said...

I'm confused by the logic. Suppose we have A7=B7=0, C6=1. This should not be overflow, right? But then we have:

(A7 NOR B7) AND C6
=(0 NOR 0) AND 1
=1 AND 1
=1

and then

V = not(((A7 NOR B7) AND C6) NOR (something))
= not (1 NOR (something))
= not (0)
= 1

so the overflow bit is set. Did I make a mistake in logic, or in understanding what setting the overflow bit means?

January 15, 2013 at 12:53 PM

Anonymous Duncan Gunn said...

exciting and excellent article that took me back to my childhood. Back then I dreamed of writing a killer game and tought myself 6502 and Z80. Sure rhe killer game never emerged but programming has become a lifelong love of mine and I even made a bit of money indirectly through gadgets I've built and sold. As for those pussies that never tried getting down with the hardware, whats up with ya!?

January 15, 2013 at 2:16 PM

Anonymous Anonymous said...

Great article. I've read other descriptions of how circuits work in silicon, but this is the first one that didn't leave me more confused than I started.

January 15, 2013 at 3:02 PM

Anonymous P. Freret said...

Rolf Andreassen asked, "Suppose we have A7=B7=0, C6=1. This should not be overflow, right?"

Right. Notice that the logic diagram for the overflow calculation produces the complement of the overflow. The Boolean expression for the OVF calculation is missing a NOT:

NOT OVF = ((A7 NOR B7) AND C6) NOR ((A7 NAND B7) NOR C6)

This is the same as

OVF = ((A7 NOR B7) AND C6) OR ((A7 NAND B7) NOR C6)

which simplifies to

OVF = (-A7 & -B7 & C6) + (A7 & B7 & -C6)

The first term corresponds to the sum of two positive numbers overflowing to produce a negative number. The second term corresponds to the sum two negative numbers overflowing to produce a positive number.

An equivalent expression for overflow is

OVF = C6 XOR C7

Overflow occurs when the carry into an adder's MSB stage is different from its carry out.

January 15, 2013 at 5:01 PM

Anonymous Matthew Hagerty said...

Very very cool! Thanks for taking the time to put together such a nice article. I have been trying recently to learn how to "read" the polygons, and you explanations and graphics help quite a bit.

January 15, 2013 at 6:35 PM

Anonymous Rolf Andreassen said...

P. Freret said: Notice that the logic diagram for the overflow calculation produces the complement of the overflow. The Boolean expression for the OVF calculation is missing a NOT.



The NOT is on the right-hand side of the expression; I have:

V = not(((A7 NOR B7) AND C6) NOR (something))

which is equivalent to your

NOT OVF = ((A7 NOR B7) AND C6) NOR (something)

being left-multiplied by NOT on both sides.

January 16, 2013 at 9:58 AM

Blogger Ken Shirriff said...

Rolf: if A7=B7=0, C6=1, this corresponds to adding for example 0x50 and 0x50, yielding 0xa0. In this case, two positive numbers were added, yielding a negative number. So overflow occurs. The two original numbers are positive because the top bit is 0 (A7 and B7), but the result is negative because the top bit is 1 (due to C6).

(Note that the overflow flag is for signed arithmetic, and is different from carry.)

I put most of the mathematics of overflow in my other article, which hopefully will make things clearer: http://www.arcfn.com/2012/12/the-6502-overflow-flag-explained.html

January 16, 2013 at 11:11 AM

Anonymous Rolf Andreassen said...

You're right. I was a bit confused about what overflow meant.

January 16, 2013 at 2:40 PM

Blogger Richard Galbraith said...

I have the old BBC Micro (North American Edition) still sitting in my basement. I learned on it in 1986, got my own in 1990, and basically used it until 1997. Yes, it was 6502 powered. Yes, it was made by Acorn, the people who made the original ARM Chip. Yes, Olivetti spun off ARM, renamed Acorn to Element14, and later sold Element14 off. Yes, the Raspberry Pi carries on in the tradition of the BBC Micro, complete with ARM powered SoC by Broadcom. And I have one of those as well.

My wife paid $1000 for my Acorn in 1990.
I invested less than $100 in my Raspberry Pi. :)

May 16, 2014 at 12:10 AM

You can use some HTML tags, such as <b>, <i>, <a>

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot