aboutsummaryrefslogtreecommitdiffstats
path: root/epan/asm_utils_win32_x86.asm
blob: 4d36fca9c54de5cf466a28bae824ad92e384088d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
; asm_utils_win32_x86.asm
; Functions optionally implemented in assembler
;
; Wireshark - Network traffic analyzer
; By Gerald Combs <gerald@wireshark.org>
; Copyright 1998 Gerald Combs
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
;

SECTION .text

GLOBAL _wrs_strcmp
GLOBAL _wrs_strcmp_with_data
GLOBAL _wrs_str_equal
GLOBAL _wrs_check_charset
GLOBAL _wrs_str_hash

    align 16
_wrs_strcmp:
_wrs_strcmp_with_data:
    mov ecx, dword [esp + 4]  ; a
    mov edx, dword [esp + 8]  ; b
    push ebx
CMP_LOOP:
    mov eax, dword [ecx]
    mov ebx, dword [edx]
    cmp al, bl
    jne CMP_NEQ_END
    or al, al
    jz CMP_EQ_END
    cmp ah, bh
    jne CMP_NEQ_END
    or ah, ah
    jz CMP_EQ_END
    shr eax, 16
    shr ebx, 16
    add ecx, byte 4
    add edx, byte 4
    cmp al, bl
    jne CMP_NEQ_END
    or al, al
    jz CMP_EQ_END
    cmp ah, bh
    jne CMP_NEQ_END
    or ah, ah
    jnz CMP_LOOP
CMP_EQ_END:
    pop ebx
    xor eax, eax
    retn
CMP_NEQ_END:  
    ; returns 1 or -1 based on CF flag from the last comparision
    sbb eax, eax
    pop ebx
    shl eax, 1
    inc eax
    retn

    align 16
_wrs_str_equal:
    mov ecx, dword [esp + 4]  ; a
    mov edx, dword [esp + 8]  ; b
    push ebx
EQL_LOOP:
    mov eax, dword [ecx]
    mov ebx, dword [edx]
    cmp al, bl
    jne EQL_NEQ_END
    or al, al
    jz EQL_EQ_END
    cmp ah, bh
    jne EQL_NEQ_END
    or ah, ah
    jz EQL_EQ_END
    shr eax, 16
    shr ebx, 16
    add ecx, byte 4
    add edx, byte 4
    cmp al, bl
    jne EQL_NEQ_END
    or al, al
    jz EQL_EQ_END
    cmp ah, bh
    jne EQL_NEQ_END
    or ah, ah
    jnz EQL_LOOP
EQL_EQ_END:
    xor eax, eax
    pop ebx
    not eax
    retn
EQL_NEQ_END:  
    pop ebx
    xor eax, eax
    retn

    align 16
_wrs_check_charset:
    mov edx, dword [esp + 4]  ; table
    mov ecx, dword [esp + 8]  ; str
    push edi
    push ebx
    mov edi, edx
    mov bl, byte 0xFF
CHK_LOOP:
    mov eax, dword [ecx]
    movzx edx, al
    test bl, byte [edi+edx]
    jz CHK_AL_END
    movzx edx, ah
    test bl, byte [edi+edx]
    jz CHK_AH_END
    shr eax, 16
    add ecx, byte 4
    movzx edx, al
    test bl, byte [edi+edx]
    jz CHK_AL_END
    movzx edx, ah
    test bl, byte [edi+edx]
    jnz CHK_LOOP
CHK_AH_END:
    movzx eax, ah
    pop ebx
    pop edi
    retn
CHK_AL_END:
    movzx eax, al
    pop ebx
    pop edi
    retn

    align 16
_wrs_str_hash:
    mov edx, dword [esp + 4]  ; v
    push ebx
    xor eax, eax
    mov ecx, dword [edx]
    or cl, cl
    movzx ebx, cl
    jz HASH_END
HASH_LOOP:
    sub ebx, eax
    shl eax, 5
    add eax, ebx
    or ch, ch
    movzx ebx, ch
    jz HASH_END
    sub ebx, eax
    shl eax, 5
    add eax, ebx
    shr ecx, 16
    add edx, byte 4
    or cl, cl
    movzx ebx, cl
    jz HASH_END
    sub ebx, eax
    shl eax, 5
    add eax, ebx
    or ch, ch
    movzx ebx, ch
    jz HASH_END
    sub ebx, eax
    shl eax, 5
    add eax, ebx
    mov ecx, dword [edx]
    or cl, cl
    movzx ebx, cl
    jnz HASH_LOOP
HASH_END:
    pop ebx
    retn