;
; 这是自编的strtok()函数
;
.model c,small
.data
NUL = 0000H
pp dw NUL
.code
public _strtok
; char* strtok (char *str,const char *tok)
; /* strtok size = 80 */
str equ word ptr [bp+04]
tok equ word ptr [bp+06]
_strtok proc
push bp
mov bp,sp
push si
mov bx,str
cmp bx,NUL
jnz step1
mov bx,pp
step1: jmp short here
loop1: call istok
jb step2
inc bx
here: mov ah,[bx]
and ah,ah
jnz loop1
mov ax,NUL
jmp short done
step2: mov dx,bx
jmp short there
loop2: call istok
jb incbx
mov byte ptr [bx],0
inc bx
jmp short retdx
incbx: inc bx
there: mov ah,[bx]
and ah,ah
jnz loop2
retdx: mov ax,dx
mov pp,bx
done: pop si
pop bp
ret
istok: mov si,tok
cld
next: lodsb
cmp al,+1
jb retis
cmp al,ah
jne next
retis: ret
_strtok endp
end
;
; 这是MSC6.0的strtok()函数
; 栈区开辟了长32字节的位表
;
.MODEL C,SMALL
.DATA
dw0000 DW ?
.CODE
PUBLIC _strtok
; char * strtok (char *str, char *tok)
; /* strtok size = 143 */
_strtok PROC
PUSH BP
MOV BP,SP
SUB SP,32
PUSH SI
PUSH DI
PUSH SS
POP ES
MOV CX,10h
XOR AX,AX
LEA DI,[BP-20h]
REP STOSW
MOV SI,[BP+06]
lab018B:LODSB
OR AL,AL
JZ lab01A4
MOV DI,AX
MOV CX,AX
MOV AL,01h
AND CL,07h
SHL AL,CL
MOV CL,03h
SHR DI,CL
OR BYTE PTR [BP+DI-20h],AL
JMP SHORT lab018B
lab01A4:MOV SI,WORD PTR [BP+04]
OR SI,SI
JNZ lab01AF
MOV SI,dw0000
lab01AF:LODSB
AND AX,00FFh
JNZ lab01BC
DEC SI
MOV dw0000,SI
JMP SHORT lab01FD
lab01BC:MOV DI,AX
MOV CX,AX
MOV AL,01h
AND CL,07h
SHL AL,CL
MOV CL,03h
SHR DI,CL
AND AL,BYTE PTR [BP+DI-20h]
JNZ lab01AF
LEA AX,WORD PTR [SI-01]
MOV dw0000,AX
lab01D6:LODSB
AND AX,00FFh
JNZ lab01E1
LEA AX,WORD PTR [SI-01]
JMP SHORT lab01F9
lab01E1:MOV DI,AX
MOV CX,AX
MOV AL,01h
AND CL,07h
SHL AL,CL
MOV CL,03h
SHR DI,CL
AND AL,BYTE PTR [BP+DI-20h]
JZ lab01D6
MOV BYTE PTR [SI-01],AH
XCHG SI,AX
lab01F9:XCHG AX,dw0000
lab01FD:POP DI
POP SI
MOV SP,BP
POP BP
RET
_strtok ENDP
END
;
; 这是Turbo C2.0的strtok()函数
;
.MODEL C,SMALL
.DATA
dw0000 DW ?
.CODE
PUBLIC _strtok
; char* strtok (char *s1, const char *s2)
; /* STRTOK size = 140 */
_strtok PROC
PUSH BP
MOV BP,SP
PUSH SI
PUSH DI
CMP WORD PTR [BP+04],00h
JZ lab018C
MOV AX,WORD PTR [BP+04]
MOV dw0000,AX
lab018C:JMP SHORT lab01B0
lab018E:MOV SI,WORD PTR [BP+06]
JMP SHORT lab01A0
lab0193:MOV AL,BYTE PTR [SI]
MOV BX,dw0000
CMP AL,BYTE PTR [BX]
JNZ lab019F
JMP SHORT lab01A5
lab019F:INC SI
lab01A0:CMP BYTE PTR [SI],00h
JNZ lab0193
lab01A5:CMP BYTE PTR [SI],00h
JNZ lab01AC
JMP SHORT lab01B9
lab01AC:INC dw0000
lab01B0:MOV BX,dw0000
CMP BYTE PTR [BX],00h
JNZ lab018E
lab01B9:MOV BX,dw0000
CMP BYTE PTR [BX],00h
JNZ lab01C6
XOR AX,AX
JMP SHORT lab0201
lab01C6:MOV DI,dw0000
JMP SHORT lab01F4
lab01CC:MOV SI,WORD PTR [BP+06]
JMP SHORT lab01EB
lab01D1:MOV AL,BYTE PTR [SI]
MOV BX,dw0000
CMP AL,BYTE PTR [BX]
JNZ lab01EA
MOV BX,dw0000
MOV BYTE PTR [BX],00h
INC dw0000
MOV AX,DI
JMP SHORT lab0201
lab01EA:INC SI
lab01EB:CMP BYTE PTR [SI],00h
JNZ lab01D1
INC dw0000
lab01F4:MOV BX,dw0000
CMP BYTE PTR [BX],00h
JNZ lab01CC
MOV AX,DI
JMP SHORT lab0201
lab0201:POP DI
POP SI
POP BP
RET
_strtok ENDP
END