user5500712
user5500712

Reputation:

Converting C to HLA

I am having some trouble converting this C code into HLA, I was wondering if someone could help me out. The purpose of my code is to repetitively prompt for a decimal value from the user. And in the end the program should read out the total of all the the number entered.

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);

Upvotes: 0

Views: 570

Answers (1)

rkhb
rkhb

Reputation: 14409

Here you are:

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;

And now try to use only registers instead of storage (the variables under static).

I suggest to use the "HLA Language Reference Manual" and the "HLA Standard Library Manual".

Upvotes: 1

Related Questions