StringSplitEx function
The StringSplitEx function splits a string into tokens using delimiters and stores them in a buffer. Each token is null-terminated. It returns the number of tokens in CX. The function automatically aligns the stack to 6 bytes.
Parameters (stack): 1. Pointer to the string. 2. Pointer to the delimiter string. 3. Pointer to the buffer for tokens.
Return value: CX — the number of tokens.
Flag state: The function does not modify the flags.
Program source code
Intel 8086 assembly program example demonstrating the use of the StringSplitEx function to split a string into tokens by delimiters, and of the helper PrintSplitString function.
title .286C .model small .stack 100h data segment public string db "The spring wind, caressing leaves, whispers secrets, giving flower scent.\0" buffer db 80 dup(0) delims db " ,.\0" data ends code segment public assume ds:data, cs:code include Handyfar.inc ; Include the file with functions include Handymac.inc ; Include the file with macros main proc call SetDataSegment ; Call the SetDataSegment procedure pushs ds:[buffer] ; 3rd: Push the address of variable buffer onto the stack pushs es:[delims] ; 2nd: Push the address of variable delims onto the stack pushs ds:[string] ; 1st: Push the address of variable string onto the stack call StringSplitEx ; Call procedure StringSplitEx(string, delims, buffer) := CX push FALSE ; 3rd: The FALSE value prints the string separated by spaces push cx ; 2nd: Push the number of tokens onto the stack pushs ds:[buffer] ; 1st: Push the address of variable buffer onto the stack call PrintSplitString ; Call procedure PrintSplitString(buffer, cx, FALSE) push 0 ; Push the byte return code onto the top of the stack call ExitProcessEx ; Call the ExitProcessEx(0) procedure main endp code ends end main
The spring wind caressing leaves whispers secrets giving flower scent
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".