Compare commits

...

2 Commits

Author SHA1 Message Date
andromeda
75e9c27dda remove superfluous wrapper function 2026-03-23 17:23:09 +01:00
andromeda
b952210561 add hash 2026-03-23 17:00:32 +01:00
2 changed files with 103 additions and 69 deletions

View File

@@ -390,7 +390,8 @@ assemble:
mov cx, di
mov di, [.first_argument]
mov si, cx
call get_direct_addressing_ModRM
mov dl, 11b
call get_ModRM
; al = ModR/M byte
push rax
mov al, [.pending_operator_opcode]
@@ -546,26 +547,6 @@ get_tte_typed_metadata:
and rax, 0xFF
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; the rest of rax is zeroed
; ------------------------------------------------------------------------------
get_direct_addressing_ModRM:
mov dl, 11b
call get_ModRM
ret
; ------------------------------------------------------------------------------
; get_ModRM
;
@@ -1445,6 +1426,42 @@ elemb:
mov rax, 1 ; return 1; dl an element of list
ret
; ------------------------------------------------------------------------------
; djb2
;
; description:
; gets the 64-bit djb2 hash of a given string
;
; parameters:
; rdi = size of string
; rsi -> start of string
;
; returned:
; rax = hash
; ------------------------------------------------------------------------------
djb2:
xor ecx, ecx ; rcx = index
mov rax, 5381 ; rax = hash
.loop:
cmp rcx, rdi
jge .break
mov rdx, rax
shl rax, 5
add rax, rdx
xor edx, edx
mov dl, [rsi + rcx] ; dl = current byte
add rax, rdx
inc rcx
jmp .loop
.break:
ret
; ------------------------------------------------------------------------------
; trim_trailing_whitespace
;

View File

@@ -13,6 +13,9 @@ run_tests:
mov rsi, .msg
call print.test
call clear_test_arena
call test_djb2
call clear_test_arena
call test_elemb
@@ -22,9 +25,6 @@ run_tests:
call clear_test_arena
call test_get_tte_typed_metadata
call clear_test_arena
call test_get_direct_addressing_ModRM
call clear_test_arena
call test_get_opcode
@@ -109,6 +109,68 @@ test_elemb:
.case1 db 0x54, 0x00, 0x21, 0x20, 0x34
.msg db "test_elemb...", 0x00
; ------------------------------------------------------------------------------
; test_djb2
;
; description:
; tests djb2 described functionality
; ------------------------------------------------------------------------------
test_djb2:
mov rsi, .msg
call print.test
mov rsi, .case0
mov rdi, 0
call djb2
cmp rax, 5381
jne .fail
mov rsi, .case1
mov rdi, 1
call djb2
cmp rax, 177670
jne .fail
mov rsi, .case2
mov rdi, 2
call djb2
cmp rax, 5863208
jne .fail
; why am I testing this, of course it's without side effects xD
mov rsi, .case0
mov rdi, 0
call djb2
cmp rax, 5381
jne .fail
mov rsi, .case1
mov rdi, 1
call djb2
cmp rax, 177670
jne .fail
mov rsi, .case2
mov rdi, 2
call djb2
cmp rax, 5863208
jne .fail
.pass:
mov rsi, msg_pass
call print
ret
.fail:
mov rsi, msg_fail
call print
ret
.case0 db ""
.case1 db "a"
.case2 db "ab"
.msg db "test_djb2...", 0x00
; ------------------------------------------------------------------------------
; test_get_tte_type
;
@@ -192,51 +254,6 @@ test_get_tte_typed_metadata:
ret
.msg db "test_get_tte_typed_metadata...", 0x00
; ------------------------------------------------------------------------------
; test_get_direct_addressing_ModRM
;
; description:
; tests get_direct_addressing_ModRM described functionality
; ------------------------------------------------------------------------------
test_get_direct_addressing_ModRM:
mov rsi, .msg
call print.test
mov di, 0x0000 ; rax
mov si, 0x0000 ; rax
call get_direct_addressing_ModRM
cmp al, 11000000b ; Mod Reg R/M: 11b 000b 000b
jne .fail
mov di, 0x0000 ; rax
mov si, 0x0003 ; rdx
call get_direct_addressing_ModRM
cmp al, 11000010b ; Mod Reg R/M: 11b 000b 010b
jne .fail
mov di, 0x0003 ; rdx
mov si, 0x0000 ; rax
call get_direct_addressing_ModRM
cmp al, 11010000b ; Mod Reg R/M: 11b 010b 000b
jne .fail
mov di, 0x0003 ; rdx
mov si, 0x0003 ; rdx
call get_direct_addressing_ModRM
cmp al, 11010010b ; Mod Reg R/M 11b 010b 010b
jne .fail
.pass:
mov rsi, msg_pass
call print
ret
.fail:
mov rsi, msg_fail
call print
ret
.msg db "test_get_direct_addressing_ModRM...", 0x00
; ------------------------------------------------------------------------------
; test_get_opcode
;