From e1c6771fe17f96f512098d2b2365600e7a2e0de2 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Sun, 20 Oct 2019 14:53:53 -0400 Subject: [PATCH] fix bugs, hello world assembles --- asm.img | Bin 10804 -> 10910 bytes asm.qf | 11 +- boot.img | Bin 10118 -> 10152 bytes boot.qf | 5 +- in.asm | 17 ++- out.com | Bin 5 -> 27 bytes qf.bas | 15 ++- trace.txt | 386 +++++++----------------------------------------------- 8 files changed, 85 insertions(+), 349 deletions(-) diff --git a/asm.img b/asm.img index 6124976f1d02afa73d962551104831142ace0298..d65d1ca7041a03746338d6b8e65cabea98440a3f 100755 GIT binary patch delta 1826 zcmdlIGB0$41T&-BWJe}>)(8I?7-~Q)_WS=C7_zG3Cp$99Znj{~VPq*zP0gO{$Rxvl z`#%FiNovmIhXS&UcQ!9%SoWgpYfsr8w#A3WRc_XJX=Tim-hQy+x#7dB9Zx|RD$`XroKu%-%#K6EX zS&&tpN#W~cM=oWyp9~BPd6|3w6 zCkG11Ga5|3E1=A1GMQ0Onbm@cfguGX%4!2`Fu7MqnK5PZMj>U^43LV+ z6NThib3h8ftO6zm2Ia|t>2Hy z3JQxSUlaxf@mFDG_8TA>uqs)`+mmfYlo`KGP83n*_yaN{zbpw90PGCR3=9RO#i00P zlL4_o5hBNA%DnlaNE9EdAM;EGhRv)hij1<){|hnv|Nrm*r~m&M9{m6Q|I>d4#&s^{}2P27(V_7nE}xW(dEnd>i?(zQImVsOhxxFeER?I zKZySbOipHa^?%>w>uU0>NsO=lADH}GP0@P>d)75p^FEjrB z|NsBx$+Okv>u)lGTy~A|(f^PCfBnA2~09GC@~5#F))C5AQ~hmRL{i1 z0A?^TLM0fXd{!vU1Qln3^4Xv?GgO=z%4dhtEKqS)D9r|?*`YK81H>VWU|LX!i3!XQ zVq#`sW_ZK+Zt_VDdC5=z85qnM-u@S50Qu;{e=Y`)uhG%Iv z|6l!o^#8`>^_r6PmziGw|N9>jc$k$KL9_((r~f+`ZZm%T z|N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-T9B%Z zV8^$D?q@-{~!PV`hN&YfBMhJ@cRG9|0fuKL4yOr zQUJUBC!;Cj@Be@QgLoj9GcuVn{`(IS0qOhr|M&m9jQ{_OGX7*_WB`#&V3L_Zl#!8% zfdRw=(I7d-dL|YIFoTH^D!~ZlvqEVms5ldp&jzKLq2kO?K0B0Vfr_(2X*MX$4y73w zAP!*!(}IjlOkf5h6Eg!d!)?a9lV5AdOPVo!`p>}d_P;0t$VVUkb1{H?#l~=Sva+VK zD9GO+d63^{LH&MWa_|IzIL1 diff --git a/asm.qf b/asm.qf index e653384..0145256 100755 --- a/asm.qf +++ b/asm.qf @@ -32,7 +32,7 @@ OP_SREG mkreg sreg 2 + ; : match-impl ( optypes opcount -- b ) - begin dup > 0 while + begin dup 0 > while 1 - 2dup + @ over optypes + @ != if drop drop 0 ret then repeat drop drop 1 ; @@ -44,7 +44,6 @@ OP_SREG mkreg sreg if execute drop assembled ret else drop then repeat drop 1 message yelp ; -: do.data ( cp -- data ) 2 + ; : inst-nextimpl do.data 1 + ; : inst-opcount do.data @ ; @@ -58,8 +57,14 @@ OP_SREG mkreg sreg 2 inst mov 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_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 + diff --git a/boot.img b/boot.img index 359ccf7d1185ef0715076b9fe68014aa7af29ff2..9fd511265905340aad4bb8bb7d08c0b7db9d4a49 100755 GIT binary patch delta 769 zcmZqkU*W$&f|*fm;zW7Y2mcuuY9>yUXTSfSfg!6Ze&R&g%@)i#j4Z{eso4`J%5dEN z&%jWUnv*keq737m%?nvpGqdKGmXs?_4&;z!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cd|!0>ePdsTI&&kU0#)HE39O?Fh1 zcNb-R^}m}zj`7$3Pyhe_2Py1k`1GHd;p6{GhEM-Z8K3=UV~}I~{r}hh$58p#|9}5~ z^Z)<HlM}3m*P|{QuMcWsJ}MvoN$Wwln_!|Ly<7 c|NsBDGXDPm@4pbk+yB4+|M}lOxl>&p0O!pe`~Uy| diff --git a/boot.qf b/boot.qf index 0e3030c..f0d7458 100755 --- a/boot.qf +++ b/boot.qf @@ -1,7 +1,8 @@ : debug word@ yelp ; : here 0 @ ; : here! 0 ! ; -: != not = ; +: != = not ; +: outw! dup &hff & outb! 256 / &hff & outb! ; : if ' jz_ , here 0 , ; immediate : then here over - swap ! ; immediate @@ -36,6 +37,8 @@ var does.patch : makedo word@ create ' $do , here does.patch ! -1 , ; : does> here 3 + lit :| does.patch @ ! rdrop |; , ; immediate +: do.data ( cp -- data ) 2 + ; + : $defer r> @ >r ; : defer word@ create ' $defer , :| |; , ; : redef 1 + ! ; diff --git a/in.asm b/in.asm index 6d55dc0..80ff81e 100755 --- a/in.asm +++ b/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 -\ mov \ should fail and yelp -ax &h4c01 # mov +cs push \ copy code segment to data segment +ds pop + +tell 1 + dx 0 # mov +ah 9 # movb &h21 int + +0 .EXIT + +tell +d" Hello World!$" +&h100 + swap seek outw! diff --git a/out.com b/out.com index f041664f6687e6900312efdb2ab3425cd68281f0..23241150ce4b57df14983f8fe8e1c10b7c3a1f71 100755 GIT binary patch literal 27 icmd;+-^Itch4ZZ94hEmIiXN#sIr$3V`9(P?iYfqm7YOwL literal 5 McmdnN=yO&P00uw-^Z)<= diff --git a/qf.bas b/qf.bas index c00bd52..42e3e32 100755 --- a/qf.bas +++ b/qf.bas @@ -90,6 +90,8 @@ CONST O.BITAND = -32 CONST O.BITOR = -33 CONST O.MESSAGE = -34 CONST O.TRACE = -35 +CONST O.TELL = -36 +CONST O.SEEK = -37 CONST P.HERE = 0 CONST P.LATEST = 1 @@ -166,6 +168,8 @@ CALL opcode("*", O.MUL) CALL opcode("/", O.DIV) CALL opcode("<", O.LT) CALL opcode("=", O.EQ) +CALL opcode("&", O.BITAND) +CALL opcode("|", O.BITOR) CALL opcode("jz_", O.JZ) CALL opcode("jmp_", O.JMP) CALL opcode(">r", O.RPUSH) @@ -177,6 +181,9 @@ CALL opcode(",", O.COMMA) CALL opcode("message", O.MESSAGE) CALL opcode("yelp", O.YELP) CALL opcode("trace", O.TRACE) +CALL opcode("seek", O.SEEK) +CALL opcode("tell", O.TELL) + CALL assemble("rot >rot ret") CALL assemble("over", "swap dup >rot ret") CALL assemble("2dup", "over over ret") @@ -208,7 +215,7 @@ SUB execute (op%) IF trace% > 0 AND tracevm THEN tp$ = "N/A" 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 SELECT CASE op% CASE IS >= 0 @@ -257,6 +264,11 @@ SUB execute (op%) CASE O.OUT byte$ = CHR$(pop) PUT #1, , byte$ + CASE O.TELL + CALL push(SEEK(1) - 1) + CASE O.SEEK + SEEK #1, pop + 1 + CASE O.LOOKUP istr% = pop iword = lookup(strings$(istr%)) @@ -404,6 +416,7 @@ SUB interpret (st$) END SUB SUB loadfile (filename$) + PRINT "Building "; filename$ inline% = 0 OPEN filename$ FOR INPUT AS #2 WHILE EOF(2) = 0 diff --git a/trace.txt b/trace.txt index 33f5f8f..4fe3165 100755 --- a/trace.txt +++ b/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: op1 -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: .EXIT read: ax -read: 0 -read: reg8 -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: &h4c00 +read: | read: # read: mov read: &h21 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!