commit c9a4ed1808b072963a5a8104a06eb1c66415d7f4
parent faabb5a3939dfa33eb3131e53c337a5cb201359a
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 15 Jul 2022 10:20:44 -0400
asm/i386: push immediate
Diffstat:
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/fs/asm/i386.fs b/fs/asm/i386.fs
@@ -28,6 +28,7 @@ SZ32 value opsz
: _err abort" argument error" ;
: _assert not if _err then ;
: w, here w! 2 allot ;
+: isbyte? ( n -- f ) $100 < ;
\ "Force" a value into opreg. If opreg is -1, we simply set it, but if it's set,
\ then we move opreg to oprm first.
@@ -169,6 +170,9 @@ $009f0f op setg, $009c0f op setl, $00940f op setz, $00950f op setnz,
$040000 op add, $3c0738 op cmp, $2c0528 op sub, $a8f084 op _test,
$240420 op and, $0c0108 op or, $340630 op xor,
+\ TEST can only have one direction
+: test, 0 to opdirec _test, ;
+
\ Shifts. They come in 2 versions. The "naked" version is imm-only. The "cl"
\ versions has CL as an inherent argument.
: op ( opcode -- ) doer , does> @ dup 8 rshift ( opcode opreg )
@@ -182,7 +186,12 @@ $04d3 op shlcl, $05d3 op shrcl,
\ Push/Pop
: op ( op -- ) doer c, does> c@ ( opcode -- )
oprm 0< _assert opsz SZ8 = not _assert opreg or c, asm$ ;
-$58 op pop, $50 op push,
+$58 op pop, $50 op _push,
+
+\ PUSH can also push an immediate
+: push, imm? if
+ imm isbyte? if $6a c, SZ8 to opsz else $68 c, then imm, asm$ else
+ _push, then ;
\ MOV has this special reg<-imm shortcut
: mov,
@@ -191,5 +200,3 @@ $58 op pop, $50 op push,
else $c7 c, 0 opreg! modrm, disp, imm, asm$ then
else $88 opmodrm, then ;
-\ TEST can only have one direction
-: test, 0 to opdirec _test, ;
diff --git a/fs/tests/asm/i386.fs b/fs/tests/asm/i386.fs
@@ -56,8 +56,7 @@ foo5 127 #eq
\ push/pop
code foo6
- ax 42 i) mov,
- ax push,
+ 42 i) push,
dx pop,
bp 4 i) sub,
bp 0 d) dx mov,