fix bugs, hello world assembles
This commit is contained in:
parent
e601535399
commit
e1c6771fe1
11
asm.qf
11
asm.qf
|
@ -32,7 +32,7 @@ OP_SREG mkreg sreg
|
||||||
2 + ;
|
2 + ;
|
||||||
|
|
||||||
: match-impl ( optypes opcount -- b )
|
: match-impl ( optypes opcount -- b )
|
||||||
begin dup > 0 while
|
begin dup 0 > while
|
||||||
1 - 2dup + @ over optypes + @ !=
|
1 - 2dup + @ over optypes + @ !=
|
||||||
if drop drop 0 ret then
|
if drop drop 0 ret then
|
||||||
repeat drop drop 1 ;
|
repeat drop drop 1 ;
|
||||||
|
@ -44,7 +44,6 @@ OP_SREG mkreg sreg
|
||||||
if execute drop assembled ret else drop then
|
if execute drop assembled ret else drop then
|
||||||
repeat drop 1 message yelp ;
|
repeat drop 1 message yelp ;
|
||||||
|
|
||||||
: do.data ( cp -- data ) 2 + ;
|
|
||||||
: inst-nextimpl do.data 1 + ;
|
: inst-nextimpl do.data 1 + ;
|
||||||
: inst-opcount do.data @ ;
|
: inst-opcount do.data @ ;
|
||||||
|
|
||||||
|
@ -58,8 +57,14 @@ OP_SREG mkreg sreg
|
||||||
2 inst mov
|
2 inst mov
|
||||||
2 inst movb
|
2 inst movb
|
||||||
|
|
||||||
: outw! dup &hff and outb! 256 / outb! ;
|
|
||||||
OP_IMM OP_REG16 :noname &hb8 op1 + outb! op2 outw! ; ' mov impl
|
OP_IMM OP_REG16 :noname &hb8 op1 + outb! op2 outw! ; ' mov impl
|
||||||
OP_IMM OP_REG8 :noname &hb0 op1 + outb! op2 outb! ; ' movb impl
|
OP_IMM OP_REG8 :noname &hb0 op1 + outb! op2 outb! ; ' movb impl
|
||||||
|
|
||||||
|
1 inst push
|
||||||
|
OP_SREG :noname &h06 op1 8 * + outb! ; ' push impl
|
||||||
|
OP_REG16 :noname &h50 op1 + outb! ; ' push impl
|
||||||
|
1 inst pop
|
||||||
|
OP_SREG :noname &h07 op1 8 * + outb! ; ' pop impl
|
||||||
|
OP_REG16 :noname &h58 op1 + outb! ; ' pop impl
|
||||||
|
|
||||||
|
|
||||||
|
|
5
boot.qf
5
boot.qf
|
@ -1,7 +1,8 @@
|
||||||
: debug word@ yelp ;
|
: debug word@ yelp ;
|
||||||
: here 0 @ ;
|
: here 0 @ ;
|
||||||
: here! 0 ! ;
|
: here! 0 ! ;
|
||||||
: != not = ;
|
: != = not ;
|
||||||
|
: outw! dup &hff & outb! 256 / &hff & outb! ;
|
||||||
|
|
||||||
: if ' jz_ , here 0 , ; immediate
|
: if ' jz_ , here 0 , ; immediate
|
||||||
: then here over - swap ! ; immediate
|
: then here over - swap ! ; immediate
|
||||||
|
@ -36,6 +37,8 @@ var does.patch
|
||||||
: makedo word@ create ' $do , here does.patch ! -1 , ;
|
: makedo word@ create ' $do , here does.patch ! -1 , ;
|
||||||
: does> here 3 + lit :| does.patch @ ! rdrop |; , ; immediate
|
: does> here 3 + lit :| does.patch @ ! rdrop |; , ; immediate
|
||||||
|
|
||||||
|
: do.data ( cp -- data ) 2 + ;
|
||||||
|
|
||||||
: $defer r> @ >r ;
|
: $defer r> @ >r ;
|
||||||
: defer word@ create ' $defer , :| |; , ;
|
: defer word@ create ' $defer , :| |; , ;
|
||||||
: redef 1 + ! ;
|
: redef 1 + ! ;
|
||||||
|
|
17
in.asm
17
in.asm
|
@ -1,6 +1,15 @@
|
||||||
\ The simplest possible COM file: just return 1
|
: .EXIT ax &h4c00 | # mov &h21 int ;
|
||||||
|
: d" begin in@ dup [ in@ " lit ] != while outb! repeat drop ;
|
||||||
|
|
||||||
\ 1 trace
|
cs push \ copy code segment to data segment
|
||||||
\ mov \ should fail and yelp
|
ds pop
|
||||||
ax &h4c01 # mov
|
|
||||||
|
tell 1 + dx 0 # mov
|
||||||
|
ah 9 # movb
|
||||||
&h21 int
|
&h21 int
|
||||||
|
|
||||||
|
0 .EXIT
|
||||||
|
|
||||||
|
tell
|
||||||
|
d" Hello World!$"
|
||||||
|
&h100 + swap seek outw!
|
||||||
|
|
15
qf.bas
15
qf.bas
|
@ -90,6 +90,8 @@ CONST O.BITAND = -32
|
||||||
CONST O.BITOR = -33
|
CONST O.BITOR = -33
|
||||||
CONST O.MESSAGE = -34
|
CONST O.MESSAGE = -34
|
||||||
CONST O.TRACE = -35
|
CONST O.TRACE = -35
|
||||||
|
CONST O.TELL = -36
|
||||||
|
CONST O.SEEK = -37
|
||||||
|
|
||||||
CONST P.HERE = 0
|
CONST P.HERE = 0
|
||||||
CONST P.LATEST = 1
|
CONST P.LATEST = 1
|
||||||
|
@ -166,6 +168,8 @@ CALL opcode("*", O.MUL)
|
||||||
CALL opcode("/", O.DIV)
|
CALL opcode("/", O.DIV)
|
||||||
CALL opcode("<", O.LT)
|
CALL opcode("<", O.LT)
|
||||||
CALL opcode("=", O.EQ)
|
CALL opcode("=", O.EQ)
|
||||||
|
CALL opcode("&", O.BITAND)
|
||||||
|
CALL opcode("|", O.BITOR)
|
||||||
CALL opcode("jz_", O.JZ)
|
CALL opcode("jz_", O.JZ)
|
||||||
CALL opcode("jmp_", O.JMP)
|
CALL opcode("jmp_", O.JMP)
|
||||||
CALL opcode(">r", O.RPUSH)
|
CALL opcode(">r", O.RPUSH)
|
||||||
|
@ -177,6 +181,9 @@ CALL opcode(",", O.COMMA)
|
||||||
CALL opcode("message", O.MESSAGE)
|
CALL opcode("message", O.MESSAGE)
|
||||||
CALL opcode("yelp", O.YELP)
|
CALL opcode("yelp", O.YELP)
|
||||||
CALL opcode("trace", O.TRACE)
|
CALL opcode("trace", O.TRACE)
|
||||||
|
CALL opcode("seek", O.SEEK)
|
||||||
|
CALL opcode("tell", O.TELL)
|
||||||
|
|
||||||
CALL assemble("<rot", ">rot >rot ret")
|
CALL assemble("<rot", ">rot >rot ret")
|
||||||
CALL assemble("over", "swap dup >rot ret")
|
CALL assemble("over", "swap dup >rot ret")
|
||||||
CALL assemble("2dup", "over over ret")
|
CALL assemble("2dup", "over over ret")
|
||||||
|
@ -208,7 +215,7 @@ SUB execute (op%)
|
||||||
IF trace% > 0 AND tracevm THEN
|
IF trace% > 0 AND tracevm THEN
|
||||||
tp$ = "N/A"
|
tp$ = "N/A"
|
||||||
IF sp > 0 THEN tp$ = STR$(top)
|
IF sp > 0 THEN tp$ = STR$(top)
|
||||||
PRINT #trace%, "ip:"; ip; " sp:"; sp; " rp:"; rsp; " tp:"; tp$; " fn:"; guessdef$(ip); " op:"; lookupop$(op%);
|
PRINT #trace%, "ip:"; ip; " sp:"; sp; " rp:"; rsp; " tp:"; tp$; " fn:"; guessdef$(ip); " op:"; lookupop$(op%)
|
||||||
END IF
|
END IF
|
||||||
SELECT CASE op%
|
SELECT CASE op%
|
||||||
CASE IS >= 0
|
CASE IS >= 0
|
||||||
|
@ -257,6 +264,11 @@ SUB execute (op%)
|
||||||
CASE O.OUT
|
CASE O.OUT
|
||||||
byte$ = CHR$(pop)
|
byte$ = CHR$(pop)
|
||||||
PUT #1, , byte$
|
PUT #1, , byte$
|
||||||
|
CASE O.TELL
|
||||||
|
CALL push(SEEK(1) - 1)
|
||||||
|
CASE O.SEEK
|
||||||
|
SEEK #1, pop + 1
|
||||||
|
|
||||||
CASE O.LOOKUP
|
CASE O.LOOKUP
|
||||||
istr% = pop
|
istr% = pop
|
||||||
iword = lookup(strings$(istr%))
|
iword = lookup(strings$(istr%))
|
||||||
|
@ -404,6 +416,7 @@ SUB interpret (st$)
|
||||||
END SUB
|
END SUB
|
||||||
|
|
||||||
SUB loadfile (filename$)
|
SUB loadfile (filename$)
|
||||||
|
PRINT "Building "; filename$
|
||||||
inline% = 0
|
inline% = 0
|
||||||
OPEN filename$ FOR INPUT AS #2
|
OPEN filename$ FOR INPUT AS #2
|
||||||
WHILE EOF(2) = 0
|
WHILE EOF(2) = 0
|
||||||
|
|
386
trace.txt
386
trace.txt
|
@ -1,346 +1,52 @@
|
||||||
read: array
|
|
||||||
read: ops
|
|
||||||
read: 2
|
|
||||||
read: allot
|
|
||||||
read: array
|
|
||||||
read: optypes
|
|
||||||
read: 2
|
|
||||||
read: allot
|
|
||||||
read: var
|
|
||||||
read: currop
|
|
||||||
read: :
|
read: :
|
||||||
read: op1
|
read: .EXIT
|
||||||
read: ops
|
|
||||||
read: @
|
|
||||||
read: ;
|
|
||||||
read: :
|
|
||||||
read: op2
|
|
||||||
read: ops
|
|
||||||
read: 1
|
|
||||||
read: +
|
|
||||||
read: @
|
|
||||||
read: ;
|
|
||||||
read: 0
|
|
||||||
read: const
|
|
||||||
read: OP_NONE
|
|
||||||
read: 1
|
|
||||||
read: const
|
|
||||||
read: OP_REG8
|
|
||||||
read: 2
|
|
||||||
read: const
|
|
||||||
read: OP_REG16
|
|
||||||
read: 3
|
|
||||||
read: const
|
|
||||||
read: OP_SREG
|
|
||||||
read: 4
|
|
||||||
read: const
|
|
||||||
read: OP_IMM
|
|
||||||
read: :
|
|
||||||
read: op!
|
|
||||||
read: (
|
|
||||||
read: currop
|
|
||||||
read: @
|
|
||||||
read: >r
|
|
||||||
read: optypes
|
|
||||||
read: r@
|
|
||||||
read: +
|
|
||||||
read: !
|
|
||||||
read: ops
|
|
||||||
read: r@
|
|
||||||
read: +
|
|
||||||
read: !
|
|
||||||
read: 1
|
|
||||||
read: r>
|
|
||||||
read: +
|
|
||||||
read: currop
|
|
||||||
read: !
|
|
||||||
read: ;
|
|
||||||
read: :
|
|
||||||
read: assembled
|
|
||||||
read: 0
|
|
||||||
read: currop
|
|
||||||
read: !
|
|
||||||
read: ;
|
|
||||||
read: :
|
|
||||||
read: mkreg
|
|
||||||
read: makedo
|
|
||||||
read: ,
|
|
||||||
read: does>
|
|
||||||
read: @
|
|
||||||
read: swap
|
|
||||||
read: makedo
|
|
||||||
read: ,
|
|
||||||
read: ,
|
|
||||||
read: does>
|
|
||||||
read: dup
|
|
||||||
read: @
|
|
||||||
read: swap
|
|
||||||
read: 1
|
|
||||||
read: +
|
|
||||||
read: @
|
|
||||||
read: op!
|
|
||||||
read: ;
|
|
||||||
read: OP_REG8
|
|
||||||
read: mkreg
|
|
||||||
read: reg8
|
|
||||||
read: OP_REG16
|
|
||||||
read: mkreg
|
|
||||||
read: reg16
|
|
||||||
read: OP_SREG
|
|
||||||
read: mkreg
|
|
||||||
read: sreg
|
|
||||||
read: 0
|
|
||||||
read: reg16
|
|
||||||
read: ax
|
read: ax
|
||||||
read: 0
|
read: &h4c00
|
||||||
read: reg8
|
read: |
|
||||||
read: al
|
|
||||||
read: 4
|
|
||||||
read: reg8
|
|
||||||
read: ah
|
|
||||||
read: 1
|
|
||||||
read: reg16
|
|
||||||
read: cx
|
|
||||||
read: 1
|
|
||||||
read: reg8
|
|
||||||
read: cl
|
|
||||||
read: 5
|
|
||||||
read: reg8
|
|
||||||
read: ch
|
|
||||||
read: 2
|
|
||||||
read: reg16
|
|
||||||
read: dx
|
|
||||||
read: 2
|
|
||||||
read: reg8
|
|
||||||
read: dl
|
|
||||||
read: 6
|
|
||||||
read: reg8
|
|
||||||
read: dh
|
|
||||||
read: 3
|
|
||||||
read: reg16
|
|
||||||
read: bx
|
|
||||||
read: 3
|
|
||||||
read: reg8
|
|
||||||
read: bl
|
|
||||||
read: 7
|
|
||||||
read: reg8
|
|
||||||
read: bh
|
|
||||||
read: 4
|
|
||||||
read: reg16
|
|
||||||
read: sp
|
|
||||||
read: 5
|
|
||||||
read: reg16
|
|
||||||
read: bp
|
|
||||||
read: 6
|
|
||||||
read: reg16
|
|
||||||
read: si
|
|
||||||
read: 7
|
|
||||||
read: reg16
|
|
||||||
read: di
|
|
||||||
read: 0
|
|
||||||
read: sreg
|
|
||||||
read: es
|
|
||||||
read: 1
|
|
||||||
read: sreg
|
|
||||||
read: cs
|
|
||||||
read: 2
|
|
||||||
read: sreg
|
|
||||||
read: ss
|
|
||||||
read: 3
|
|
||||||
read: sreg
|
|
||||||
read: ds
|
|
||||||
read: :
|
|
||||||
read: #
|
|
||||||
read: OP_IMM
|
|
||||||
read: op!
|
|
||||||
read: ;
|
|
||||||
read: :
|
|
||||||
read: read-impl
|
|
||||||
read: (
|
|
||||||
read: dup
|
|
||||||
read: @
|
|
||||||
read: swap
|
|
||||||
read: dup
|
|
||||||
read: 1
|
|
||||||
read: +
|
|
||||||
read: @
|
|
||||||
read: swap
|
|
||||||
read: 2
|
|
||||||
read: +
|
|
||||||
read: ;
|
|
||||||
read: :
|
|
||||||
read: match-impl
|
|
||||||
read: (
|
|
||||||
read: begin
|
|
||||||
read: dup
|
|
||||||
read: >
|
|
||||||
read: 0
|
|
||||||
read: while
|
|
||||||
read: 1
|
|
||||||
read: -
|
|
||||||
read: 2dup
|
|
||||||
read: +
|
|
||||||
read: @
|
|
||||||
read: over
|
|
||||||
read: optypes
|
|
||||||
read: +
|
|
||||||
read: @
|
|
||||||
read: !=
|
|
||||||
read: if
|
|
||||||
read: drop
|
|
||||||
read: drop
|
|
||||||
read: 0
|
|
||||||
read: ret
|
|
||||||
read: then
|
|
||||||
read: repeat
|
|
||||||
read: drop
|
|
||||||
read: drop
|
|
||||||
read: 1
|
|
||||||
read: ;
|
|
||||||
read: :
|
|
||||||
read: inst
|
|
||||||
read: (
|
|
||||||
read: makedo
|
|
||||||
read: ,
|
|
||||||
read: 0
|
|
||||||
read: ,
|
|
||||||
read: does>
|
|
||||||
read: dup
|
|
||||||
read: @
|
|
||||||
read: currop
|
|
||||||
read: @
|
|
||||||
read: !=
|
|
||||||
read: if
|
|
||||||
read: 0
|
|
||||||
read: message
|
|
||||||
read: yelp
|
|
||||||
read: ret
|
|
||||||
read: then
|
|
||||||
read: 1
|
|
||||||
read: +
|
|
||||||
read: @
|
|
||||||
read: begin
|
|
||||||
read: dup
|
|
||||||
read: while
|
|
||||||
read: read-impl
|
|
||||||
read: currop
|
|
||||||
read: @
|
|
||||||
read: match-impl
|
|
||||||
read: if
|
|
||||||
read: execute
|
|
||||||
read: drop
|
|
||||||
read: assembled
|
|
||||||
read: ret
|
|
||||||
read: else
|
|
||||||
read: drop
|
|
||||||
read: then
|
|
||||||
read: repeat
|
|
||||||
read: drop
|
|
||||||
read: 1
|
|
||||||
read: message
|
|
||||||
read: yelp
|
|
||||||
read: ;
|
|
||||||
read: :
|
|
||||||
read: do.data
|
|
||||||
read: (
|
|
||||||
read: 2
|
|
||||||
read: +
|
|
||||||
read: ;
|
|
||||||
read: :
|
|
||||||
read: inst-nextimpl
|
|
||||||
read: do.data
|
|
||||||
read: 1
|
|
||||||
read: +
|
|
||||||
read: ;
|
|
||||||
read: :
|
|
||||||
read: inst-opcount
|
|
||||||
read: do.data
|
|
||||||
read: @
|
|
||||||
read: ;
|
|
||||||
read: :
|
|
||||||
read: impl
|
|
||||||
read: (
|
|
||||||
read: here
|
|
||||||
read: >r
|
|
||||||
read: >r
|
|
||||||
read: (
|
|
||||||
read: r@
|
|
||||||
read: inst-nextimpl
|
|
||||||
read: @
|
|
||||||
read: ,
|
|
||||||
read: ,
|
|
||||||
read: r@
|
|
||||||
read: inst-opcount
|
|
||||||
read: begin
|
|
||||||
read: dup
|
|
||||||
read: while
|
|
||||||
read: 1
|
|
||||||
read: -
|
|
||||||
read: swap
|
|
||||||
read: ,
|
|
||||||
read: repeat
|
|
||||||
read: drop
|
|
||||||
read: r>
|
|
||||||
read: inst-nextimpl
|
|
||||||
read: r>
|
|
||||||
read: swap
|
|
||||||
read: !
|
|
||||||
read: ;
|
|
||||||
read: :
|
|
||||||
read: int
|
|
||||||
read: &hcd
|
|
||||||
read: outb!
|
|
||||||
read: outb!
|
|
||||||
read: assembled
|
|
||||||
read: ;
|
|
||||||
read: 2
|
|
||||||
read: inst
|
|
||||||
read: mov
|
|
||||||
read: 2
|
|
||||||
read: inst
|
|
||||||
read: movb
|
|
||||||
read: :
|
|
||||||
read: outw!
|
|
||||||
read: dup
|
|
||||||
read: &hff
|
|
||||||
read: and
|
|
||||||
read: outb!
|
|
||||||
read: 256
|
|
||||||
read: /
|
|
||||||
read: outb!
|
|
||||||
read: ;
|
|
||||||
read: OP_IMM
|
|
||||||
read: OP_REG16
|
|
||||||
read: :noname
|
|
||||||
read: &hb8
|
|
||||||
read: op1
|
|
||||||
read: +
|
|
||||||
read: outb!
|
|
||||||
read: op2
|
|
||||||
read: outw!
|
|
||||||
read: ;
|
|
||||||
read: '
|
|
||||||
read: mov
|
|
||||||
read: impl
|
|
||||||
read: OP_IMM
|
|
||||||
read: OP_REG8
|
|
||||||
read: :noname
|
|
||||||
read: &hb0
|
|
||||||
read: op1
|
|
||||||
read: +
|
|
||||||
read: outb!
|
|
||||||
read: op2
|
|
||||||
read: outb!
|
|
||||||
read: ;
|
|
||||||
read: '
|
|
||||||
read: movb
|
|
||||||
read: impl
|
|
||||||
read: \
|
|
||||||
read: \
|
|
||||||
read: \
|
|
||||||
read: ax
|
|
||||||
read: &h4c01
|
|
||||||
read: #
|
read: #
|
||||||
read: mov
|
read: mov
|
||||||
read: &h21
|
read: &h21
|
||||||
read: int
|
read: int
|
||||||
|
read: ;
|
||||||
|
read: :
|
||||||
|
read: d"
|
||||||
|
read: begin
|
||||||
|
read: in@
|
||||||
|
read: dup
|
||||||
|
read: [
|
||||||
|
read: in@
|
||||||
|
read: lit
|
||||||
|
read: ]
|
||||||
|
read: !=
|
||||||
|
read: while
|
||||||
|
read: outb!
|
||||||
|
read: repeat
|
||||||
|
read: drop
|
||||||
|
read: ;
|
||||||
|
read: cs
|
||||||
|
read: push
|
||||||
|
read: \
|
||||||
|
read: ds
|
||||||
|
read: pop
|
||||||
|
read: tell
|
||||||
|
read: 1
|
||||||
|
read: +
|
||||||
|
read: dx
|
||||||
|
read: 0
|
||||||
|
read: #
|
||||||
|
read: mov
|
||||||
|
read: ah
|
||||||
|
read: 9
|
||||||
|
read: #
|
||||||
|
read: movb
|
||||||
|
read: &h21
|
||||||
|
read: int
|
||||||
|
read: 0
|
||||||
|
read: .EXIT
|
||||||
|
read: tell
|
||||||
|
read: d"
|
||||||
|
read: &h100
|
||||||
|
read: +
|
||||||
|
read: swap
|
||||||
|
read: seek
|
||||||
|
read: outw!
|
||||||
|
|
Loading…
Reference in a new issue