The following is pseudo-code:
int array_list[] = {0, 11, 13, 18, 21, 23, 24, 17, 45};
int array_size = sizeof array_list/sizeof sample;
int index = 0; // index for while loop
int sum = 0; // accumulate the result
for (current_size = array_size ; current_size > 0; current_size--){
while (index<current_size){
if(array_list[index]is even){
sum += array_list[index];
}
index += 1;
}
}
My work is:
.data
sum DWORD 0
sample DWORD 0
array_list DWORD 10,11,13,18,21,23,24,17,45
array_size = ($-array_list)/Type array_list
.code
main PROC
mov eax,0
mov edx,sample
mov esi,0
mov ecx,array_size
L1:
cmp esi,ecx
jl L2
jmp L5
L2:
cmp array_list[esi*4], edx
jg L3
jmp L4
L3:
add eax,array_list[esi*4]
L4:
inc esi
jmp L1
L5:
mov sum,eax
I'm confusing how to do for_while loops in .asm file. My question is how can I code
for (current_size = array_size ; current_size > 0; current_size--){
to my code?