HLA 将 1 和 n 之间的所有数字相加

HLA Adding Up All The Numbers Between One And n

汇编语言

Write a program that computes (n)(n+1)/2. It should read the value “n” from the user. Hint: you can compute this formula by adding up all the numbers between one and 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

我如何编写代码以输出输入数字的总和?

已解决

经过多次更改后,程序运行正常。我就是这样修改的

mov(0,ecx);
    stdout.put("You Have Entered: ",n,nl);
    for(mov(0,eax);eax<=n;add(1,eax)) do
        add(eax,ecx);
    endfor;

为了打印和,这是代码

stdout.puti32(ecx); 

我用stdout.puti32把十六进制转成原来的十进制数制