commit 8af85ff584454cb304a71ba6b80d12d2216d65dc
parent f535170932adaf19038555163f33b43df38cdb4a
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 30 Jun 2023 17:02:44 -0400
hal i386: add i) support to *, and /mod,
Diffstat:
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/fs/doc/hal.txt b/fs/doc/hal.txt
@@ -235,7 +235,7 @@ Instructions:
-, op -- dest - operand
*, op -- dest * operand
/mod, op -- divide dest by operand and put remainder in A register.
- Can't be used with A>).
+ Can't be used with A>) or <>).
<<, op -- dest lshift operand
>>, op -- dest rshift operand
&, op -- Z dest and operand
diff --git a/fs/tests/hal.fs b/fs/tests/hal.fs
@@ -1,4 +1,7 @@
?f<< /tests/harness.fs
+: spit ( a u -- ) swap >r for
+ i 40 mod not if nl> then
+ 8b to@+ V1 .x1 next rdrop ;
testbegin
code test1 ( a b -- a-b )
PSP) @!,
@@ -212,4 +215,13 @@ code test22 ( n a -- n )
create foo $12345678 ,
$23456789 foo test22
foo @ $12345689 #eq
+
+\ /mod with i)
+code test23 ( n -- r q )
+ 3 i) /mod,
+ dup,
+ PSP) A>) !,
+ exit,
+
+10 test23 3 #eq 1 #eq
testend
diff --git a/fs/xcomp/i386/kernel.fs b/fs/xcomp/i386/kernel.fs
@@ -286,7 +286,18 @@ xcode +n, ( n operand -- ) \ operand n i) add,
ax $8000 i) or, L1 abscall, ( n -- )
ax dwrite, xdrop, ret,
-xcode *, ( operand -- ) \ TODO: support i)
+\ Before writing the operand MUL/DIV operation, we check if the operand is
+\ immediate. If it is, we load that immediate in CX and mangle the operand so
+\ that the source becomes CX.
+pc to L2 ( operand -- )
+ ax HALIMM i) test, forward8 jnz, ret, forward! \ not an immediate
+ $b9 i) cwrite, cx lblhbank m) mov, cx dwrite, \ cx i) mov,
+ ax HALIMM ^ i) and, \ remove imm flag
+ al $c1 i) or, \ src=CX
+ ret,
+
+xcode *, ( operand -- )
+ L2 abscall,
xdup,
ax HALINV i) test, forward8 jz, \ inverted, save AX to DI
ax HALINV ^ i) and,
@@ -304,7 +315,8 @@ xcode *, ( operand -- ) \ TODO: support i)
xdrop,
ret,
-xcode /mod, ( operand -- ) \ TODO: support i)
+xcode /mod, ( operand -- )
+ L2 abscall,
$d231 i) wwrite, \ dx dx xor,
ax $f730 i) or, L1 abscall,
$d389 i) wwrite, \ bx dx mov,