汇编语言统计字符串的长度

求字符串的长度。在数据段定义一个字符串首地址为String,该字符串以”$”作为结束标志,长度不超过100个字节,统计该字符串的长度并存入Len的内存单元。

data segment
String db 100,?,100 dup('$')
Len db 0
data ends

code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax

lea dx,String
mov ah,0ah   ;输入字符串
int 21h

mov dl,0ah   ;换行
mov ah,2
int 21h
mov dl,0dh
mov ah,2
int 21h

mov bx,offset String[2]
mov al,0
mov cl,0

do:
mov al,String[bx]
cmp al,'$'
je over
inc bx
inc cl
jmp do

over:
mov Len,cl
mov ah,4ch
int 21h

code ends
end start

亲测无错,
⬇ 记得点赞!

发布了4 篇原创文章 · 获赞 1 · 访问量 26

猜你喜欢

转载自blog.csdn.net/qq_45014208/article/details/103996702