| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | SquishHash function |
Hello everyone. I am working on some low level Squish functions. I don't
talk the language of C, however I talk the language of ASM. :-) This is one
function I've just completed, the translation was very simple. I think it's
right.
If someone wants to clean it up a little so it's C callable and use it in
their code they are most welcome. It will probably be a tad faster than
compiled C because it performs the conversion to lowercase
"inline" rather than as a function call.
; SQHASH.ASM
; Creates a Squish hash value for use with the Squish messagebase
; format.
; NOTE: Uses 32 bit registers, therefore requires 386+ processor
; Original code written 24-Aug-1995.
; Author: Rowan Crowe, 3:635/727{at}fidonet
; rowan{at}jelly.freeway.dialix.oz.au
; * Unconditionally released to the public domain *
; This is the algorithm from SQDEV.PRN:
;
; ===================================================================
; Set "hash" to a value of 0
;
; For each 8-bit character "ch" in the To: field, repeat:
;
; - Shift "hash" left by four bytes.
; - Convert "ch" to lowercase
; - Increment the hash by the ASCII value of "ch"
;
; - Set "g" to the value of "hash"
; - Perform a bitwise AND on "g", using a mask of
; 0xf0000000.
;
; - If "g" is non-zero:
;
; - Perform a bitwise OR on "hash" with the value
; of "g".
; - Shift "g" right by 24 bits.
; - Perform a bitwise OR on "hash" with the value
; of "g".
;
; Perform a bitwise AND on "hash" with a value of 0x7fffffff.
; ===================================================================
.386
CODE SEGMENT
ASSUME CS:CODE
_SquishHash PROC Far
; DS:SI -> string to hash
; CX = length of string
; Returns:
; EAX = hash value
; -- Conversion reference --
; EAX = "hash"
; EBX = "ch"
; EDX = "g"
; --------------------------
xor eax, eax ; Set "hash" to a value of 0
{at}HashLoop:
movzx ebx, byte ptr ds:[si]
inc si
shl eax, 4 ; Shift "hash" left by four bytes.
cmp bl, 'A'
jb {at}KeepCase
cmp bl, 'Z'
ja {at}KeepCase
add bl, 32 ; Convert "ch" to lowercase
{at}KeepCase:
add eax, ebx ; Increment the hash by the ASCII value
; of "ch"
mov edx, eax ; Set "g" to the value of "hash"
and edx, 0f0000000h ; Perform a bitwise AND on "g", using a
; mask of 0xf0000000.
jz {at}HashCont ; If "g" is non-zero:
or eax, edx ; Perform a bitwise OR on "hash" with
; the value of "g".
shr edx, 24 ; Shift "g" right by 24 bits.
or eax, edx ; Perform a bitwise OR on "hash" with
; the value of "g".
{at}HashCont:
and eax, 07fffffffh ; Perform a bitwise AND on "hash" with
; a value of 0x7fffffff.
loop {at}HashLoop
ret
ENDP
CODE ENDS
END
---
* Origin: Melbourne, Australia (3:635/727.1)SEEN-BY: 50/99 632/348 998 633/371 634/384 635/503 513 544 727 638/102 SEEN-BY: 639/100 640/230 690/718 711/401 410 430 807 808 809 934 713/888 SEEN-BY: 800/1 7877/2809 @PATH: 635/727 632/348 635/503 50/99 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.