汇编语言
编写一个计算 (n)(n+1)/2 的程序。它应该从用户那里读取值“n”。提示:您可以通过将 1 和 n 之间的所有数字相加来计算此公式。
我在 HLA 中编写上述代码时遇到了挑战。我设法得到以下
program printing_n_Numbers;
#include("stdlib.hhf");
static
n:int32;
i:int32;
begin printing_n_Numbers;
stdout.put("Enter n: ");
stdin.get(n);
mov(0,ecx)
stdout.put("printing ",n," Numbers ",nl);
for(mov(0,eax);eax<=n;add(1,eax)) do
for(mov(0,ebx);ebx<eax;add(1,ebx)) do
ecx = add(eax,ebx);
stdout.put("N was = ");
stdout.puti32(exc);
stdout.newln();
endfor;
endfor;
end printing_n_Numbers;
当我输入一个像 6 这样的数字时,输出是
Enter n: 6
printing 6 Numbers
N was = 1
N was = 2
N was = 3
N was = 4
N was = 5
N was = 2
N was = 4
N was = 6
N was = 3
N was = 6
N was = 4
N was = 8
N was = 5
N was = 6
我将如何对其进行编码以输出输入数字的总和?