Your place is saved automatically on this browser.
Before typing: how to read an assembly source line
Assembly source has a small vocabulary of parts. Learning the names helps us discuss code clearly.
What does 'immediate' mean?
An immediate value is a literal value written directly in the instruction. In LD A,$42, the value $42 is part of the instruction itself. This is different from loading a value from a memory address, which we will learn later.
Comments are part of good assembly programming
Comments explain intent. Assembly instructions can be very compact, so a short comment often saves time later. Comments do not become machine code. As the Next Asset Lab grows, clear comments will be important, but we will avoid comments that merely repeat the instruction.
Create the source
From the Odin Monitor:
NEW creates a new Odin source document. We then use the physical EDIT key to switch from the Monitor to the full-screen editor.
Enter the first small program
Do not rush past these four lines. Each one introduces an idea.
start:
start is a label. A label gives a human-readable name to an address. Labels make assembly source much easier to understand than hard-coding every address.
ld a,$42
This tells the Z80 to place the value $42 into the 8-bit A register. Because A is eight bits wide, a two-digit hexadecimal value is a natural fit.
ld hl,$6000
This tells the Z80 to place the 16-bit value $6000 into the HL register pair. In this exercise we deliberately point HL at the same address where Odin places our code.
ret
RET means return. It tells the CPU to return to the code that called our routine. The exact stack mechanism behind RET will be taught properly later; for now it is enough to know that Odin can call our short routine and RET allows control to come back.
How can RET know where to return?
For now we only need a simple model. When Odin runs our routine, it arranges for a return address to be remembered on the stack. RET takes that saved address and puts it back into the Program Counter, so execution continues in Odin.
The stack, SP, PUSH, POP and CALL deserve a proper lesson of their own. At this stage we only need enough understanding to know that RET is not magic: it uses an address that was previously saved.
Save the native Odin source
Return to the Monitor with EDIT, then enter:
Because the document already has the name tut01.odn, S saves it using that name. LS confirms that the file exists.
