I have an assignment regarding looping in Assembly. Nothing difficult since it's just the start of the course. I have done what was asked and just wanted to see if what I have done is correct. Also, I would like to know if there is anything that is un-needed or could be removed. (I enjoy seeing different ways to go about things and being able to see what is more efficient).
Evaluate the sum of 2n - 5, where n goes from 1 to 7
This is what I have done:
_num1
DB 0
mov cx, 1 ; set counter to 1
mov eax, 0 ; use eax to keep total
eval:
mov [_num1], cx ; set num1 to cx value
shl [_num1], 1 ; double value of num1
add eax, [_num1] ; add values of 2n to eax
sub eax, 5 ; subtract 5 from eax (total)
inc cx ; increment cx
cmp cx, 7 ; check if equal
jne eval
Should this work properly? If so, are there any ways of improving it? If not, what is wrong with the implementation?