Assembler generates OPL output

Use this section to showcase your programming examples. Or to ask members for programming suggestions
Post Reply
amenjet
Posts: 179
Joined: Tue Jan 03, 2023 7:54 pm

Assembler generates OPL output

Post by amenjet »

I've just added a feature to the 6303 Psion macro assembler (https://github.com/blackjetrock/psion-org2-assembler) that outputs OPL code with the assembled machine code in it. It might be useful to someone...

So, if you have this example code:

Code: Select all

       MUL      ;Multiplies A and B together.
       XGDX     ;Put result in X	;
	 
       RTS   ;Return
and you assemble it, you get (as well as other output files), a file with this in it:

Code: Select all

mult%:(M%,N%)
LOCAL MC$(3)
MC$=CHR$($3d)
MC$=MC$+CHR$($18)
MC$=MC$+CHR$($39)
RETURN USR(ADDR(MC$)+1,M%*256+N%)
It's easily customised by altering the assembler Tcl source.

Andrew
Lostgallifreyan
Posts: 83
Joined: Thu Jan 12, 2023 8:25 pm

Re: Assembler generates OPL output

Post by Lostgallifreyan »

If you want to do it for larger programs, instead of using OPL string extension which is slow, you could call this:

Code: Select all

BYTES:(A%,H$)
REM CODE:18EC02DD43EE00DF414FE6003A54DD4509EC00814025028007C1402502C00748484848C40F1B36099C4122E4DE43D64632A700085A26F9DE4539
LOCAL C$(58),S$(255),V%(2)
C$="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
S$=H$ :V%(1)=ADDR(S$) :V%(2)=A%
RETURN USR(ADDR(C$)+1,ADDR(V%()))
When that is translated to OB3, replacing the string of XXXXX... with the hex code in the comment will make a procedure that can stow an arbitrary string of code or data input by H$ anywhere you can point it to by the input A%. The reason for this weird method is that the procedure cannot build itself. :) Once you have it transferred to an Organiser pack, it will solve (or in a moment of misguided boredom, cause) some tough problems.

It can replace both POKCNV% and CONV$ when working with machine code in OPL.

If anyone wants to see a full listing of the ASM (and more explanation of why I did it) there's one on my site at lostgallifreyan.org in the software section.
Post Reply