Write a program which reads a number n from the console. Then calculates the sum of all odd numbers between 1 and 2n + 1 (incl.).
Assignment also on GitHub, Exercise 0.0.
print_eax as well as the header and tail of the script are provided by the tutor.
format PE console entry start include 'win32a.inc' ; =============================================== section '.text' code readable executable start: call read_hex mov esi, 1 ; esi becomes the counting variable. mov ebx, 2 mul ebx add eax, 2 mov edi, eax ; edi becomes the limit. mov eax, esi mov ebx, 2 ; Will be the divisor. mov ecx, 0 ; ecx will store the sum. operationSet: mov edx, 0 ; Make sure that the register is empty. div ebx cmp edx, 0 JE manageOperationSet ; If 0 then skip next operation. add ecx, esi manageOperationSet: inc esi mov eax, esi cmp esi, edi jne operationSet mov eax, ecx call print_eax push 0 call [ExitProcess] include 'training.inc'
I've tested my program with the numbers from 1 to 6 and get correct results. I think it works correctly, but I'm not sure concerning my register usage.
Moreover: What could be improved? Are there weak points in my code?