0

how to correctly implement the addition of binary numbers from two early arrays

There was a problem updating the array.

I need to replace the 2s in my resulting array with 1, 0

but there is a problem with the update that I can't handle

output result should be 1010 which is early 10

but I can't update and I'm stuck either on 0201 or 2010 or nothing in general, how to fix this problem?

check_data: -- from this point everything stops working

    section .text
    global _start
_start:
    mov esi, array_1
    mov ecx, len_arr_1

stack_push_1:       
    lodsb
    push ax
    loop stack_push_1
    
mov esi, 0
mov ecx, len_arr_2

_add_two_array:
    
    pop ax
    add ax, [array_2 + esi]
    inc esi
    mov [res + esi], ax
    loop _add_two_array



mov eax, 3

check_data: 
    mov esi, -1
    cmp eax, esi
    je output_set
    
    mov esi, 2
    cmp [res + eax], esi
    je update
    dec ecx
    jmp check_data
    
update:

    mov esi, 0
    mov [res + eax], esi
    mov esi, 1
    dec eax
    mov [res + eax], esi
    mov esi, -1
    cmp eax, esi
    je output_set
    

output_set:
    mov esi, 0
    mov ecx, len_res

output:
    
    push ecx
    
    mov ecx, [res + esi]
    inc esi
    add ecx, 48
    mov [msg], ecx
    mov edx, msg_len
    mov ecx, msg
    mov ebx, 1
    mov eax, 4
    int 0x80
    
    pop ecx
    
    loop output

exit:
    nop
    mov eax, 1
    mov ebx, 0
    int 80H


section .data

array_1 db 1, 0, 1
len_arr_1 equ $ - array_1

array_2 db 1, 0, 1
len_arr_2 equ $ - array_2

res db 0, 0, 0, 0
len_res equ $ - res

msg db  '', 0xa
msg_len equ $ - msg
Cthulhu
  • 1
  • 3
  • do not post duplicate questions ... instead edit in new info to your original one and use comments to notify us of changes ... – Spektre Apr 29 '22 at 11:38

0 Answers0