commit 772942e7deff99e73fd1fa9247293bd1a25cf9f5
parent dc69524d0f60680b6477ee932f7590048b3d2ce4
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 7 Oct 2022 14:29:25 -0400
asm/i386: add loop, loopz, loopnz,
Diffstat:
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/fs/asm/i386.fs b/fs/asm/i386.fs
@@ -185,6 +185,10 @@ $4 op jz, $5 op jnz, $2 op jc, $3 op jnc,
$8 op js, $9 op jns, $c op jl, $d op jnl,
$7 op ja, $6 op jna,
+: op ( opcode -- ) doer , does> ( rel a -- )
+ @ over jrel8? _assert op, jrel8, ;
+$e2 op loop, $e1 op loopz, $e0 op loopnz,
+
\ JMP and CALL
\ These are special. They can either be called with a modrm tgt, or with *no
\ argument at all*. In the latter case, an absolute addr to call is waiting on
diff --git a/fs/xcomp/i386.fs b/fs/xcomp/i386.fs
@@ -645,18 +645,18 @@ xcode EMIT
lblemit pspushN,
ret,
-\ TODO: support case where u=0
xcode rtype ( a u -- )
CX SI pspop2,
pc to lblrtype
+ cx cx test,
+ lblret abs>rel jz,
al [esi] movclr,
AX pspush,
si push, cx push,
lblemit m) call,
cx pop, si pop,
si inc,
- cx dec,
- lblrtype abs>rel jnz,
+ lblrtype abs>rel loop,
ret,
\ During early boot, it's better to halt the machine than to go back to the
@@ -848,8 +848,7 @@ L2 forward! \ parse ok
ax 4 i) shl, \ res*16
ax bx add,
si inc,
- cx dec,
- ( pc ) abs>rel jnz, ( loop )
+ ( pc ) abs>rel loop, ( loop )
[ebp] ax mov,
1 pspushN,
ret,
@@ -868,8 +867,7 @@ pc ( loop )
L1 abs>rel jnc, \ fail
ax bx add,
si inc,
- cx dec,
- ( pc ) abs>rel jnz, ( loop )
+ ( pc ) abs>rel loop, ( loop )
[ebp] ax mov,
1 pspushN,
ret,