print macro msg
lea dx, msg
mov ah, 09h
int 21h
endm
data segment
msg1 db 13, 10, 10, 'Enter the string: $'
msg2 db 13, 10, 10, 'The entered string is: $'
msg3 db 13, 10, 10, 'The length of the string is: $'
array db 20 dup(0)
lenstr db 5 dup(0)
data ends
code segment
assume cs: code, ds: data
start: mov ax, data
mov ds, ax
print msg1
lea si, array
这是一个 ALP,用于接受来自键盘的字符串并显示其长度。有很多部分我不明白该程序是如何工作的。
read: mov ah, 01h
int 21h
cmp al, 0dh
je next
mov [si], al
inc si
inc bl
jmp read
在这里,为什么我们要比较 al,0dh,当 al 开始时不包含任何值?因此,如果有人可以解释整个程序,那将非常有帮助。
next: mov al, '$'
mov [si], al
print msg2
print array
print msg3
lea si, lenstr
xor ax, ax
mov al, bl
mov bl, 10
div bl
add al, 30h
mov [si], al
inc di
add ah, 30h
mov [si], ah
inc si
mov al, '$'
mov [si], al
print lenstr
mov ax, 4c00h
int 21h
code ends
end start
另外,我们不能只用于count db $-array
查找字符串的长度吗?
read: mov ah, 01h ; Identification of DOS service.
int 21h ; Invokation of the service.
cmp al, 0dh
je next
mov [si], al
inc si
inc bl
jmp read
DOS service Int 21h/AH=01h等待直到用户按下一个键,例如数字5,AL=35h
在这种情况下它返回。当 s|he 按Enter 键(表示字符串结束)时,服务返回AL=0Dh
。
为什么我们要比较 al,0dh,当 al 开始时不包含任何值?
你最好问一下,bl
当我们不知道之前有什么时,我们为什么要递增?我们不能相信寄存器在我们的程序开始时包含 0(您中的一些人确实如此)。显然bl
是为了计算输入的字符数。
另外,我们不能只使用 count db $-array 来查找字符串的长度吗?
仅当字符串在程序中静态定义时。我们不知道用户要输入多少个字符,因此我们必须在运行时动态计算它们。在宏中使用的 DOS 服务Int 21h/AH=09h要求在最后输入的字符后
插入$。print
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句