coolcoolcool
coolcoolcool

Reputation: 3

High Level Assembly (HLA) Programming error on for loop

I'm trying to solve this problem:

Write a program to produce a number table as described here. This table should be built from a single integer value provided by the user. The program will display a square 5X5 of various numbers. The entered number should show up in the table making a capital L shape. Every other spot inside the box should also be filled with a number. Those excess numbers should start with one bigger than the entered number and increment by one for every additional number used.

For example, the following output should be produced when the user inputs the starting value 15:

Gimme a starting value: 15 15 16 17 18 19 15 20 21 22 23 15 24 25 26 27 15 28 29 30 31 15 15 15 15 15

My code is below and I keep getting an error on line 15 (for (a := 1 to 5): Syntax error, unexpected assignTkn, expecting '(', Near << := >>

I can't figure out how to fix it:

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

static
    StartingVal: int32;
    a: int32;
    b: int32;

begin NumberTable;
    stdout.put("Starting value: ");
    stdin.get(StartingVal);

    stdout.newln();

    for (a := 1 to 5)
        for (b := 1 to 5)
            if (b = 3 or a = 5)
                stdout.put(StartingVal, " ");
            else
                stdout.put(StartingVal + (a - 1) * 5 + (b - 1), " ");
            endIf;
        endFor;
        stdout.newln();
    endFor;

    exit();
end NumberTable;`

I tried adding brackets and 'do', still get the same error. I feel like it's obvious, but i'm not sure what i'm missing

Upvotes: 0

Views: 105

Answers (1)

Romy
Romy

Reputation: 1

To be honest, I don't fully understand the purpose of your program. But I applied all the necessary corrections to make it compile-able.

  • The syntax of the for-loop is for( initStmt; BoolExpr; incStmt ) do

  • Logical or is represented by ||

  • Also the calculation will not work as expected, because HLA is not so high-level. You need to break the calculation steps down and perform it in processor registers.

  • exit() does not exist this way and needs to be removed.

    program NumberTable;
     #include("stdlib.hhf")
    
     static
         StartingVal: int32;
         a: int32;
         b: int32;
    
     begin NumberTable;
         stdout.put("Starting value: ");
         stdin.get(StartingVal);
    
         stdout.newln();
    
         for( mov(0, a); a<=5; add(1, a) ) do
             for( mov(0, b); b<=5; add(1, b) ) do
                 if (b = 3 || a = 5) then
                     stdout.put(StartingVal, " ");
                 else
                     mov(a, eax);
                     sub(1, eax);
                     intmul(5, eax);
                     mov(b, ebx);
                     sub(1, ebx);
                     add(StartingVal, eax);
                     add(eax, ebx);
                     // ebx := StartingVal + (a-1) * 5 + (b-1);
                     stdout.put(ebx, " ");
                 endif;
             endfor;
             stdout.newln();
         endfor;
    
     end NumberTable;
    

Output Starting value: 15

00000009 0000000A 0000000B 15 0000000D 0000000E
0000000E 0000000F 00000010 15 00000012 00000013
00000013 00000014 00000015 15 00000017 00000018
00000018 00000019 0000001A 15 0000001C 0000001D
0000001D 0000001E 0000001F 15 00000021 00000022
15 15 15 15 15 15

Upvotes: 0

Related Questions