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
This is an ALP to accept a string from the keyboard and display its length. There are various parts where I don't understand how the program works.
read: mov ah, 01h
int 21h
cmp al, 0dh
je next
mov [si], al
inc si
inc bl
jmp read
Here, why are we comparing al, 0dh, when al does not contain any value to begin with?
So, it will be really helpful if someone could explain the whole program.
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
Also, can't we just use count db $-array to find the length of the string?