计算1+2+3+…… +N。
C语言描述:
#include <stdio.h> int main() { int n=10,sum=0; for(int i=1;i<=n;i++) { sum+=i; } printf("%d",sum); }
汇编语言:
include irvine32.inc .data n dword 10 .code main proc mov ecx,n mov eax,0 mov ebx,1 sumloop: add eax,ebx inc ebx loop sumloop call writeint main endp end main
运行结果: