将C转换为HLA

时间:2015-10-29 00:21:20

标签: c assembly hla

我在将这个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);

1 个答案:

答案 0 :(得分: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下的变量)。

我建议使用the "HLA Language Reference Manual" and the "HLA Standard Library Manual"