0

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);
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • 3
    Any specific thing you are stuck with? If not, it's likely that this is going to be closed as “too broad.” Also, please notice that contrary to popular opinion, Stack Overflow is not a code writing service. – fuz Oct 29 '15 at 00:32
  • Gotcha, thank you for that! I am particularly stuck on trying to convert " scanf( %d, &j ); " portion of the code. Is there an HLA counterpart to the "scanf" function? –  Oct 29 '15 at 00:47
  • 1
    Have you considered just calling `scanf()` in your HLA code? – fuz Oct 29 '15 at 09:08

1 Answers1

1

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".

rkhb
  • 14,159
  • 7
  • 32
  • 60