0

我在将此 C 代码转换为 HLA 时遇到了一些麻烦,我想知道是否有人可以帮助我。我的代码的目的是重复提示用户输入十进制值。最后程序应该读出所有输入数字的总和。

bool keepGoing;
int goal = O, total = 0, j = 0;
keepGoing = true;

printf("Feed Me: ");
scanf("%d", &goal);

total = goal;

while (keepGoing) {
    scanf("%d", &j);

    if (j >= goal)
        keepGoing = false;

    total += j;
    goal = j;
}

printf("Your total is %d\n", total);
4

1 回答 1

1

给你:

program DoIt;
#include( "stdlib.hhf" );

static
    keepGoing : boolean;
    goal : int32 := 0;
    total : int32 := 0;
    j : int32 := 0;

begin DoIt;

    mov (true,keepGoing);
    stdout.put ("Feed Me: ");

    // scanf ( "%d", &goal );
    stdin.geti32();
    mov (eax, goal);

    mov (eax, total);

    while (keepGoing) do

        // scanf( "%d", &j );
        stdin.geti32();
        mov (eax, j);

        if (eax >= goal) then
            mov (false, keepGoing);
        endif;

        add (eax,total);
        mov (eax,goal);

    endwhile;

    stdout.put ("Your total is ", total, nl);

end DoIt;

现在尝试使用寄存器而不是存储(下的变量static)。

我建议使用“HLA 语言参考手册”和“HLA 标准库手册”

于 2015-10-29T17:17:07.593 回答