Hello,

Maybe I am too dumb to figure out where is the problem.  I am implementing
a large integer addition function, b = a + b, where a,b point to arrays
with num 16-bit words, the function will return the carry value, either 0
or 1.  The problem is that this simple function always causes wrong
results, while a for loop (in C) simply does the job.  I spent hours on it
and could not figure our where is the problem.  Any suggestion will be
highly appreciated!

Thanks,

haodong

uint16_t addition(uint16_t *a, uint16_t *b, uint16_t num) {
    uint16_t carry = 0;

        asm volatile (
                "1:                             \n"
                "       rra %0                  \n"
                "       addc 0(%1), 0(%2)       \n"
                "       rlc %0                  \n"
                "       add #2, %1              \n"
                "       add #2, %2              \n"
                "       dec %3                  \n"
                "       jnz 1b                  \n"
                 :"+r"(carry), "+r"(a), "+r"(b), "+r"(num)
                :
                );
    return carry;
}

Reply via email to