Luc Pauwels

The Assembler AS

Jürgen Koslowski

Hi folks,

By popular demand, here is the assembler AS I mentioned in my last posting. Recall Friedrich Schroeder's assembler ASS

  ASS [87E2]
  << -> lm
    << HEX "" 1 lm SIZE
       FOR i
         "#" lm i DUP2 1 + DUP SUB 3 ROLLD
         DUP SUB + + STR-> B->R CHR + 2
       STEP
       #3CEAA SYSEVAL
    >>
  >>
and Alonzo Gariepy's partial assembler HEXIFY
        HEXIFY [6AC9]
        << "" SWAP 1 OVER SIZE
        FOR j
                "#" OVER j 1 + DUP SUB + OVER j j SUB + "h" +
                STR-> B->R CHR ROT SWAP + SWAP 2
        STEP DROP
        >>
What I liked about HEXIFY was that it does not change the mode to HEX (even though my computer is nearly always set to HEX anyway.) Also, the avoidance of a local variable saves some space. ASS, on the other hand uses the very neat trick #3CEAA SYSEVAL, which avoids putting the string into memory and essentially running it. It simply moves the pointer D1 10 nybbles further so the string prolog and the size information are no longer read. So the string produced in the loop is not moved about at all! For good measure, I've also thrown FAST in, to speed the loop up.
  AS [EB91]
  <<
     FAST
     "" SWAP 1 OVER SIZE
     FOR j
           "#" OVER J 1 + DUP SUB + OVER j DUP SUB + "h" +
           STR-> B->R CHR ROT SWAP + SWAP 2
     STEP DROP
     System Object
  >>
The System Object at the end is the result of applying the techniques described in my last contribution to the string "AAEC3". You can key in the program with an arbitrary instruction in place of the System Object, place the program in level 3 of the stack, put 35 into level 2, and then "AAEC3" in level 1. Then run your old assembler on this string to get a System Object, and execute 'pP" to put it into the program replacing the previous instruction in position 35.

You must have some other assembler before you can build this one! Replacing the System Object with #3CEAA SYSEVAL will give you one. Having 'pP' or something similar around would be helpful as well.

Finally, if you are byte-conscious, you could strip off the outer brackets << and >>. An easy and fast way of doing that is to use the following program:

  vV [C7A0]
  <<
     DUP
     System Object 1 - 2 SWAP
     System Object
  >>
The first System Object is generated by assembling the string "E3970"; it finds the size of a composite structure in level 1. The second one comes from "E6870"; it produces a substructure of the object in level 3, with beginning and end specified in levels 2 and 1, respectively.

Recall the program you want to strip the << and the >> off of to level 1 and execute 'vV'. This saves 5 bytes per program.

Any comments or suggestions are welcome.

Jürgen Koslowski
Dept. of Math. & Comp. Sci.
Macalester College
St. Paul, MN 55105-1899