StringSplitEx 函数
StringSplitEx 函数使用分隔符将字符串分割为标记,并将它们保存在缓冲区中。每个标记以零结尾。在 CX 中返回标记的数量。函数会自动将栈对齐 6 个字节。
参数(栈): 1. 字符串的指针。2. 分隔符字符串的指针。3. 标记缓冲区的指针。
返回值: CX - 标记的数量。
标志状态: 函数不改变标志状态。
程序源代码
Intel 8086 汇编程序示例,演示使用 StringSplitEx 函数按分隔符将字符串分割为标记,以及辅助函数 PrintSplitString 的使用。
title .286C .model small .stack 100h data segment public string db "Spring wind, caressing the leaves, whispers secrets of blooming gardens.\0" buffer db 80 dup(0) delims db " ,.\0" data ends code segment public assume ds:data, cs:code include Handyfar.inc ; 包含函数文件 include Handymac.inc ; 包含宏文件 main proc call SetDataSegment ; 调用过程 SetDataSegment pushs ds:[buffer] ; 第3步:将变量 buffer 的地址压入栈顶 pushs es:[delims] ; 第2步:将变量 delims 的地址压入栈顶 pushs ds:[string] ; 第1步:将变量 string 的地址压入栈顶 call StringSplitEx ; 调用过程 StringSplitEx(string, delims, buffer) := CX push FALSE ; 第3步:FALSE 表示以空格分隔输出字符串 push cx ; 第2步:将标记数量压入栈顶 pushs ds:[buffer] ; 第1步:将变量 buffer 的地址压入栈顶 call PrintSplitString ; 调用过程 PrintSplitString(buffer, cx, FALSE) push 0 ; 将字节值(返回代码)压入栈顶 call ExitProcessEx ; 调用过程 ExitProcessEx(0) main endp code ends end main
Spring wind caressing the leaves whispers secrets of blooming gardens
示例取自教材 "HANDYFAR - MASM (Dovgopolov Evgeny Sergeevich)".