getting closer

This commit is contained in:
~d6 2024-09-09 23:36:43 -04:00
parent 62cc1ffd12
commit 6febc83848
2 changed files with 34 additions and 0 deletions

View File

@ -131,4 +131,33 @@
#01 u32-rshift u32-add ( z** v=w+y-1/2** [ylo* yhi*] ) #01 u32-rshift u32-add ( z** v=w+y-1/2** [ylo* yhi*] )
STH2r STH2r u32-div !u32-add ( z+v/y** ) STH2r STH2r u32-div !u32-add ( z+v/y** )
( print an x32 number to stdout )
@x32-emit ( x/** -> )
;x32-emit/draw-ch !x32-draw
&draw-ch ( c^ -> ) #18 DEO JMP2r
( draw an x32 number using the given character-drawing subroutine )
@x32-draw ( x/** draw-char* -> )
,&f STR2 LITr 00 ( x** [0^] )
&loop ( x1** [... count^] )
#0000 #000a u32-divmod ( q** r** )
NIP2 NIP INCr ( q** r^ [... count+1^] )
LIT "0 ADD STH SWPr ( q** [... c^ count+1^] )
STHkr #03 NEQ ?&next ( q** [... c^ count+1^] )
INCr LITr ". SWPr ( q** [... c^ dot^ count+2^] )
&next ( q** [... count+n^ )
OVR2 OVR2 ( q** q** [... count+n^] )
u32-non-zero ?&loop ( q** [... count+n^] )
POP2 POP2 ( [... count+n^] )
&pad ( [... count+n^] )
STHkr #04 GTH ?&unroll ( [... count+n^] )
STHkr #03 NEQ ?{ INCr LITr ". SWPr }
INCr LITr "0 SWPr !&pad ( [... 0^ count+n+1^] )
&unroll ( [... x0^] )
STHr ( x0^ [...] )
&uloop ( x^ [... z^] )
STHr LIT2 [ &f $2 ] JSR2 ( x^ [...] ; call f[z] )
#01 SUB DUP ?&uloop ( x-1^ [...] )
POP JMP2r ( )
~math32.tal ~math32.tal

View File

@ -30,6 +30,11 @@
#0000 #0007 #0000 #07d0 LIT "/ ;x32-div #0000 #0004 test-binop ( 0.007 / 2 = 0.004 ) #0000 #0007 #0000 #07d0 LIT "/ ;x32-div #0000 #0004 test-binop ( 0.007 / 2 = 0.004 )
#0000 #0009 #0000 #07d0 LIT "/ ;x32-div #0000 #0004 test-binop ( 0.009 / 2 = 0.004 ) #0000 #0009 #0000 #07d0 LIT "/ ;x32-div #0000 #0004 test-binop ( 0.009 / 2 = 0.004 )
#0a18 DEO #0a18 DEO
#0000 #0001 x32-emit #0a18 DEO
#0000 #03e8 x32-emit #0a18 DEO
#0001 #e078 x32-emit #0a18 DEO
#0123 #4567 x32-emit #0a18 DEO
#7fff #ffff x32-emit #0a18 DEO
#800f DEO BRK #800f DEO BRK
~fix32.tal ~fix32.tal