More progress on assembler
This commit is contained in:
parent
dd73644f29
commit
25f988812c
|
@ -0,0 +1,14 @@
|
|||
%swap2 { SWP SWP2 }
|
||||
%swap4 { swap2 swap2 }
|
||||
%swap8 { swap4 swap4 }
|
||||
%swap16 { swap8 swap8 }
|
||||
|
||||
%NOPa2r { NOP2r }
|
||||
|
||||
;Hello { world 2 there 1 testing 10 }
|
||||
|
||||
( references to variables (e.g. Hello.world) not implemented yet )
|
||||
|
||||
NOPa2r
|
||||
swap16
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
%HCF { #0000 DIV }
|
||||
%SHORT_FLAG { #20 }
|
||||
%RETURN_FLAG { #40 }
|
||||
|
||||
( devices )
|
||||
|
||||
|
@ -23,19 +24,49 @@
|
|||
,assembler-heap-start =assembler.heap
|
||||
#0070 =assembler.addr
|
||||
|
||||
,$token ^assemble-token JSR
|
||||
,$token2 ^assemble-token JSR
|
||||
,$token3 ^assemble-token JSR
|
||||
,$token4 ^assemble-token JSR
|
||||
,$token5 ^assemble-token JSR
|
||||
~assembler.state
|
||||
,$read-filename =File.name
|
||||
#1000 =File.length
|
||||
#f000 =File.load
|
||||
|
||||
#f000 #1000 ^assemble-chunk JSR
|
||||
HCF
|
||||
|
||||
$token [ 3b Hello 00 ]
|
||||
$token2 [ 7b 00 ]
|
||||
$token3 [ testing 00 ]
|
||||
$token4 [ 30 00 ]
|
||||
$token5 [ 7d 00 ]
|
||||
$read-filename [ etc/assembler-test.usm 00 ]
|
||||
|
||||
@assemble-chunk ( ptr* len* -- 00 if EOF found in chunk
|
||||
OR assembled-up-to-ptr* 01 if reached end of chunk )
|
||||
OVR2 ADD2 STH2
|
||||
#0001 SUB2
|
||||
|
||||
$per-token
|
||||
DUP2 STH2
|
||||
|
||||
$loop
|
||||
#0001 ADD2
|
||||
DUP2 PEK2
|
||||
#20 GTH ^$loop JNZ
|
||||
|
||||
DUP2 OVR2r STH2r LTS2 ^$valid JNZ
|
||||
SWP2r POP2r POP2
|
||||
STH2r #0001 ADD2
|
||||
#01 JMP2r
|
||||
|
||||
$valid
|
||||
DUP2 PEK2 #00 OVR2 POK2
|
||||
STH2r #0001 ADD2 ^assemble-token JSR
|
||||
^$per-token JNZ
|
||||
|
||||
POP2 POP2r #00 JMP2r
|
||||
|
||||
@assemble-macro ( macro-ptr* -- )
|
||||
DUP2 ,strlen JSR2 DUP2 #0000 EQU2 ^$end JNZ
|
||||
OVR2 ^assemble-token JSR
|
||||
ADD2 #0001 ADD2
|
||||
^assemble-macro JMP
|
||||
|
||||
$end
|
||||
POP2 POP2
|
||||
JMP2r
|
||||
|
||||
@assemble-token ( string-ptr* -- )
|
||||
( get location of tree )
|
||||
|
@ -628,6 +659,7 @@
|
|||
$end
|
||||
DUP ^$loop JNZ
|
||||
POP
|
||||
~assembler.state #0c ORA =assembler.state
|
||||
JMP2r
|
||||
|
||||
(
|
||||
|
@ -656,7 +688,7 @@
|
|||
JMP2r
|
||||
|
||||
@macro-} [ 0000 ] [ 0000 ] [ 7d ]
|
||||
~assembler.heap DUP2 #f0 ROT ROT POK2
|
||||
~assembler.heap DUP2 #00 ROT ROT POK2
|
||||
#0001 ADD2 =assembler.heap
|
||||
~assembler.state #fc AND =assembler.state
|
||||
JMP2r
|
||||
|
@ -687,10 +719,40 @@
|
|||
JMP2r
|
||||
|
||||
@normal-main
|
||||
,$string =Console.string
|
||||
HCF
|
||||
~assembler.token
|
||||
,opcodes-tree OVR2 #03 ,traverse-tree JSR2
|
||||
^$not-opcode JNZ
|
||||
|
||||
$string [ Not 20 implemented 0a 00 ]
|
||||
,opcodes-asm SUB2 #0007 DIV2
|
||||
SWP2 #0003 ADD2
|
||||
$flags
|
||||
DUP2 PEK2
|
||||
DUP #00 EQU ^$end-flags JNZ
|
||||
DUP #32 NEQ ^$not-two JNZ
|
||||
POP SWP2 SHORT_FLAG ORA SWP2 #0001 ADD2 ^$flags JMP
|
||||
$not-two
|
||||
DUP #72 NEQ ^$not-r JNZ
|
||||
POP SWP2 RETURN_FLAG ORA SWP2 #0001 ADD2 ^$flags JMP
|
||||
$not-r
|
||||
POP POP2 ~assembler.token SWP2
|
||||
^$not-opcode JMP
|
||||
|
||||
$end-flags
|
||||
POP POP2
|
||||
,write-byte JSR2
|
||||
POP
|
||||
JMP2r
|
||||
|
||||
$not-opcode
|
||||
POP2
|
||||
,macro-tree SWP2 #ff ,traverse-tree JSR2
|
||||
^$not-macro JNZ
|
||||
,assemble-macro JMP2 ( tail call )
|
||||
|
||||
$not-macro
|
||||
( FIXME complain about bad opcode / nonexistent macro )
|
||||
POP2
|
||||
JMP2r
|
||||
|
||||
(
|
||||
Here's the big set of trees relating to labels. Starting from l-root, all
|
||||
|
|
Loading…
Reference in New Issue