I went to write a toy recently and needed a word tokeniser and did not have one. This is the test piece for the algo that will be added to the main library.
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include64\masm64rt.inc
.code
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
entry_point proc
LOCAL pcmd :QWORD ; pseudo cmd line pointer
LOCAL parr :QWORD ; array pointer
LOCAL arrm[16] :QWORD ; array memory
LOCAL acnt :QWORD
LOCAL .r15 :QWORD
mov .r15, r15 ; preserve non volatile register
mov parr, ptr$(arrm) ; get array pointer
mrm pcmd, "one , two,three , four,five , six,seven , eight,nine , ten"
rcall wordtok,pcmd,parr,44 ; call the word parser
mov acnt, rax ; get the arg count
mov r15, parr ; load array address into r15
sub r15, 8 ; set up loop
lbl:
add r15, 8 ; add 8 byte offset
rcall szTrim,QWORD PTR [r15] ; trim any junk from both ends
conout QWORD PTR [r15],lf ; display each word
sub acnt, 1 ; decrement the counter
jnz lbl ; loop back if not zero
mov r15, .r15 ; restore non volatile register
waitkey
invoke ExitProcess,0
ret
entry_point endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
NOSTACKFRAME
wordtok proc ; pcmd:QWORD, parr:QWORD, dlmt:QWORD
; -------------------------------------------
; tokenise text based on a supplied delimiter
; text is parsed in place (no copy)
; pcmd = pointer to text to tokenise
; parr = array pointer
; dlmt = delimiter as user supplied ascii char as number IE: 44 = ","
; return value = word or text count
; -------------------------------------------
mov r11, rcx ; pcmd
mov r10, rdx ; parr
xor r9, r9 ; use r9 as arg counter
mov [r10], r11 ; load first start address
add r10, 8
add r9, 1 ; increment counter
sub r11, 1
lbl0:
add r11, 1
movzx rax, BYTE PTR [r11]
test rax, rax ; test for and exit on terminator
jz out1
cmp rax, r8 ; check if char is delimiter
jne lbl0 ; loop back if not
mov BYTE PTR [r11], 0 ; terminate array member
add r11, 1 ; increment to next arg 1st char
add r9, 1 ; increment the arg counter
mov [r10], r11 ; load next text address into r10
add r10, 8 ; add 8 for next array member
jmp lbl0
out1:
mov rax, r9 ; return the arg count
ret
wordtok endp
STACKFRAME
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
; wordtok proc pcmd:QWORD, parr:QWORD, dlmt:QWORD
; ; -------------------------------------------
; ; tokenise text based on a supplied delimiter
; ; text is parsed in place (no copy)
; ; pcmd = pointer to text to tokenise
; ; parr = array pointer
; ; dlmt = delimiter as user supplied ascii char as number IE: 44 = ","
; ; return value = word or text count
; ; -------------------------------------------
; mov r11, pcmd
; mov r10, parr
; xor r9, r9 ; use r9 as arg counter
;
; mov [r10], r11 ; load first start address
; add r10, 8
; add r9, 1 ; increment counter
; sub r11, 1
; lbl0:
; add r11, 1
; movzx rax, BYTE PTR [r11]
; test rax, rax ; test for and exit on terminator
; jz out1
; cmp rax, dlmt ; check if char is delimiter
; jne lbl0 ; loop back if not
; mov BYTE PTR [r11], 0 ; terminate array member
; add r11, 1 ; increment to next arg 1st char
; add r9, 1 ; increment the arg counter
; mov [r10], r11 ; load next text address into r10
; add r10, 8 ; add 8 for next array member
; jmp lbl0
;
; out1:
; mov rax, r9 ; return the arg count
; ret
;
; wordtok endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end