标题:C语言标准库中strtok函数的汇编代码
只看楼主
–★–
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1512
专家分:0
注 册:2006-5-1
 问题点数:0 回复次数:1 
C语言标准库中strtok函数的汇编代码

;
; 这是自编的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

搜索更多相关主题的帖子: strtok C语言 函数 汇编 NUL 
2006-05-18 19:49
–★–
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1512
专家分:0
注 册:2006-5-1
得分:0 

//自编的stpcpy函数
.model c,small
.code
public _stpcpy
;char* stpcpy (char *dest, const char *src)
; /* stpcpy size = 25 */
dest equ word ptr [bp+04]
src equ word ptr [bp+06]
_stpcpy proc
push bp
mov bp,sp
push si
mov si,src
mov bx,dest
cld
next: lodsb
mov [bx],al
inc bx
and al,al
jnz next
lea ax,[bx-1]
pop si
pop bp
ret
_stpcpy endp
end


//Turbo C 的stpcpy函数
//取自cs.lib库的反汇编
.MODEL C,SMALL
.CODE
EXTRN _memcpy:NEAR
EXTRN _strlen:NEAR
PUBLIC _stpcpy
; char* stpcpy (char *dest, const char *src)
; /* STPCPY size = 39 */
_stpcpy PROC
PUSH BP
MOV BP,SP
PUSH SI
PUSH WORD PTR [BP+06]
CALL _strlen
POP CX
MOV SI,AX
INC AX
PUSH AX
PUSH WORD PTR [BP+06]
PUSH WORD PTR [BP+04]
CALL _memcpy
ADD SP,+06
MOV AX,[BP+04]
ADD AX,SI
POP SI
POP BP
RET
_stpcpy ENDP
END


落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。
2006-05-18 21:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-65358-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.251988 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved