Skip to content

Machine Code for Beginners

Usborne's 48-page guide to the Z80 and the 6502

Usborne's 1983 picture-book introduction to machine code taught the Z80 and the 6502 side by side, for the Spectrum, ZX81, VIC-20, BBC Micro, Atari, Oric and Commodore 64. Readers wrote mnemonics, looked up the hex by hand and poked it in with a BASIC hex loader. Sinclair User called it the easiest book on the subject on the market.

Most machine code books of 1983 were written for one computer and assumed the reader already knew BASIC well. Usborne’s Machine Code for Beginners was 48 pages long, cost £1.99, was drawn like a comic, and set out to teach two different processors at once. Every program in it comes twice, once for the Z80 and once for the 6502, so the same book served a child with a ZX Spectrum and a friend with a BBC Micro or a VIC-20. Sinclair User thought a junior-school child could learn from it, and called the way it tackled the subject “nothing short of brilliant”.

It was honest about the job. “Machine code is difficult and very laborious, with lots of rules to obey and small details to remember,” the introduction warns. “Don’t worry if you find it very hard at first.”

Fast facts

  • Authors: Lisa Watts and Mike Wharton.
  • Pictures and design: illustrated by Naomi Reed and Graham Round; designed by Graham Round and Lynne Norman.
  • 6502 consultants: A. P. Stephenson and Chris Oxlade.
  • Published: 1983, by Usborne Publishing, London; an American paperback from EDC Publishing followed in January 1984.
  • Length: 48 pages, including the index.
  • Processors: the Z80 and the 6502, side by side.
  • Machines named: the Spectrum and ZX81 (and their American Timex versions, the Timex 2000 and 1000), the VIC-20, BBC Micro, Atari computers and Oric, and the Commodore 64, whose 6510 “understands 6502 machine code”.
  • Price: £1.99.
  • Free download: one of fifteen Usborne computer books released as free PDFs in February 2016.

One book, two processors

The book explains the split on its first page. “Computers with different microprocessors understand different machine code. All computers with the same type of microprocessor, though, use the same machine code.” So it picked the two families that between them covered most British home computers, and printed each program in both. A footnote lets the reader off half the work: “From now on, if you have a Z80 you can skip over the 6502 programs and if your computer uses 6502 instructions, ignore the Z80 programs.”

The book works up from the bottom. It opens inside the case, with the ROM, the RAM, the clock crystal and the buses, then explains the memory as “lots of little boxes”, each with an address. Hex numbers come next, then PEEK and POKE, the registers of each processor, and the instruction set. Later pages cover addressing modes (immediate, absolute, indirect and indexed), the carry flag and two-byte arithmetic, comparisons and the zero flag, jumps, conditional branches, the stack and subroutine calls, and two’s complement for working out backward branches. Conversion charts, the opcode tables for both processors and a glossary of “machine code words” fill the back pages.

Writing code by hand

There is no assembler in the book. Readers wrote a program as mnemonics, looked up each instruction’s hex code in the tables at the back, and typed the codes into a short BASIC “hex loader”, which turned each pair of hex digits into a number and POKEd it into memory. The first program adds 2 and 4 and stores the answer. On the 6502 it is four instructions:

Code
LDA #&02    A9 02
ADC #&04    69 04
STA address 8D lb hb
RTS         60

The book’s own warning applies here: a 6502 adds the carry flag too, and the book explains a few pages later that “it is important to clear the carry flag using the instruction CLC” before an addition. Its first listing leaves the CLC out.

Before any of this, the reader had to make room. The book shows how to lower the top of BASIC’s memory on each machine (CLEAR on the Spectrum, HIMEM on the Oric, two POKEs on the VIC-20), and gives the ZX81 trick of filling a REM statement at the start of the program with one digit per byte, then POKEing the machine code over the digits. Running the code took the machine’s own command, “CALL, others use PRINT USR or SYS”.

The longest program is a screen flash that swaps two blocks of the display, “a flashing effect” that “shows how simple animation works”. The 6502 version uses indexed addressing, counting X down to zero, and branches back with D0 EF: EF is the two’s complement of 17, the number of bytes back to the second instruction. The Z80 version uses HL and DE as pointers and B as a counter. A delay loop in BASIC slows it down, “because the machine code is so fast”. Spectrum owners got a note of caution elsewhere: the message-printing program would not give “a legible message on the screen because of the way the screen memory is organized”.

The pictures

Sinclair User’s John Gilbert reviewed the book in March 1984 and reprinted the review in the magazine’s 1985 annual. “The title may deter you and you may think it is just another machine code book but it is the easiest book on the subject on the market.” He liked its cast: “The cartoon characters, such as robots and bugs, which are included, teach machine code in a subtle manner. It is possible to read the book as a comic strip, taking little account of the main text and still derive a knowledge of assembly and machine language.” That both processor families were covered was, he wrote, “an extra bonus”.

The book did not claim to be the last word. Its “Going further” page sends readers on to Rodnay Zaks’s Programming the Z80 and Programming the 6502 (“not easy to read for beginners, but they are useful for reference”), Commodore’s VIC 20 Programmer’s Reference Guide, and 6502 Machine Code for Beginners by A. P. Stephenson, one of the book’s own consultants. It also recommends buying an assembler, which “makes machine code programming much easier”, and notes that the BBC Micro had one built in.

Later life

The book stayed in print and in demand. In March 1987 ZX Computing closed a machine code tutorial by telling readers they “could do much worse than to buy ‘Machine Code for Beginners’ published by Usborne at a mere £1.99”, which would “gently fill in much background material”. In February 2016 Usborne made it one of fifteen of its 1980s computer books free to download as PDFs. The Usborne computing books entry covers the whole range, and From BASIC to machine code follows the book’s first routine on a Spectrum.

Sources

  • Lisa Watts and Mike Wharton, Machine Code for Beginners (Usborne, 1983): title page and imprint; “About this book” and its footnote on machines; “Getting to know your computer”, pp. 6–7; “The computer’s memory”, p. 8; “A simple program”, p. 17 and its footnote; the hex loader, p. 24; running a program, p. 25; lowering the top of RAM and the VIC-20 and ZX81 tips, pp. 20–22; the carry flag and CLC, p. 29; the message program and the Spectrum note, p. 32; subroutines and the stack, pp. 35–36; conditional branches and two’s complement, pp. 36–37; screen flash program, pp. 38–39; “Going further” and suggested books, p. 40.
  • Sinclair User issue 24, March 1984, p. 99: John Gilbert, books column (the review quoted). The same review appears in the Sinclair User Annual 1985, in Gilbert’s survey of 1984’s computer books.
  • ZX Computing Monthly, March 1987: machine code tutorial recommending the book at £1.99.
  • Your Computer, November 1982: Newnes advertisement listing A. P. Stephenson’s 6502 Machine Code for Beginners as forthcoming.
  • Open Library, work OL6669547W (web, secondary): the London 1983 edition and the EDC Publishing paperback of January 1984. https://openlibrary.org/works/OL6669547W
  • Shaun Nichols, “Ready for a nostalgia kick? Usborne has put its old computer books on the web for free”, The Register, 9 February 2016 (web, secondary): Machine Code for Beginners among the fifteen titles. https://www.theregister.com/2016/02/09/usborne_programming_books_now_free/

See also

Checked. Verified against primary sources and signed off by a person.