Assembler ADC (add with carry)

mov eax, ptr_to_num1 ; little endian
mov ebx, ptr_to_num2 ; little endian
xor ecx, ecx
xor edx, edx
clc
bytes_addition:
    mov dl, byte [eax+ecx] ; byte from shortest
    adc dl, byte [ebx+ecx]
    mov byte [eax+ecx], dl
    inc ecx
    cmp ecx, 4 ; counter, 
    jl bytes_addition

Consider in

EAX: 4F2252FF (large end)

EBX: 00DFFC00 (big end)

The result of this addition is incorrect: 50024fff (big endian). It should be 50024eff. It seems that the carry flag is affected, but why?

+4
source share
1 answer

cmp affects the transfer, as it is used for unsigned comparisons.

You can run ecxat -4 and then use jnz bytes_addition. You already have incone that sets the flag to zero when it ecxbecomes zero and does not affect the transfer.

Of course, this offset must be compensated either by adding 4 to eaxthe loop, or by adding 4 offsets in the addressing.

+5
source

Source: https://habr.com/ru/post/1619751/


All Articles