@@ -69,11 +69,11 @@ assoc(`tib', `TIB ') assoc(`accept', `ACCEPT ') assoc(`key', `KEY ') assoc(`base', `BASE ') assoc(`cmove', `CMOVE ') -assoc(`dbg', `DBG ') +assoc(`bye', `BYE ') assoc(`drop', `DROP ') assoc(`dup', `DUP ') assoc(`emit', `EMIT ') assoc(`evaluate', `EVALUATE') assoc(`execute', `EXECUTE ') @@ -134,10 +134,26 @@ assoc(`mult', `* ') assoc(`minus', `- ') assoc(`plus', `+ ') assoc(`store', `! ') assoc(`fetch', `@ ') +assoc(`pad', `PAD ') +assoc(`hld', `HLD ') +assoc(`hold', `HOLD ') +assoc(`todigit', `>DIGIT ') +assoc(`nstart', `<# ') +assoc(`nnn', `# ') +assoc(`nns', `#S ') +assoc(`nend', `#> ') +assoc(`umdivmod', `UM/MOD ') +assoc(`udot', `U. ') +assoc(`dot', `. ') +assoc(`is_lt0', `0< ') +assoc(`abs', `ABS ') +assoc(`hex', `HEX ') +assoc(`decimal', `DECIMAL ') +assoc(`binary', `BINARY ') ; DX-Forth is intended to be loaded at address $14200, and not ; exceed $17FFF. The dictionary space is intended to occupy ; from $18000-$1BFFF. Somewhere in this space must also exist ; things like the Forth stacks and block buffers. @@ -168,11 +184,11 @@ next: lhu W,0(I) addi I,I,2 add W,W,D jalr x0,0(W) -dbg: jalr x0,0(x0) +_bye: jalr x0,0(x0) ; ==== COLD ; ; Note that some words need relative references defined here ; to resolve circular dependencies. E.g., we must invoke QUIT @@ -179,10 +195,12 @@ ; from here, despite QUIT being defined much later in the ; listing. squote = _squote - _start lit16 = _lit16 - _start +lit32 = _lit32 - _start +lit64 = _lit64 - _start align 4 _cold: jal W,_docol _cold_0: hword quit, wedge ; Quit should never return. @@ -428,10 +446,18 @@ ld W,0(S) addi S,S,8 blt W,T,_rtnT _rtnF: addi T,x0,0 jal x0,next + +; Sets T to -1 if T<0; 0 otherwise. + + align 4 +_is_lt0: + blt T,x0,_rtnT + addi T,x0,0 + jal x0,next ; Bitwise AND, OR, XOR. align 4 __and: @@ -458,10 +484,14 @@ _negate: xori T,T,-1 addi T,T,1 jal x0,next + align 4 +_abs: blt T,x0,_negate + jal x0,next + align 4 __2star: slli T,T,1 jal x0,next @@ -705,10 +735,22 @@ ld t3, 48(sp) addi sp, sp, 56 jalr x0, 0(ra) ; End routines. + +; UM/MOD ( ud u -- r q ) + + align 4 +_umdivmod: + addi a2,T,0 + ld a1,0(S) + ld a0,8(S) + jal ra,mathUDivMod + sd a1,8(S) + addi S,S,8 + jal x0,next ; M* ( a b -- a*b.L a*b.H ) ; ; This implementation isn't particularly efficient. But, ; it should be correct. @@ -1134,10 +1176,66 @@ hword dup, strt, store, cur, store _accept_0: hword key, bs, c_c, c_m, gr, drop, go, _accept_0 - _start ; END ACCEPT + +; BEGIN PICTURED NUMERIC OUTPUT + + align 4 +_pad: jal W,_docol + hword lit32 + align 4 + word _quit_0 + 256 + $14200 ; Base this on HERE when we implement it. + hword exit + + align 4 +_hld: jal W,_dovar + align 8 + dword 0 + + align 4 +_hold: jal W,_docol + hword lit16, -1, hld, plussto, hld, fetch, cstore, exit + + align 4 +_todigit: + jal W,_docol + hword dup, lit16, 10, is_geu, zgo, _todigit_0 + hword lit16, 7, plus +_todigit_0: + hword lit16, $30, plus, exit + + align 4 +_nstart: + jal W,_docol + hword pad, hld, store, exit + + align 4 +_nend: jal W,_docol + hword drop, hld, fetch, pad, over, minus, exit + + align 4 +_nnn: jal W,_docol ; nn: is taken elsewhere. + hword lit16, 0, base, fetch, umdivmod, swap, todigit, hold, exit + + align 4 +_nns: jal W,_docol +_nns_0: hword dup, zgo, _nns_1, nnn, go, _nns_0 +_nns_1: hword exit + + align 4 +_udot: jal W,_docol + hword nstart, nns, nend, type, exit + + align 4 +_dot: jal W,_docol + hword dup, is_lt0, tor, abs, nstart, nns, rfrom + hword zgo, _dot_0, lit16, $2D, hold +_dot_0: hword nend, type, exit + +; END PICTURED NUMERIC OUTPUT ; ==== Look stuff up in the dictionary. ; ; The dictionary is a mapping of word name to code field ; address (CFA). The dictionary is expressed as a relational @@ -1405,10 +1503,24 @@ align 4 _base: jal W,_dovar align 8 dword 10 + align 4 +_hex: jal W,_docol + hword lit16, 16, base, store, exit + + align 4 +_decimal: + jal W,_docol + hword lit16, 10, base, store, exit + + align 4 +_binary: + jal W,_docol + hword lit16, 2, base, store, exit + align 4 sign = _sign - _start _sign: jal W,_dovar align 8 dword 0 @@ -1509,6 +1621,5 @@ align 4 _quit: lui R,$14000 ; Hard reset of return stack. jal W,_docol _quit_0: hword cr, rep, go, _quit_0 -