The syntax used in the Bit Bashing section of Safalra’s Website is similar to that used in many high-level programming languages. Each line (except those consisting of a label) represents one machine code instruction, and is either and a command or a jump.
Commands
Each command takes the form var = expression, where each var is a single letter variable, from the set {a,b,…,z}, and expression takes one of the following forms:
| Operation | Common name | Description |
|---|---|---|
! var | Bitwise not | A bit in the output is 0 if and only if the corresponding bit in the input is 1 |
var & var | Bitwise and | A bit in the output is 1 if and only if the corresponding bits in the inputs are both 1 |
var | var | Bitwise or | A bit in the output is 0 if and only if the corresponding bits in the inputs are both 0 |
var ^ var | Bitwise xor | A bit in the output is 1 if and only if the corresponding bits in the inputs are different |
var << n | Shift left | A bit in the output is 1 if and only if the nth lower bit in the input is 1 - the n lowest bits are 0 |
var >> n | Arithmetic shift right | A bit in the output is 1 if and only if the nth higher bit in the input is 1 - the n highest bits are 1 if and only if the highest bit in the input is 1 |
var >>> n | Logical shift right | A bit in the output is 1 if and only if the nth higher bit in the input is 1 - the n highest bits are 0 |
var + var | Addition | The two variables are added |
var - var | Subtraction | The second variable is subtracted from the first |
var * var | Multiplication | The two variables are multiplied |
var / var | Integer division | The first variable is divided by the second |
var % var | Modulus | The remainder after dividing the first variable by the second |
Labels and jumps
Labels take the form label name where name can be any combination of lower-case letters — {a,b,…,z} — digits — {0,1,…,9} — and the underscore character.
Jumps take the form jump condition name and jump to the label with name name if the condition is met.
The possible values of condition are:
| Condition | Description |
|---|---|
zero | Jumps if the result of the previous command was 0 |
nonzero | Jumps if the result of the previous command was not 0 |
Note that more conditions may be added to this list as the Bit Bashing section of Safalra’s Website expands.