Jump to content

Why does adc behave as it does?


Recommended Posts

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. :???:

Link to comment
Share on other sites

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:

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 by Kylearan
Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...