Bit Bashing Syntax

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:

OperationCommon nameDescription
! varBitwise notA bit in the output is 0 if and only if the corresponding bit in the input is 1
var & varBitwise andA bit in the output is 1 if and only if the corresponding bits in the inputs are both 1
var | varBitwise orA bit in the output is 0 if and only if the corresponding bits in the inputs are both 0
var ^ varBitwise xorA bit in the output is 1 if and only if the corresponding bits in the inputs are different
var << nShift leftA 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 >> nArithmetic shift rightA 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 >>> nLogical shift rightA 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 + varAdditionThe two variables are added
var - varSubtractionThe second variable is subtracted from the first
var * varMultiplicationThe two variables are multiplied
var / varInteger divisionThe first variable is divided by the second
var % varModulusThe 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:

ConditionDescription
zeroJumps if the result of the previous command was 0
nonzeroJumps 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.

This article was last edited on 14th April 2007. The author can be contacted using the form below.
Back to home page
Bookmark with: