TITLE         String length procedure         MODULE2.ASM
COMMENT |
        Objective: To write a procedure to compute string
                   length of a NULL terminated string.
            Input: String pointer in BX register.
|          Output: Returns string length in AX.
.MODEL SMALL
.CODE
PUBLIC string_length
string_length PROC
      ; all registers except AX are preserved
      push    SI             ; save SI
      mov     SI,BX          ; SI := string pointer
repeat1:
      cmp     BYTE PTR [SI],0  ; is it NULL?
      je      done             ; if so, done
      inc     SI               ; else, move to next character
      jmp     repeat1          ;       and repeat
done:
      sub     SI,BX          ; compute string length
      mov     AX,SI          ; return string length in AX
      pop     SI             ; restore SI
      ret
string_length ENDP
      END
