strfind: assure re-check is done on mismatch after initial match + add tests
This commit is contained in:
@@ -192,6 +192,17 @@ strfind:
|
|||||||
|
|
||||||
.noMatch:
|
.noMatch:
|
||||||
; not gonna figure out here if there was an existing match already. just XOR r10b,r10b and load original pointer to what[] to rsi
|
; not gonna figure out here if there was an existing match already. just XOR r10b,r10b and load original pointer to what[] to rsi
|
||||||
|
; EDIT: actually yes I am. strfind("gidgiddy", "giddy", 0); [gid]giddy<>[gid]dy is a match but then gid[g]iddy<>gid[d]y is not while it should check gid[g]iddy<>[g]iddy
|
||||||
|
test r10b, r10b
|
||||||
|
jz .continueLoop
|
||||||
|
mov rsi, r11
|
||||||
|
mov r9b, byte [rsi]
|
||||||
|
cmp byte [rdi], r9b
|
||||||
|
jne .itReallyWasNoMatchAfterAll
|
||||||
|
mov r8, rcx
|
||||||
|
inc rsi
|
||||||
|
jmp .continueLoop
|
||||||
|
.itReallyWasNoMatchAfterAll:
|
||||||
xor r10b, r10b
|
xor r10b, r10b
|
||||||
mov rsi, r11
|
mov rsi, r11
|
||||||
|
|
||||||
|
@@ -83,6 +83,7 @@ extern strcpy
|
|||||||
extern strcat
|
extern strcat
|
||||||
extern strclr
|
extern strclr
|
||||||
extern strcmp
|
extern strcmp
|
||||||
|
extern strfind
|
||||||
;convert.asm
|
;convert.asm
|
||||||
extern atoi
|
extern atoi
|
||||||
extern itoa
|
extern itoa
|
||||||
@@ -132,6 +133,7 @@ section .rodata
|
|||||||
TEST_strcat equ 1
|
TEST_strcat equ 1
|
||||||
TEST_strclr equ 1
|
TEST_strclr equ 1
|
||||||
TEST_strcmp equ 1
|
TEST_strcmp equ 1
|
||||||
|
TEST_strfind equ 1
|
||||||
;convert.asm
|
;convert.asm
|
||||||
TEST_atoi equ 1
|
TEST_atoi equ 1
|
||||||
TEST_itoa equ 1
|
TEST_itoa equ 1
|
||||||
@@ -315,6 +317,15 @@ section .rodata
|
|||||||
addTest(strcmp5, "strcmp(strBuff1, str1)") ;14
|
addTest(strcmp5, "strcmp(strBuff1, str1)") ;14
|
||||||
addTest(strcmp6_1, "strclr(strBuff1, 64)")
|
addTest(strcmp6_1, "strclr(strBuff1, 64)")
|
||||||
addTest(strcmp6_2, "strcmp(str1, strBuff1)") ;0
|
addTest(strcmp6_2, "strcmp(str1, strBuff1)") ;0
|
||||||
|
;strfind()
|
||||||
|
addTestHeader(_strfind, "strfind")
|
||||||
|
strfind_str db "I am not a gidgiddy goat or a gigiddyd goat but a giddy goat!",EOS
|
||||||
|
strfind_what db "giddy",EOS
|
||||||
|
strfind_strs db "\tstrfind_str: %s\n\tstrfind_what: %s\n",EOS
|
||||||
|
addTest(strfind1, "strfind(strfind_str, strfind_what, 0)") ;15
|
||||||
|
addTest(strfind2, "strfind(strfind_str, strfind_what, 15)") ;33
|
||||||
|
addTest(strfind3, "strfind(strfind_str, strfind_what, 33)") ;51
|
||||||
|
addTest(strfind4, "strfind(strfind_str, strfind_what, 51)") ;0
|
||||||
;atoi()
|
;atoi()
|
||||||
addTestHeader(_atoi, "atoi")
|
addTestHeader(_atoi, "atoi")
|
||||||
addTest(atoi1, "atoi(''079168045'')") ;79168045
|
addTest(atoi1, "atoi(''079168045'')") ;79168045
|
||||||
@@ -1144,6 +1155,48 @@ _start:
|
|||||||
assert_eq(0)
|
assert_eq(0)
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
|
;--- strfind()
|
||||||
|
%if TEST_strfind
|
||||||
|
printTestHeader(_strfind)
|
||||||
|
|
||||||
|
lea rdi, [rel strfind_strs]
|
||||||
|
lea rsi, [rel strfind_str]
|
||||||
|
lea rdx, [rel strfind_what]
|
||||||
|
call printf
|
||||||
|
|
||||||
|
; TEST 1: strfind(strfind_str, strfind_what, 0) => 15
|
||||||
|
printTest(strfind1)
|
||||||
|
lea rdi, [rel strfind_str]
|
||||||
|
lea rsi, [rel strfind_what]
|
||||||
|
xor rdx, rdx
|
||||||
|
call strfind
|
||||||
|
assert_eq(15)
|
||||||
|
|
||||||
|
; TEST 2: strfind(strfind_str, strfind_what, 15) => 33
|
||||||
|
printTest(strfind2)
|
||||||
|
lea rdi, [rel strfind_str]
|
||||||
|
lea rsi, [rel strfind_what]
|
||||||
|
mov rdx, 15
|
||||||
|
call strfind
|
||||||
|
assert_eq(33)
|
||||||
|
|
||||||
|
; TEST 3: strfind(strfind_str, strfind_what, 33) => 51
|
||||||
|
printTest(strfind3)
|
||||||
|
lea rdi, [rel strfind_str]
|
||||||
|
lea rsi, [rel strfind_what]
|
||||||
|
mov rdx, 33
|
||||||
|
call strfind
|
||||||
|
assert_eq(51)
|
||||||
|
|
||||||
|
; TEST 4: strfind(strfind_str, strfind_what, 51)
|
||||||
|
printTest(strfind4)
|
||||||
|
lea rdi, [rel strfind_str]
|
||||||
|
lea rsi, [rel strfind_what]
|
||||||
|
mov rdx, 51
|
||||||
|
call strfind
|
||||||
|
assert_eq(0)
|
||||||
|
%endif
|
||||||
|
|
||||||
;--- atoi()
|
;--- atoi()
|
||||||
%if TEST_atoi
|
%if TEST_atoi
|
||||||
printTestHeader(_atoi)
|
printTestHeader(_atoi)
|
||||||
|
Reference in New Issue
Block a user