How to find sum of even numbers in assembly?

Viewed 175

I am learning assembly on my own. I want to find sum of even numbers. However, it does not work, I can't understand why, it does not show any error.

my code is below

        mov ebx, 0;
        mov ESI, [arr]; 
        mov ECX, [arr_size];

    sumeven:
        push ebx;
       
        mov eax, dword ptr[ESI];
        mov ebx, 2;
        cdq
        idiv ebx;
        cmp edx, 0;
        je adding;
        


    adding: 
        pop ebx;
        add ebx, dword ptr[ESI];
        add ESI, 4;
        loop sumeven;


    mov result, ebx;

I am using inline assembly in c language.

1 Answers

I added condition for not equal to 0, and it worked.


        cmp edx, 0;
        je adding;
        jne notequal;
    notequal:
    ---


Related