Bit Manipulation & Bitwise Operations

Bitwise Operations

Bitwise Operations Tutorial

 

Instruction Table

Bit Manipulation Instruction Table

Here is the table given by the exam board in the syllabus.

 

Label
Instruction
Explanation
Opcode Operand
AND #n Bitwise AND operation of the contents of ACC with the operand
AND <address> Bitwise AND operation of the contents of ACC with the contents of <address>
XOR #n Bitwise XOR operation of the contents of ACC with the operand
XOR <address> Bitwise XOR operation of the contents of ACC with the contents of <address>
OR #n Bitwise OR operation of the contents of ACC with the operand
OR <address> Bitwise OR operation of the contents of ACC with the contents of <address> (can be an absolute address or a symbolic address)
LSL #n Bits in ACC are shifted logically n places to the left. Zeros are introduced on the right hand end
LSR #n Bits in ACC are shifted logically n places to the right. Zeros are introduced on the left hand end
<label>: <opcode> <operand> Labels an instruction
<label>: <data> Gives a symbolic address to the memory location with contents <data>

Bitwise Operations / Bit Masking

Bit Masking Operations

When computers were first invented processing power was very limited so any tricks that could be used to speed up processing were incredibly useful and as such bit masking was introduced.

Bit Masking allows the checking, setting and resetting individual bits within a binary without having to loop through or involve complicate logic. It could all be achieved at the logic circuit level which meant that the operations were incredibly efficient.

Computers are far more powerful today, however the amount of data our programs process has also increased exponentially, and so in certain circumstances these ‘binary tricks’ can still come in credibly handy. They are also useful in low level control applications where simple systems use individual bits as flags. These systems are often battery/solar power systems so it is also useful to reduce processing as much as possible. Bit masking is also still widely used in networking when using subnet masks.

 

 

Resources