用汇编编写一个求字符串长度的程序解决思路

用汇编编写一个求字符串长度的程序
题目如下:

编写一个求字符串的子程序STRLEN,该字符串以0位结束标志,其首地址存放在DS:DX,其长度存在CX返回。

------解决方案--------------------
MOV CX,FFFF
MOV DI,STRADDR // ES:DI指向串
MOV AL,00 // AL置0,要搜索的串结束符
REPNZ
SCASB // 重复搜索直到结束符
NEG CX
DEC CX
DEC CX
// 到此CX中已经得到串长度
------解决方案--------------------
;---------------------------------------------------
Get_String_Length PROC NEAR
;
; Get the length of a string end with zero.
; Receive(s): ES:BP = segment:offset of the string
; Return(s): CX = length of the string
;---------------------------------------------------

PUSH BP

MOV CX,0 ;clear CX counter
Counting:
CMP BYTE PTR ES:[BP],0
JE Count_Finish
INC CX
INC BP
JMP Counting
Count_Finish:
POP BP

RET

Get_String_Length ENDP