commit 3ea3d99
zzo38
·
2023-04-21 01:21:22 +0000 UTC
parent 852b7da
Add a file prg/misc.tal with some miscellaneous stuff, which might be useful for using some of them in other programs.
1 files changed,
+27,
-0
+27,
-0
1@@ -0,0 +1,27 @@
2+\\ Miscellaneous stuff, which may be useful to use some of it in other programs.
3+\\ This file is public domain.
4+
5+\\ Print a 16-bit signed number as decimal (without leading zeros).
6+@printn ( number* -- )
7+ DUP2k #1f SFT2 EQUk [? LIT2 "- 18 DEO ]@ MUL2 SUB2
8+ LITr 00
9+ [@
10+ #000a DIV2k STH2k MUL2 SUB2
11+ STH2 SWP2r STH2r
12+ NIPr LITr 30 ADDr
13+ ORAk ]?
14+ POP2
15+ [@ STHr #18 DEO STHrk ]?
16+ POPr
17+ JMP2r
18+
19+\\ Add together two 32-bit numbers.
20+@add32 ( hi1* lo1* hi2* lo2* -- hi* lo* )
21+ ROT2 STH2k ADD2 STH2k ROT2 ROT2 GTH2r #00 STHr ADD2 ADD2 SWP2
22+ JMP2r
23+
24+\\ Absolute value of 16-bits.
25+@abs ( in* -- out* )
26+ DUP2k #1f SFT2 MUL2 SUB2
27+ JMP2r
28+