summaryrefslogtreecommitdiff
path: root/twasm/asm/main.asm
diff options
context:
space:
mode:
authorandromeda <andromeda@lenovo>2026-03-23 17:00:32 +0100
committerandromeda <andromeda@lenovo>2026-03-23 17:00:32 +0100
commitb952210561ab64ce6af22ab53f2fd3f5d1fa0985 (patch)
tree315f528432f9653b62269d872050ab45091576ef /twasm/asm/main.asm
parent50e635332ce581df14d596afb6bbe6d821196877 (diff)
add hash
Diffstat (limited to 'twasm/asm/main.asm')
-rw-r--r--twasm/asm/main.asm36
1 files changed, 36 insertions, 0 deletions
diff --git a/twasm/asm/main.asm b/twasm/asm/main.asm
index 1ed4932..7262a8f 100644
--- a/twasm/asm/main.asm
+++ b/twasm/asm/main.asm
@@ -1446,6 +1446,42 @@ elemb:
ret
; ------------------------------------------------------------------------------
+; djb2
+;
+; description:
+; gets the 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
;
; description: