Running MC in a String

Developer(s): Rolf Miller
Date: 1983
Type: Program
Platform(s): ZX81, TS 1000

Shows how to keep machine code in a string, where it SAVEs with the program but is never LISTed. Line 1 sets Z$ to the code in hex. Lines 2-6 convert each pair of hex digits to a byte and POKE it back into the start of Z$ itself, which works because Z$ is the first variable in the variables area. Z$ holds two routines: a 27-byte line renumber and a Syntactic Sum.

Type FAST and RUN; the program stops at line 7. GOTO 9980 renumbers the program in steps of 10 (it does not change GOTOs or GOSUBs). GOTO 9990 prints the Syntactic Sum of the program in memory. The article says “GOTO 9990 to renumber”, but in the listing line 9980 calls the renumber and line 9990 the Syntactic Sum. The sum of the listing as printed is 20610, and after renumbering it is 20570, as the article says.

If you delete lines 1-7 after running, don’t RUN again (RUN clears the variables and the code with them), and don’t assign Z$ again. The code’s address changes if the program or display grows, so don’t use this method when the program’s size changes while the code runs.

Published in Syntax May 1983 (Running MC in a String Variable).

Related Articles

You can place and execute machine code (MC) in three places: REM line, memory reserved above RAMTOP, and a string.

Image Gallery

Source Code

   1 LET Z$="217D40110A00722373234E234623097ED676C8010A00EB09EB18EB217D40ED5B0C40DD2100007CBA20087DBB2004DDE5C1C94E0600DD092318EC"
   2 LET Z=PEEK 16400+PEEK 16401*256+3
   3 FOR A=16518 TO 16633 STEP 2
   4 POKE Z,(PEEK A-28)*16+PEEK (A+1)-28
   5 LET Z=Z+1
   6 NEXT A
   7 STOP
9980 RAND USR (PEEK 16400+PEEK 16401*256+3)
9981 STOP
9990 PRINT USR (PEEK 16400+PEEK 16401*256+30)
9991 STOP

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