天天看點

彙編語言統計字元串的長度

求字元串的長度。在資料段定義一個字元串首位址為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

           

繼續閱讀