Laboratory4.3 Bit manipulation8-bit registers

Bit-Manipulation Laboratory

Write assembly instructions, run them one step at a time, and watch every register change bit by bit. Each step shows the exact 8-bit result, the bits that changed and the status flags the instruction set.

Perform logical, arithmetic and cyclic shifts on binary values
Use AND, OR and XOR to manipulate bits
Test, set and clear individual bits with bit masks

Watch it before you run it

The coach calls the play

How one coaching instruction becomes a 16-bit word the machine can run

4.2Kick-off · stored program1 / 6program → main memory

Tactics board · the coach's call

12345678PLAYBOOK · MEMORY100 LDM #5101 ADD #3102 STO 200COACH · CONTROL UNITNothing called yet,the book stays shutSCOREBOARD · ACC0latest result

Machine · instruction format

000000000000000016-bit instruction wordPCnext address0x0064MARaddress in use0x0000MDRword in transit0x0000CIRinstruction0x0000ACCresult0x0000ADDRESS BUSDATA BUSCONTROL BUSMAIN MEMORY · one word per cell100LDM #50x0105101ADD #30x0203102STO 2000x03C8103END0x0000left = opcode · right = operand, joined as one 16-bit word

Coach · Kick-off, the playbook is on the bench

The squad has not learned the playbook by heart. Every play sits in the book until the coach calls it, and only the called play is ever used.

Machine · Stored program concept

Instructions and data both sit in main memory as binary. The processor holds no instructions of its own until one is fetched, which is why the same CPU can run any program.

stored-program conceptvon Neumann architecturemain memory
Pace

Every word shown here is 16 bits: opcode in the top eight, operand in the bottom eight. Click a step to jump straight to it.

Program

One instruction per line · values as 12, 0x0C or 0b00001100 · comments start with ;

OR with a mask forces the masked bits to 1 and leaves every other bit alone.

0 of 4 instructions executed

Experiments

Try these in the lab

Instruction set

The subset of the 9618 assembly language this laboratory executes.

LDILoad a fixed 8-bit value into a register

LDI R0, 0b10101010

MOVCopy a register or value into a register

MOV R1, R0

ANDBitwise AND with a register or value

AND R0, 0b00001111

ORBitwise OR with a register or value

OR R0, 0b00001111

XORBitwise XOR with a register or value

XOR R0, 0b00001111 · also written EOR

NOTInvert every bit of the register

NOT R0

LSLLogical shift left by n places (carry = last bit out)

LSL R0, 2

LSRLogical shift right by n places (carry = last bit out)

LSR R0, 2

ADDADD a register or value

ADD R0, 1

SUBSUB a register or value

SUB R0, 1

INCINC the register by one

INC R0

DECDEC the register by one

DEC R0

CMPCompare without storing — sets N, Z, C and V

CMP R0, 0b00100000

ENDStop execution

END

Registers · 8-bit

click a bit to flip it

76543210
hexdenary
R0
0x000
R1
0x000
R2
0x000
R3
0x000
R4
0x000
R5
0x000
R6
0x000
R7
0x000

Status register

N 0Z 0C 0V 0N negative · Z zero · C carry out · V signed overflow

Execution trace

0 steps

Press Step to execute the first instruction. Each entry shows the instruction, the binary result and the registers it changed.

Trace table

One row per executed instruction · click any row to rewind the machine to that step

step 0

Press Play or Step and every instruction will appear here as a row, with the full register state after it runs.

Cambridge International AS & A Level Computer Science 9618 · for examination 2027–2029

Part of StoreySniper.com · original teaching material