-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrcasecmp.asm
55 lines (48 loc) · 926 Bytes
/
strcasecmp.asm
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
;;
;; EPITECH PROJECT, 2024
;; minilibc
;; File description:
;; strcasecmp
;;
SECTION .text
GLOBAL strcasecmp
strcasecmp:
XOR rax, rax
PUSH rbx
PUSH rdx ; counter
XOR rdx, rdx
.loop:
; compare rdi[rdx] and rsi[rdx]
MOV al, BYTE [rdi + rdx]
MOV ah, BYTE [rsi + rdx]
CMP al, ah
JE .inc
MOV bl, al
MOV bh, ah
; 'a' | 32 = 'A'
OR bl, 0b100000 ; 'A' | 32 = 'A'
CMP bl, 'a' ; because ascii table trick
JL .end ; bitwise xor yes yes
CMP bl, 'z'
JG .end ; also we need to check if
; it's a letter.
OR bh, 0b100000 ; much not gud stuff would
CMP bh, 'a' ; happen if it's not
JL .end ; 'cause we messing around
CMP bh, 'z' ; with the ascii table
JG .end
MOV al, bl
MOV ah, bh
CMP al, ah
JNE .end
.inc:
CMP al, 0
JE .end
INC rdx
JMP .loop
.end:
POP rdx
POP rbx
SUB al, ah
MOVSX rax, al
RET