My assembler RASM (so called RoboAssembler that I started in January 1997) has external table file where you can write rules to convert assembler instructions to sequence of bytes - some of such rules are simple and straightforward:
ADD_R0,-1 #00 #1F
ADD_R0,R0 #01 #00
MOV_[R0,R0],R0 #0A #00
As you can see every 12-bit instruction is represented by 2 bytes (higher byte 1st, lower byte 2nd and sorry I can't support [R0:R0] because colon : means label in RASM and instruction prefixes may not have spaces inside so that's why it's having _ in it)
And some rules have logic inside the code of RASM. For example relative jumps were already supported in code when I implemented 8086 support about 20 years ago.
JR #0F B
RASM already knows that if we put label as argument of such instruction it will calculate offset:
LABELUP:
ADD_R0,R0
JR LABELUP
JR LABELDOWN
MOV_[R0,R0],R0
LABELDOWN:
ADD_R0,-1
will assemble into
000 01 LABELUP: ADD_R0,R0
00
001 0F JR LABELUP
FE
002 0F JR LABELDOWN
01
003 0A MOV_[R0,R0],R0
00
004 00 LABELDOWN: ADD_R0,-1
1F
Some instructions will require to add more logic into RASM to support new rules, for example 4-bit argument should be summarized with 2nd byte of instruction in some cases - such rule in table file may look like this:
ADD_R0, #00 #10+
That means that ADD_R0, 1 should be translated into #00 #11 and for example ADD_R0, 12 into #00 #1C etc.
Also we need to add some logic that in case of label as an argument of such instruction will take 4 lower bits of the label to implement MOV_PCL, label
Long jumps and long calls most likely should be converted to pair of instructions transparently and invisibly for user:
JMP #0E B #09 #D0+ // MOV_PC,(LBL>>4) MOV_PCL,LBL&15
CALL #0E B #09 #C0+ // MOV_PC,(LBL>>4) MOV_JSR,LBL&15
Also RASM is not able to support instructions looking like MOV [NN],R0 and MOV R0,[NN] so instead I'll add new aliases for these two: SR0 NN (Save R0) and LR0 NN (Load R0).
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.