Good news: you can make this much simpler !
I found a mathematical way to find it:
The sum of ALL numbers until n is given by: n*(n+1)/2
Since we want only odd numbers, we can modify it like this:
1 2 3 4 5 ...
0 1 2 3 4 ...
+______________
1 3 5 7 9 ...
So the formula is then: n*(n+1)/2 + (n-1)*n/2 = n²!
We're almost there, but when we give a n, it will give us all the numbers smaller than 2N.
We can use bitshift right, which halve the number AND round it down.
So the code is, assuming the input is in ax:
;assume the unsigned integer limit X is already in ax:
shr ax,1
mul ax
; done !
Thus this will calculate te sum of odd numbers strictly lower than X, so:
X = 15;
bitshift right: 00001111 --> 00000111 = 7;
square: 49 = 1 + 3 + 5 + 7 + 9 + 11 + 13;