[This completes the series on machine language programming for the ZX80. The information in this column works equally well on the ZX81 and TS1000.–EO]
LET A=USR(16427) [16514 for 8K ROM] says “GOSUB machine code routine starting at address 16427.” After the subroutine finishes, control returns to BASIC (unless you forget a RETurn instruction).
Inside the subroutine, however, you can use several instructions for each CALLing and RETurning–one “unconditional” (“Do It!”) and eight “conditional” (“Do it only if x”). Flags hold true-false conditions that may be tested.
For example, if your subroutine completes only if A=0, then use a RET Z instruction, which returns only if Z flag is set (1; True). RET NC returns only if the Carry flag is not set (0; False), and therefore continues without returning if the Carry Flag is set.
CALL instructions work the same way. For example, if your subroutine calls math routines in ROM under certain circumstances (A=9, BC>90, etc.), then test a register with a CP (compare) instruction and CALL Z. The CP instruction sets the Z flag True if A equals the number compared.
Be careful! Not all instructions set the flags as you might expect. For instance, LD A,0 does not affect the Z flag. Z-80 manuals list which instructions affect which flags.
Together, CALLs and RETurns can test flags for:
Zero or Nonzero (Z/NZ) Carry or No carry (C/NC) Parity Odd or Even (PO/PE) Plus or Minus (P/M)