Subject: Re: [stella] time to stick me with a fork? From: KirkIsrael@xxxxxxxxxxxxx Date: 14 Mar 2004 21:54:52 -0000 |
> At 01:41 PM 3/14/2004 +0000, you wrote: > > >Subpixel Joust Pong comes to mind. Everyone on the group said it > >was the right thing to do, and it made all the difference in > >the world, but 16 bit math still makes me go crosseyed sometimes. > >(I understand why you clear the carry before addition, but owe > >it to myself to spend some time w/ the 6502 emulator and figure > >out why you need to set the carry before subtraction.) > In a nutshell - the carry bit is essentially the 9th bit of accumulator > (possibly other math functions of the cpu as well - it's been a number of > years since I've touched 6502 programming) so, when your addition results > in a value greater than 255 decimal, the 9th bit (carry) catches the > carryover. In a subtraction, it PREVENTS an underflow. (in other words, > when you set the 9th bit of the accumulator to 1 it becomes impossible for > your subtraction to go below zero, or to become negative.) Ok, maybe I'm starting to get it. I find the carry for addition easy to understand-- not enough room for the bits, one gets pushed into the carry, and then if you do another addition thereafter, that'll get added in to the right. I think what messed me up with subtraction, is this idea that the carry bit was...like, a bit whose meaning was...numeric? But REALLY, it's more of a flag. Because in subtraction, the mental metaphor of the carry bit as a "numeric bit" breaks down, because if it's not set, that means the result of what's happening at the rightmost bits is one LESS than what you'd expect. I know that's a rough, vaguely handwaving description that misses the "why" (like, I think there's a more elegant, deeper reason why they didn't reverse the meaning, so you always Cleared Carry before any math) but I'm getting the basics. -- KirkIsrael@xxxxxxxxxxxxx http://kisrael.com You Shall Not Subject Your God To Market Forces! --Book of Om, Chap. IV v.6b ("Small Gods",Terry Pratchett) ---------------------------------------------------------------------------------------------- Archives (includes files) at http://www.biglist.com/lists/stella/archives/ Unsub & more at http://www.biglist.com/lists/stella/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [stella] time to stick me with , KirkIsrael | Thread | Re: [stella] time to stick me with , Chris Wilkson |
Re: [stella] time to stick me with , Ronald A. Laski, Jr. | Date | Re: [stella] time to stick me with , Chris Wilkson |
Month |