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 zcmZWoTWnNS6g~Uix$~s2DFm>cR}Xy!8m$r1su)W&O0e1*NC<)8v>nPwXQrLDG#Csa z!7swcWG79Dk%aWiOd>Qj(GP6!!w(XTl13guk%FQrL$wouKxvQb+&lW?$31)Pz1QAn zpLNdteCL^6=hvCkz#T@!x}}6Ts*&dxp!Yx64;-3qGY7~uoJbskSL?Zf%t&H@=PE<= z)AU(a-n25KBV)1LP>p+B2$4JhT9_s|<&~7@oLBm$1c{zRe=-e@_X3=;gUJET`D={m z3@?Lrkz+pTy@bqYdL)U~wbl=Cn)E2vRiM2Z(M_K6N#AeSB%aO2kLYd%IEUleO?os} z5e`>b5hMD5JN(l97=Aj*6byTpHB9u!IY%{SR1kmWuk%|Z#Ea=nI-bHX&$!F9tB)Uc zR}zV%FKI|2-Wrfp$MJylZUiG0Ka}8(K&`I@PG2T5{0inU+llyGb~rS)=mDpTn2sx>z%Is@4o&pXW? zNKXNT%wWteT;S6c(hvsERMdGbLm#!j4VhYBjpMX#(N`3PGmMnZP>ee(C2ioLN@+DA z5y!zI)+V4{?#9T^@z2P=z*HrzHbnb$)Oy)QbI8BSsVYgYaSr)65$(ZaiCAyh2%V^l zmyzGev7mJCMszrdZNu)px`7SpJw6qb)W=gnX&uxI&IKdZfF{^z5J+;jC(0ewvTO`q zDn8PCuqBxq#9nJXClE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4INY;LO=0RvGn}~r6c{e_Se6d z!;RXVz%oesRPQ@+_-3pa!!TT$BmJfYkca>)`hh2lJfrCBsp&?8`l zR=s6bnPN$uMy#WI%8TrpdZcFD{G3`-^T4_Oz39)XmwBkFE;@vc4eXIs)6U8mAj7Lw zHa_lIHO%GJ@q_(9Ef`qW>Z*)0e4oxknQc!akfYFQ9mj5P)*^)KFqP9B4Pm( z{Hyx;!|ENr5ok({@bzl@%qZ}@x=GV&3G6q@O%b9Bb=^ii2Y6Tn3p=J&S=bmF+tUz6KOumQ<1k5Pu7&SLAk`j+0j|sKWEr fs&B;@ErE>Fih;Z!(-0mUa`k^5g+hc(f-b~=H&=Dw 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 zcmXw0O-NKx6ux(6-preMPGlgJI?f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 / &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!