bAdkOde

Looping statement

bAdkOde has one looping-statement, which is analogous to a while loop.

Usage:
{ [logic-operator] [src]
   ...
   [statements]
   ...
}

There are four logic operators which are = or equal to zero, ! or not equal to zero, + or greater than zero and or lesser than zero. The source parameter can either be a register or a memory location. The loop will run as long as the condition specified by the logic operator and source parameter is true.

Examples:

# Loop while the value in register a is not zero
{!a
 ...
}

# Loop while the value in location pointed to by register b is zero
{=[b
 ...
}

# Loop while the value in register a is positive
{+a
 ...
}

# Loop while the value in location pointed to by register b is negative
{-[b
 ...
}

Macros

Usage:

Macro definition:
@[macro-name]([param1], ..., [paramN]) = [block of bAdkOde statements 
                                          that use param1, ..., paramN];

Macro usage:
&[macro-name]([param1], ..., [paramN])

Macros are a useful feature in many assemblers. They provide a convenient way to re-use blocks of code. I decided to implement macros in bAdkOde as well. Notice the semi-colon at the end of the macro definition. This tells the parser that the definition has ended.

Examples:
# Macro to convert ASCII representation of integer to actual
# integer value
@atoi(CHR) = -48CHR;

# Macro to convert integer value to ASCII representation of
# integer value
@itoa(NUM) = +48NUM;

# Input a character
?a
# Convert to actual integer value
&atoi(a)

# Store the number 9 in location pointed to by value in 
# register a
>9[a
# Convert 9 to ASCII value of the character '9' (57)
&itoa([a)

Note: Macros aren’t specified in the EBNF because they really aren’t part of the language itself. They’re simply concise representations of a set of instructions.

Labels
Labels are place-holders for “magic numbers”. They make the code much easier to read.

Usage:
Label definition:
*[label-name] = [label-value];

Label usage:
$[label-name]$

In the following example, I’m going to use a label to replace the number ’48’:

Examples:
# Define the offset that we're going to use 
*OFFSET = 48;

# Macro to convert ASCII representation of integer to actual
# integer value
@atoi(CHR) = -$OFFSET$CHR;

# Macro to convert integer value to ASCII representation of
# integer value
@itoa(NUM) = +$OFFSET$NUM;