Student worksheet

Bits and Representation

Three lesson sections: predict, build, explain. Work on paper or in the local lab. No name, account or student record is requested by the app.

22. Bit Masks and Flags

Select individual bits with AND and set them with OR.

Open this lesson →

1. Predict and trace

Before running the Try program, predict its output and trace the first three executed instructions. Track the relevant registers, flags or memory as needed. Then step the program to compare.

LOAD 13
AND 5
PRINT
OR 2
PRINT
HALT

Queue input: None

Initialize memory: All bytes initially zero

InstructionPC beforePC afterR0 beforeR0 afterRelevant stateOutput
       
       
       

2. Build and check

Read a byte from 0 through 255. Print only its bits 0 and 2 as a numeric mask, using AND 5.

Required instruction types: INPUT, AND

Starter program

INPUT
# Keep bits 0 and 2.
PRINT
HALT

Your program and notes

3. Explain the machine

What does the mask5 select?