HLA - High Level Assembler
Dlaczego HLA?
Struktura programu

program HelloWorld;
#include( "stdlib.hhf" )
begin HelloWorld;
   stdout.put( "Hello, World of Assembly Language", nl );
end HelloWorld;

hla -v hw

Deklaracje danych globalnych

static
  i8: int8;
  i16: int16;
  i32: int32 := -2130;
  u16: uns16 := 12455;
  isReal : boolean := true;
  c: char := 'c';
  s: string := "Tekst"

Struktura programu

 

Struktura programu

 

Struktura programu

 

Struktura programu

 

Podprogramy

procedure ProcName ;
 
   // lokalne deklaracje 
 
begin ProcName;
 
   // ciało funkcji
 
end ProcName;

program zeroBytesDemo;
#include( “stdlib.hhf” );
 
 // Zeruje 256 elementów tablicy "intów"
 // której adres jest przekazywany EBX  
 procedure zeroBytes;
 begin zeroBytes;
 
   mov( 0, eax );
   mov( 256, ecx );
   repeat
 
     mov( eax, [ebx] ); 
     add( 4, ebx ); 
     dec( ecx ); 
 
   until( ecx = 0 ); // Repeat for 256 dwords.
 
 end zeroBytes;
 
static
 dwArray: dword[256]; 
 
begin zeroBytesDemo;
 lea( ebx, dwArray );
 
 call zeroBytes;
 // zeroBytes(); 
 
end zeroBytesDemo;

Przekazywanie parametrów przez wartość

program PassByValueDemo;
#include( "stdlib.hhf" );
var 
 i: int32;
 j: int32;
 
 procedure pbv( a:int32;  b:int32 );
 var 
    suma : int32;
 begin pbv;
 
   push( eax );
 
   // a = -1;
   mov( -1, a ); // Store -1 into the “a” parameter.
 
   // b = -2;
   mov( -2, b ); // Store -2 into the “b” parameter.
 
   // Print the sum of a+b.
   mov( b, eax );
   add( a, eax );
   mov( eax, suma);
   stdout.put( "a+b=", suma, nl );
 
 end pbv;
 
begin PassByValueDemo;
 
 mov( 50, i );
 mov( 25, j );
 
 // Call pbv passing i and j by value
 pbv( i, j );
 
 stdout.put
 ( 
  "i= ", i, nl, 
  "j= ", j, nl 
 );
end PassByValueDemo;
 

Przekazywanie parametrów przez referencje

program PassByRefDemo;
#include( “stdlib.hhf” );
var 
 i: int32;
 j: int32;
 
 procedure pbr( var a:int32; var b:int32 );
   const
     aa: text := “(type int32 [ebx])”;
     bb: text := “(type int32 [ebx])”;
 
 begin pbr;
 
   push( eax );
   push( ebx ); // Need to use EBX to dereference a and b.
 
   // a = -1;
   mov( a, ebx ); // Get ptr to the “a” variable.
   mov( -1, aa ); // Store -1 into the “a” parameter.
 
   // b = -2;
   mov( b, ebx ); // Get ptr to the “b” variable.
   mov( -2, bb ); // Store -2 into the “b” parameter.
 
   // Print the sum of a+b.
   // Note that ebx currently contains a pointer to “b”.
   mov( bb, eax );
   mov( a, ebx ); // Get ptr to “a” variable.
   add( aa, eax );
   stdout.put( “a+b=”, (type int32 eax), nl );
 
 end pbr;
 
begin PassByRefDemo;
 // Give i and j some initial values so
 // we can see that pass by reference will
 // overwrite these values.
 
 mov( 50, i );
 mov( 25, j );
 
 // Call pbr passing i and j by reference
 
 pbr( i, j );
 
 // Display the results returned by pbr.
 stdout.put
 ( 
  “i= “, i, nl, 
  “j= “, j, nl 
 );
end PassByRefDemo;


Tomasz Kapela, Kraków 2011-2020