1
addInt:
        clc
        mov ax, cx
        add ax, bx
            JNC convert

how would i be able to test if the sum is in range of 16 bits, since if I add using 16 bits register the result does not show the carry over value even if the sum is greater than 16 bits, OF will not work either since it will never become overflow due to the use of 16 bits registers. How should i continue this code to make it jump to convert loop. for example if I have FFFF + FFFE, the sum will be 1FFFD, but the eax register will only show FFFD, without the carry over 1 thank in advance for helping

4

1 回答 1

2

You should be able to tell after the add instruction if your resultant value is larger than 16-bits.

The ADD instruction performs integer addition. It evaluates the result for both signed and unsigned integer operands and sets the OF and CF flags to indicate a carry (overflow) in the signed or unsigned result, respectively. The SF flag indicates the sign of the signed result.

Since you appear to be dealing with unsigned 16-bit values, you should look at CF, the carry flag after the addition:

addInt:
    clc
    mov ax, cx
    add ax, bx                ; Sets CF if result is larger than 16-bits
    jc .larger_than_16_bits
于 2013-05-20T04:56:51.273 回答