8K/12K Disassembler

Developer(s): Martin Irons (K2MI)
Date: 1983
Type: Cassette
Platform(s): ZX81, TS 1000

A Z80 disassembler written in BASIC. You give it a start address. For each instruction it prints the address, the bytes in decimal and hex, and the mnemonic, with the operands filled in: 8- and 16-bit values, relative jumps shown as an offset and a target address, and the IX and IY indexed forms. Each time the screen fills it waits for input. ENTER carries on, C copies the screen to the printer, Q stops, and typing an address starts again from there. Lines 9920–9944 also hold a small machine code loader for POKEing bytes from the keyboard.

The cassette is a MICRO-80 Incorporated tape with a printed label reading "8k/16k Disassembler "DA1" All Rights Reserved By Martin H. Irons, Goshen, NY". The REM at line 8000 says "SINCLAIR ZX80/ZX81 8K/12K DISASSEMBLER ALL RIGHTS RESERVED MARTIN H. IRONS", and line 8010 reads "12/20/82 MOD 3 12 K". The tape opens with TESTLOAD, a short program for setting the recorder's volume. When it loads, it says so on screen and then loads DA1 automatically: "LEAVE RECORDER RUNNING … DA1 WILL LOAD ITSELF."

The program's own instructions (lines 8100–8190) are: enter GOTO 9000, enter the start address, then use ENTER, C, Q or a new address. Never use RUN, and don't disassemble data, because "IT PRINTS GARBAGE".

Program Analysis

Program Structure

  • Lines 7990–7995: STOP, then SAVE "DA1".
  • Lines 8100–8200: the instructions screen.
  • Lines 9000–9062: the main loop. It prints each address, calls the decimal and hex dump routines, then decodes the opcode. A counter D skips the operand bytes of instructions longer than one byte.
  • Lines 9050–9058: look up the opcode in a table. The first character of each entry is the instruction length. Characters with codes below 21 are placeholders that send control to a formatter at 9200+O*20.
  • Lines 9339–9706: the formatters. They print 16-bit addresses, (IX+d) and (IY+d), (HL), immediate bytes and relative jump targets, and they handle the CB, ED, DD and FD prefixes through their own tables.
  • Lines 9950–9994: subroutines for the decimal dump, hex dump, page prompt and start address.

Notable Techniques

  • Line numbers and constants are kept in variables (GOSUB IP, GOTO PR, C0, C1, C12) or written as VAL "9060", which saves memory on an 8K-ROM machine. This is why the program must never be started with RUN, which would clear those variables.
  • The instruction tables are string arrays. One entry holds the length digit plus the mnemonic text, with control codes marking where operands go. Each table is indexed directly by the opcode byte.
  • Line 9014 tests the scroll counter at 16442 to decide when a screenful has been printed.

Potential Issues

  • The recovered DA1 file is about 2.3 KB and holds no variables. The constants, line-number variables and instruction tables that the program depends on are missing. The program also has no lines below 7990 that could rebuild them. As recovered, it stops with report 2 at line 8200 (GOSUB IP), and Joe's screenshot shows this. A complete copy saved with its variables would be needed to use it.
  • The cassette label says "8k/16k", but the REM says "8K/12K".

Image Gallery

Source Code

7990 STOP
7995 SAVE "DA[1]"
8000 REM    SINCLAIR ZX80/ZX81              8K/12K DISASSEMBLER             ALL RIGHTS RESERVED                                             MARTIN H. IRONS                 46 MAGIC CIRCLE DR.             GOSHEN , NY 10924    
8010 REM    12/20/82  MOD 3 12 K 
8100 PRINT "HOW TO USE THIS DISASSEMBLER:"
8110 PRINT ,,"  1 - INPUT ""GOTO 9000""."
8120 PRINT ,,"  2 - INPUT STARTING ADDRESS."
8130 PRINT ,,"  3 - HIT ENTER TO  CONT , OR "
8140 PRINT ,,"       INPUT ""C"" TO  COPY, OR "
8150 PRINT ,,"       INPUT ""Q"" TO  STOP, OR "
8160 PRINT ,,"       INPUT A NEW ADDRESS."
8170 PRINT ,,"  4 - NEVER RUN THIS PROGRAM."
8180 PRINT ,,"  5 - DO NOT DISASSEMBLE DATA -       IT PRINTS GARBAGE."
8190 PRINT ,,,,"  NOW HIT ENTER TO  GOTO 9000"
8200 GOSUB IP
9000 GOSUB ESA
9001 LET D=C0
9002 FOR I=N TO N+TOP
9005 PRINT I;TAB VAL "6";
9006 GOSUB DEC
9007 GOSUB HX
9008 IF D>C0 THEN GOTO VAL "9060"
9010 GOSUB VAL "9050"
9013 LET D=D-C1
9014 IF PEEK VAL "16442">C2 THEN NEXT I
9016 GOSUB IP
9018 LET N=I+C1
9020 IF Z$="" OR Z$="C" THEN GOTO VAL "9002"
9030 LET N=VAL Z$
9040 GOTO VAL "9001"
9050 IF PEEK I>C0 THEN LET W$=L$(PEEK I)
9051 IF PEEK I=C0 THEN LET W$="1NOP"
9052 LET I1=I+C1
9053 LET D=VAL W$(C1)
9054 LET W$=W$(C2 TO )
9055 IF W$="" THEN GOTO EOL
9056 LET O=CODE W$
9057 IF O>VAL "20" THEN GOTO PR
9058 GOTO VAL "9200"+O*VAL "20"
9060 PRINT 
9062 GOTO VAL "9013"
9339 GOTO PR
9340 PRINT STR$ (PEEK (I+C2)+VAL "256"*(PEEK (I+C3)));
9342 GOTO TR
9384 PRINT "(";X$;"+";PEEK (I+C2);")";
9386 GOTO TR
9400 PRINT "(HL)";
9402 GOTO TR
9420 PRINT "EX (SP),";
9422 GOTO TR
9442 GOTO VAL W$(C2 TO )
9460 PRINT X$;
9462 GOTO TR
9480 PRINT PEEK (I+C3);
9484 GOTO TR
9500 IF PEEK (I+C3)<>VAL "118" THEN LET W$=C$(PEEK (I+C3)+C1)
9502 IF PEEK (I+C3)=VAL "118" THEN LET W$=C$(VAL "120")
9504 GOTO GS
9559 GOTO PR
9560 PRINT STR$ (PEEK (I1));
9564 GOTO TR
9580 IF PEEK (I1)<VAL "128" THEN PRINT "+";STR$ (PEEK (I1));" (";STR$ (I+PEEK (I1)+C2);")";
9582 IF PEEK (I1)>VAL "127" THEN PRINT "-";STR$ (VAL "256"-PEEK (I1));" (";STR$ (I+PEEK (I1)-VAL "254");")";
9586 GOTO TR
9600 PRINT STR$ (PEEK (I1)+VAL "256"*(PEEK (I+C2)));
9604 GOTO TR
9620 PRINT CHR$ O;
9622 LET W$=W$(C2 TO )
9624 GOTO NC
9630 PRINT 
9632 RETURN
9640 LET W$="2RLC B"
9642 IF PEEK (I1)>C0 THEN LET W$=A$(PEEK (I1))
9644 GOTO GS
9660 LET X$="IX"
9662 LET W$=C$(PEEK (I1))
9664 GOTO GS
9680 LET W$=B$(PEEK (I1)-63)
9682 GOTO GS
9700 LET X$="IY"
9702 LET W$=C$(PEEK (I1))
9706 GOTO GS
9920 REM MACHINE LANGUAGE LOADER
9922 INPUT Z$
9924 IF Z$="Q" THEN GOTO END
9926 IF Z$="" THEN GOTO VAL "9942"
9928 IF VAL Z$<VAL "256" THEN GOTO VAL "9938"
9930 LET A=VAL Z$
9932 PRINT AT VAL "21",VAL "31";AT VAL "21",C0;
9933 SCROLL
9934 PRINT AT C12,VAL "8";A,PEEK A;"  "
9936 GOTO VAL "9922"
9938 POKE A,VAL Z$
9940 GOTO VAL "9934"
9942 LET A=A+C1
9944 GOTO VAL "9932"
9950 PRINT (STR$ (PEEK (I)+VAL "1000"))(C2 TO );TAB C10;
9952 RETURN
9960 LET Z$="0123456789ABCDEF"
9962 LET N=PEEK I
9964 LET N1=INT (N/VAL "16")
9966 LET N2=N-N1*VAL "16"
9968 PRINT Z$(N1+C1);Z$(N2+C1);" ";
9970 RETURN
9980 INPUT Z$
9981 IF Z$="Q" THEN GOTO END
9982 IF Z$="C" THEN COPY
9983 CLS
9984 RETURN
9990 CLS
9991 PRINT ,,,,"     INPUT STARTING ADDRESS"
9992 INPUT N
9993 CLS
9994 RETURN
9998 CLS
9999 STOP

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.