Your place is saved automatically on this browser.
Create tut02.odn using the workflow from Part 1. Type this complete example:
Read it slowly before running. First, A receives $12. Next, CP $12 compares A with the same value, so Z is set. JR NZ,not_equal jumps only if Z is not set, so that jump is not taken. LD B,$01 executes. The unconditional JR done skips over the alternative LD B,$00. Finally HL is set to the familiar inspection address and RET returns to Odin.
Expected state after R: A is $12, B is $01, and HL is $6000 if using the same assembly origin as Tutorial 1. The last comparison made Z set. Odin’s other register values can reflect earlier state because the programme did not initialise them.
Now change only the comparison to cp $13, save and assemble again. A remains $12, but this time Z is clear; the jump to not_equal is taken and B ends as $00.
Common beginner mistake: fall-through
Remove the line jr done on paper, not from your saved working source, and follow the remaining instructions. After B receives $01, execution would continue straight down into the label not_equal and run LD B,$00 as well. The result would be $00 even in the equal case. A label does not stop execution. It merely names a position. This is why the unconditional branch is present.
Inspecting the programme rather than guessing
Save with S; assemble with A; check T for start, not_equal and done; and inspect memory with M $6000. You should see different machine-code lengths for LD, CP and the jumps. The exact branch offsets are the assembler’s job, not something you need to memorise.
