For context: Because of online classes, some Indian university computer classes have reduced to teachers just giving us the code and expecting us to rote learn the thing.
The program is to count the number of +ve and -ve numbers in a given array. The entire code is here.
My question is from lines 45 through 59 (given below)
mov esi, arr
mov ecx,arr_size ;Array counter i.e. 6
mov ebx,0; ;counter for +ve nos
mov edx,0; ;counter for -ve nos.
next_num:
mov eax,[esi] ; take no. in RAX
rcl eax,1 ; rotate left 1 bit to check for sign bit
jc negative
positive:
inc ebx ; no carry, so no. is +ve
jmp next
negative:
inc edx ; carry, so no. is -ve
next:
add esi,4 ; 32 bit nos i.e. 4 bytes
loop next_num
In the above code, from what I can understand, I'm storing the starting location of the array in the ESI register and scanning each element and checking if it's positive or not
However, how do I know when I've reached the end of the array?
The code is maintaining the ECX register but not using it. Why isn't this running endlessly then?
Shouldn't some sort of loop with a DEC ECX and JE 0 instructions be there as well?