实现n1+...+n2 比如求:43+44+...+63的和
算法:n1+...+n2 =(n1+n2)*(n2-n1+1)/2
.386
.model stdcall,flat
option casemap:none
includelib msvcrt.lib
printf proto c:dword,:vararg
scanf proto c:dword,:vararg
.data?
num1 dd ?
num2 dd ? ;//////结果=num1+...+num2
.data
szMsg db 'Please input two num (for example: 43,63) :',0
szRes db '%d,%d',0
szFmt db '%d+...+%d=%d',0dh,0ah,0
.code
start:
invoke printf,offset szMsg
invoke scanf,offset szRes,offset num1,offset num2
mov eax,num1
add eax,num2
mov edx,num2
inc edx
sub edx,num1
mul edx
sar eax,1
invoke printf,offset szFmt,num1,num2,eax
ret
end start
;//// ml /c /coff my.asm
;/// link /SUBSYSTEM:console my.obj