Devpac80 Companion cover: MON80, HiSoft's monitor, showing the companion's SUM program disassembled on the Tatung Einstein
← Back to Modules
module
6

What GEN80 Wants

Introduction

The assembly course's S11 printed a message by walking along a string of bytes until it reached a 0. Its strings were written the way z80asm likes them: DEFB 'HELLO ',0. GEN80 does not take that line - and one of the obvious ways of fixing it is a trap. This section rebuilds S11's program and gathers every difference between the two assemblers in one place.

Strings Go In DEFM

GEN80 has two directives for bytes:

  • DEFB takes numbers, and characters one at a time: DEFB "H","E",0.
  • DEFM takes one string: DEFM "HELLO ".

A string after DEFB is Bad expression. So a z80asm string with its 0 on the end becomes two lines:

MSG1:   DEFM "HELLO "
        DEFB 0

The Trap

It is tempting to write that as one line, DEFM "HELLO ",0. GEN80 takes it without a word - and ignores everything after the string. There is no 0. DEFM "AB","CD" is the same: you get AB and nothing else.

The assembler will not tell you. Your program will: a string with no 0 on the end just carries on into whatever comes after it. Try it in Change One Thing below.

Quotes

A single character is written in double quotes: LD A,"H". In single quotes it is Bad expression. DEFM is the one place single quotes work: DEFM 'HELLO' is the same as DEFM "HELLO". It is simplest to use double quotes everywhere.

Labels

  • The colon is optional: PUTS: and PUTS both define a label.
  • Only the first 10 characters count. MESSAGEPART1 and MESSAGEPART2 are the same label to GEN80 - Redefined symbol.
  • Case matters. PUTS and Puts are two different labels.

ORG And Includes

  • No ORG needed. Every program starts at 100h. ORG 256 still works but draws a warning, *WARNING* ORGs used: 01. ORG sets the addresses your code is assembled for - it does not move the code within the file, which always starts with your first instruction.
  • Including a file is *I NAME, starting in the very first column, for a file NAME.GEN on the disc. include 'vdp.asm' is Bad mnemonic, and a *I with spaces in front of it is Symbol is Reserved Word. S8 points you on to splitting a bigger program into files this way.

Everything Else Is The Same

The rest of what you wrote in the assembly course goes through unchanged:

  • numbers in decimal, 41h, 0FFh, 01000001b - and GEN80 also takes #41 and %01000001
  • $ for the current address, EQU, DEFW (low byte first), DEFS (filled with zeros)
  • expressions, with * done before + - so the assembly course's 3800h+9*32+12 means what it did - unary minus, and label arithmetic like MSG+1
  • (HL), (IX+5), (4000h), JR and DJNZ to labels, RST 8 or RST 08h
  • mnemonics in lower case, if you prefer

The Code

S11's program, for GEN80:

; TEXT - THE ASSEMBLY COURSE'S S11

        LD HL,MSG1
        CALL PUTS
        LD HL,MSG2
        CALL PUTS
        RET

; PRINT THE STRING AT HL, UP TO A 0
PUTS:   LD A,(HL)
        CP 0
        RET Z          ; DONE
        RST 8
        DEFB 158       ; ZOUTC
        INC HL
        JR PUTS

MSG1:   DEFM "HELLO "
        DEFB 0
MSG2:   DEFM "WORLD"
        DEFB 0

Edit, assemble and run

ED80 TEXT.GEN

Type it in, CONTROL-K CONTROL-X, ENTER, then:

GEN80 TEXT
TEXT

What you should see

0:TEXT
HELLO WORLD
0:

Change One Thing

  • Join MSG1's two lines into one: MSG1: DEFM "HELLO ",0. GEN80 is happy. What does the program print now, and why that?
  • Change DEFM to DEFB on MSG1's line. What does GEN80 say?
  • Rename MSG1 to MESSAGEPART1 and MSG2 to MESSAGEPART2, everywhere they appear. Which line does GEN80 complain about?
  • Add ZOUTC EQU 158 near the top, and change DEFB 158 to DEFB ZOUTC. Does anything change when it runs?

Summary

Strings go in DEFM, one per line, with the 0 on a DEFB of its own; characters go in double quotes; labels are case-sensitive and count 10 characters; no ORG; *I for includes. Almost everything else is as the assembly course wrote it. Appendix II has the whole list on one page.

Next

S7: watching a program from the inside with MON80.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.