Assembly language program to input string from user and display its length
Code
org 100h
.stack 100h
.data
string db 100 dup ('$')
length db "The total length is: $"
.code
main proc
mov ax,@data
mov ds,ax
mov bx,0
mov si,offset string
l1: ;lable
mov ah,01
int 21h
cmp al,13 ;13 is enter key in ASCI
je dis
mov [si],al
inc bx
inc si
jmp l1
dis: ;dis is a lable
mov dx,10
mov ah,02
int 21h
mov dx,13
mov ah,02
int 21h
mov dx,offset length
mov ah,09
int 21h
mov ax,bx
mov bx,10
mov dx,0
mov cx,0
l2:
div bx
push dx
mov dx,0
inc cx
cmp ax,0
jne l2
mov ah,02
l3:
pop dx
add dx,48
int 21h
loop l3
mov ah,4ch
int 21h
main endp
end main
Output
Note: It will also include spaces in given string
Comments
Post a Comment