summaryrefslogtreecommitdiff
path: root/twasm/asm/main.asm
diff options
context:
space:
mode:
authorandromeda <andromeda@lenovo>2026-03-09 23:00:39 +0100
committerandromeda <andromeda@lenovo>2026-03-09 23:01:12 +0100
commita972f38bb636fdcb41a2bb7c856f7f546076b397 (patch)
treef41fde5f682d33e228510aa3b73e9bf6041a8df4 /twasm/asm/main.asm
parent869420ef7ab2bfa8bc04c44584e55bb337d83f32 (diff)
add get_direct_addressing_ModRM and test_*, fix a couple bugs/typos, add 'reg value' as register metadata
Diffstat (limited to 'twasm/asm/main.asm')
-rw-r--r--twasm/asm/main.asm84
1 files changed, 72 insertions, 12 deletions
diff --git a/twasm/asm/main.asm b/twasm/asm/main.asm
index 57af625..1dfad3b 100644
--- a/twasm/asm/main.asm
+++ b/twasm/asm/main.asm
@@ -188,6 +188,63 @@ get_tte_typed_metadata:
ret
; ------------------------------------------------------------------------------
+; get_direct_addressing_ModRM
+;
+; description:
+; given 2 register tokens, returns the ModR/M byte in direct addressing
+; (mod = 11b) mode
+;
+; parameters:
+; di = token table entry `reg`
+; si = token table entry `R/M`
+;
+; returned:
+; al = ModR/M byte
+; ------------------------------------------------------------------------------
+
+get_direct_addressing_ModRM:
+ ; TODO something is backwards in this function but I don't see it. If the test
+ ; suite fails, it's too far gone; rewrite it.
+ push rdi
+ push rsi
+ ; get metadata of reg
+ call get_tte_typed_metadata
+ ; al = typed metadata of reg
+ pop rsi
+ pop rdi
+
+ mov bl, al ; bl = metadata of reg
+
+ push rdi
+ push rsi
+ push rbx
+
+ ; get metadata of R/M
+ mov di, si
+ call get_tte_typed_metadata
+ ; al = typed metadata of R/M
+
+ pop rbx
+ pop rsi
+ pop rdi
+
+ mov dl, al
+
+ shr dl, 2
+ and dl, 111b ; mask
+
+ shr bl, 2
+ and bl, 111b ; mask
+ shl bl, 3
+
+ xor eax, eax
+ or al, 11b << 6 ; mod bits
+ or al, dl ; reg bits
+ or al, bl ; R/M bits
+ and rax, 0xFF ; mask for byte
+ ret
+
+; ------------------------------------------------------------------------------
; tokenising
; ------------------------------------------------------------------------------
@@ -872,30 +929,33 @@ tokens:
dw 0x0059
.by_name_5:
.by_id:
+ dw 0x0010 ; eax
+ db 0x02 ; type: register
+ db 00000010b ; reg: 000b
+ ; width: 10b (32 bits)
+
+ dw 0x0000 ; rax
+ db 0x02 ; type: register
+ db 00000011b ; reg: 000b
+ ; width: 11b (64 bits)
+
+ dw 0x0003 ; rdx
+ db 0x02 ; type: register
+ db 00001011b ; reg: 010b
+ ; width: 11b (64 bits)
+
dw 0x0053 ; xor
db 0x01 ; type: operator
db 0x02 ; # operands
- dw 0x0010 ; eax
- db 0x02 ; type: register
- db 0x02 ; width: 32 bit
-
dw 0x0054 ; inc
db 0x01 ; type: operator
db 0x01 ; # operands
- dw 0x0000 ; rax
- db 0x02 ; type: register
- db 0x03 ; width: 64 bit
-
dw 0x0056 ; mov
db 0x01 ; type: operator
db 0x02 ; # operands
- dw 0x0003 ; rdx
- db 0x02 ; type: register
- db 0x03 ; width: 64 bit
-
dw 0x004F ; hlt
db 0x01 ; type: operator
db 0x00 ; # operands