I need some help in AT&T assembly again, I've load some data into memory like below (hex and dec).
(gdb) x/8xb &buffer_in
0x8049096: 0x03 0x02 0x10 0x27 0xe8 0x03 0x64 0x00
(gdb) x/8db &buffer_in
0x8049096: 3 2 16 39 -24 3 100 0
Lets say that first byte = number count, second = each number length in bytes and then we got (first * second) bytes of numbers. For this example, 3 numbers, 2 bytes each, first number is 16 39 and so one. I would like to add each number, so in this case it would be adding 0x10 + 0xe8 (lower byte) to result[0] then 0x27 + 0x03 to result[1] and then again, result[0] = result[0] + 0x64 and finally result[1] = result[1] + 0x00.
When I'm adding 0x64 to result[0] which already contains 0xf8, the CF (carry flag) is set, and that's great of course because I would like to use this carry in result[1] next addition. But the problem is that after next CMP instruction (I'll mark it on code below) this carry flag is cleared so the final result is 0x5C2A (when I combine two bytes of result) and should be 0x5C2B (but the carry flag didnt affect the addition due to cmp instruction).
%eax - amount of numbers to sum
%ecx - length of each number in bytes
%esi - before loops start is pointing to first byte of 'real' data (0x10 in this case)
loop1:
movl $0, %ebx
loop2:
leal (%esi, %ebx, 1), %edi
movb (%edi), %dl # %dl contain now next byte to add
adc %dl, result(%ebx) # adding to result
inc %ebx
cmp %ebx, %ecx # this comparsion clears CF flag and that's the problem
JG loop2
leal (%esi, %ecx, 1), %esi
dec %al
cmp $0, %al
JG loop1