Write a assembly program to calculate the length of String.
Create a file named exp8.c in Notepad and save it in D:\TASM:
.model small
.stack 100h
.data
str_s db 'COMPUTERS$'
length db 0
msg db 0Dh,0Ah,'Length of string = $'
.code
main proc
mov ax, @data
mov ds, ax
mov si, offset str_s
next:
mov al, [si]
cmp al, '$'
je show
inc si
inc length
jmp next
show:
lea dx, msg
mov ah, 09h
int 21h ; Print message
mov al, length
add al, 30h ; Convert to ASCII
mov dl, al
mov ah, 02h
int 21h ; Print the length digit
mov ah,4ch
int 21h
main endp
end main
Inside DOSBox, compile and run:
tasm filename.asm
tlink filename.obj
Run Debug:
td filename.exe