commit bd9afb80910e4d9fff7a6b687cb0f214be80ef03
parent dd04bc4bc2b35f03229a4f28144cd55272f9dc0c
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sun, 30 Oct 2022 16:47:44 -0400
asm/i386: add two shortcut encoding forms
1. The "AX + imm" short form
2. The "rm/32-or-16 + sign-extended-imm8" short form
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/fs/asm/i386.fs b/fs/asm/i386.fs
@@ -59,7 +59,7 @@
op16b if $66 c, then dup 8 rshift $ff and ?dup if c, then c, ;
: modrm, ( -- ) \ write down modrm, errors out if not all parts are there.
- opmod 3 lshift opreg or 3 lshift oprm or dup $100 < _assert c, ;
+ opmod 3 lshift opreg or 3 lshift oprm or dup isbyte? _assert c, ;
: sib, ( -- ) \ write down the SIB byte if needed.
realmode not if oprm SIB = opmod 3 < and if sib c, then then ;
@@ -80,7 +80,9 @@
opdirec << or op, msd, asm$ ;
: opimm, ( opcode opreg -- ) \ write the operation in "immediate" mode
- opreg! maybe8b op, msd, imm, asm$ ;
+ opreg! op8b not if
+ 1 or imm isbyte? if ( sign-extended imm8 ) 8b! 2 or then then
+ op, msd, imm, asm$ ;
\ Setting arguments
@@ -174,7 +176,7 @@ $9c op pushf, $9d op popf, $cf op iret,
\ of the size of its relative offset. To that end, we auto adjust that relative
\ address to the size of the op. Therefore, "0 jmp," is an infinite loop encoded
\ as EB FE.
-: jrel8? ( rel -- f ) $7f + $100 < ;
+: jrel8? ( rel -- f ) $7f + isbyte? ;
: jrel8, 2 - c, ;
: jrel32, ( rel32-or-16 ) realmode if 3 - w, else 5 - , then ;
@@ -218,7 +220,7 @@ $e2 op loop, $e1 op loopz, $e0 op loopnz,
\ r = opreg override
\ m = modrm opcode
: op ( reg opcode -- ) doer , does> @ ( opcode -- )
- dup 16 rshift opreg! $ffff and dup $100 < if maybe8b then opmodrm, ;
+ dup 16 rshift opreg! $ffff and dup isbyte? if maybe8b then opmodrm, ;
$0400f7 op mul, $0600f7 op div, $0300f7 op neg, $0200f7 op not,
$0100fe op dec, $0000fe op inc,
$000f9f op setg, $000f9c op setl, $000f97 op seta, $000f92 op setb,
@@ -234,7 +236,10 @@ $020f01 op lgdt, $030f01 op lidt,
\ m = modrm opcode
: op ( opcode -- ) doer , does> @ ( opcode )
imm? if
- 8 rshift dup >> $fc and $80 or swap 7 and ( opcode opreg ) opimm,
+ opmod 3 = opreg AX = and if \ AX shortcuts
+ 16 rshift maybe8b op, imm, asm$
+ else
+ 8 rshift dup >> $fc and $80 or swap 7 and ( opcode opreg ) opimm, then
else $ff and maybe8b opmodrm, then ;
$040000 op add, $3c0738 op cmp, $2c0528 op sub, $a80084 op _test,
$240420 op and, $0c0108 op or, $340630 op xor, $000086 op xchg,