minerscale Posted February 13, 2017 Share Posted February 13, 2017 Hi guys, I'm just starting 2600 after making a game for the genesis in C. I'm quite enjoying the ridiculous challenge of doing it and i'm interested in the properties of adc and the carry flag. Why does adc add one more to the accumulator when the carry flag is set? It seems quite random that it would be doing that. It's sort of useful but a pain in the ass at the same time. I end up having to call clc wasting 2 cycles in the process. I'm very confused as to why. So any insight into that would be great. Quote Link to comment Share on other sites More sharing options...
Kylearan Posted February 13, 2017 Share Posted February 13, 2017 (edited) It allows you to extend an addition beyond 8 bits. You can carry over any overflow from the lower 8 bits to the higher 8 bits of a 16 bit addition. For example, if you want to add 100 to a 16 bit number, you can do this: clc lda lowByte adc #100 sta lowByte lda highByte adc #0 sta highByte If the first addition (adc #100) overflows the lower 8 bits, i.e. the result is >255, the carry bit will be set and the second addition will actually add 1 instead of 0 to the high byte. Edited February 13, 2017 by Kylearan Quote Link to comment Share on other sites More sharing options...
minerscale Posted February 13, 2017 Author Share Posted February 13, 2017 (edited) Ahh that makes sense now, Thanks! Is this a 6502 thing or an Atari 2600 thing in general? Edited February 13, 2017 by minerscale Quote Link to comment Share on other sites More sharing options...
Kylearan Posted February 13, 2017 Share Posted February 13, 2017 Ahh that makes sense now, Thanks! Is this a 6502 thing or an Atari 2600 thing in general? It's a general microprocessor thing, not limited to the 6502. You'll find a carry flag and its equivalent use in addition (and subtraction) instructions on all micro processors. Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted February 13, 2017 Share Posted February 13, 2017 For future reference, SBC is SuBtracting with Carry. SEt the Carry flag before subtraction. Quote Link to comment Share on other sites More sharing options...
Mr SQL Posted February 13, 2017 Share Posted February 13, 2017 I'd say it is a 6502 thing with it's relative RISC design; contemporary CPU's had both add and add with carry instructions. Pecularities of RISC architecture abound, for example there are no long branch instructions so you manufacture them by reverse branching over jumps. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.