Assembly ADC (Add with carry) to C++

后端 未结 6 1437
我寻月下人不归
我寻月下人不归 2020-12-01 14:46

There is an x86 assembly instruction ADC. I\'ve found this means "Add with carry". What does this mean/do? How would one implement the behavior of thi

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 15:06

    There is a bug in this. Try this input:

    unsigned first[10] =  {0x00000001};
    unsigned second[10] = {0xffffffff, 0xffffffff};
    

    The result should be {0, 0, 1, ...} but the result is {0, 0, 0, ...}

    Changing this line:

    carry = (first[i] > result[i]);
    

    to this:

    if (carry)
        carry = (first[i] >= result[i]);
    else
        carry = (first[i] > result[i]);
    

    fixes it.

提交回复
热议问题