ENVIRONMENT
- HLA (High Level Assembler - HLABE back end, POLINK linker)
Version 2.16 build 4413 (prototype)
- Windows 10
NOTE
- This example below is written in HLA (High Level Assembly), this allows for the use of high level features like for loops and the input/output provided by the standard library. Therefore some of this code needs to be translated to assembly for a pure assembly solution.
- This example is also assuming x86 or similar variant.
- Example starts with the 1st element as 0, as in the user inputs 1, and 0 is printed.
- This example will break after the 47th element of the Fibonacci sequence.
EXAMPLE
program Fibonacci;
#include("stdlib.hhf");
static
Loops: int32;
Number1: int32:= 0;
Number2: int32:= 1;
begin Fibonacci;
// Prompt user for input
stdout.put("Enter a number: ");
// Get user input
stdin.get(Loops);
// Loop for the requested amount
for (mov(0, ECX); ECX < Loops; inc(ECX)) do
// Print the Fn element
stdout.put(Number1, nl);
// Calculate the Fn+2 element
mov(Number1, EAX);
add(EAX, Number2);
// Store the Fn+1 element as the next Fn element
mov(Number2, Number1);
// Store the Fn+3 element as the Fn+2 element
mov(EAX, Number2);
endfor;
end Fibonacci;
Without Static Variables
program Fibonacci;
#include("stdlib.hhf");
begin Fibonacci;
xor(EBX, EBX);
mov(1, EDX);
stdout.put("Enter a number: ");
stdin.geti32();
for (mov(0, ECX); ECX < EAX; inc(ECX)) do
stdout.put((type int32 EBX), nl);
mov(EDX, EBP);
add(EBX, EDX);
mov(EBP, EBX);
endfor;
end Fibonacci;