Chapter 5. Branching and Looping

Kick Assembler has control directives that let you put conditions on when a directive is executed and how many time it is executed. These are explained in this chapter.

5.1. Boolean Values

The conditions for control directives are given by Boolean values, which are values that can be true or false. They are generated and used as in programming languages like Java and C#. The following are examples of boolean variables:

.var myBoolean1 = true    // Set the variable to true  
.var myBoolean2 = false   // Set the variable to false
.var fourHigherThanFive = 4>5 // Sets fourHigherThanFive = false
.var aEqualsB = a==b    // Sets true if a is the same as b
.var xNot10 = x!=10     // Sets true if x doesn’t equal 10

Here is the standard set of operators for generating Booleans:

Table 5.1. Boolean generating Functions

Name Operator Example Description
Equal == a==b Returns true if a equals b, otherwise false.
Not Equal != a!=b Returns true if a doesn't equal b, otherwise false.
Greater > a>b Returns true if a is greater than b, otherwise false.
Less < a<b Returns true if a is less than b, otherwise false.
Greater than >= a>=b Returns true if a is greater than or equal to b, otherwise false.
Less than <= a<=b Returns true if a is less or equal to b, otherwise false.

All the operators are defined for numeric values, other values have defined a subset of the above. E.g. you can't say that one boolean is greater than another, but you can see if they have the same values:

.var b1 = true==true    // Sets b1 to true
.var b2 = true!=(10<20) // Sets b2 to false

Boolean values have a set of operators assigned. These are the following:

Table 5.2. Boolean Operators

Name Operator Example Description
Not ! !a Returns true if a is false, otherwise false.
And && a&&b Returns true if a and b are true, otherwise false.
Or || A||b Returns true if a or b are true, otherwise false.

And are used like this:

.var allTrue = 10HigherThan100 && aEqualsB // Is true if the two boolean
                                           // arguments are true.

Like in languages like C++ or Java, the && and || operators are short circuited. This means that if the first argument of an && operator is false, then the second argument won't be evaluated since the result can only be false. The same happens if the first argument of an || operator is true.