Jump to content
IGNORED

Why does adc behave as it does?


minerscale

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

If you want to add numbers that are longer than 8-bits it is very useful. A number larger than 8-bits is represented using multiple 8-bit values. To add them together, you clear the carry and start adding them together from the lowest pair. If the addition overflows, the carry-out becomes the carry-in for the next addition. The code below shows how to add two 16-bit numbers. Notice that there is no CLC after the first addition as the carry flag needs to be preserved:

add16:
    clc				; clear carry
    lda num1lo
    adc num2lo                  ; add low numbers
    sta reslo			; store low sum
    lda num1hi
    adc num2hi		        ; add high numbers with carry
    sta reshi			; store high sum
Edited by cd-w
  • Like 1
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.

Guest
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.

Loading...
  • Recently Browsing   0 members

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