ADDC versus ADD

10,808

Solution 1

It's the value of the carry flag before the addition that is relevant. ADDC includes it in the sum while ADD doesn't.

ADDC X, Y stores X + Y + Carry in X.

ADD only stores X + Y in X.

The purpose of this is to allow chained addition on multi-word "big integers." This is accomplished by adding each word from least to most significant. Using ADDC ensures that carries from previous additions are carried to the next-higher significant word.

Solution 2

In each of your cases, do a subsequent:

ADD A, #0x01

and:

ADDC A, #0x01

In the first case, you should see A = 0x02 and in the second A = 0x03. When the carry flag was set, ADDC will add 1 for the carry flag in addition to the value you are adding to A.

Share:
10,808

Related videos on Youtube

user2461391
Author by

user2461391

Updated on September 15, 2022

Comments

  • user2461391
    user2461391 over 1 year

    I'm trying to figure out the difference between ADDC and ADD instructions for 8051 microcontrollers.

    Description: ADD and ADDC both add the value operand to the value of the Accumulator, leaving the resulting value in the Accumulator. The value operand is not affected. ADD and ADDC function identically except that ADDC adds the value of operand as well as the value of the Carry flag whereas ADD does not add the Carry flag to the result.

    How does ADDC "add the carry flag to the result"? The result is in the accumulator, how does it add a carry flag to it?

    Currently, as I see it, here is how they work:

    MOV A, #0xFF
    ADD A, #0x01  
    

    The result of this is A = 0x01 and C = 1

    With ADDC,

    MOV A, #0xFF
    ADDC A, #0x01  
    

    The result of this is A = 0x01 and C = 1

    Maybe my tests are not right or something. Can someone explain the difference between ADD and ADDC?