title: Accepting a string and displaying its length in assembly
body: <pre><code>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
  </code></pre>
  <p>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.</p>
  <pre><code>read:       mov ah, 01h
  int 21h
  cmp al, 0dh
  je next
  mov [si], al
  inc si
  inc bl
  jmp read
  </code></pre>
  <p>Here, why are we comparing <code>al, 0dh</code>, when <code>al</code> does not contain any value to begin with?<br />
  So, it will be really helpful if someone could explain the whole program.</p>
  <pre><code>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
  </code></pre>
  <p>Also, can't we just use <code>count db $-array</code> to find the length of the string?</p>