Hey guys can you help? I dont know how to do sum between two numbers For example :
first number>1
second number>5
sum w
You can use conditional jump to do so.
Below, there is a simple code snippet in which ebx
contains current number to be added, ecx
contains number of times loop will run (i.e, second_number - first_number +1
). sum will be stored in eax.
mov eax,0 ; initialise sum with 0
mov ebx,dword[first_number] ;initialise ebx with first_number
mov ecx,dword[second_number]
sub ecx,dword[first_number]
inc ecx ; ecx content will be end_number - start_number + 1, now
calculation: ; after calculation sum can be accessed from eax
add eax,ebx ; sum = sum + ebx content
inc ebx ; ebx = ebx + 1
dec ecx ; ecx = ecx - 1
cmp ecx,0h ; ecx == 0 ?
jne calculation ; if not then once again go through calculation.