To perform string operations using DOS interrupts.
Create a file named exp9.asm in Notepad and save it in D:\TASM:
.model small
.stack 100h
.data
msg db "Enter a string: $"
newline db 0Dh, 0Ah, "$"
output_msg db "You entered: $"
buffer db 20, 0, 21 dup('$') ; max length, actual length, string buffer
.code
main proc
mov ax, @data
mov ds, ax
; Prompt
lea dx, msg
mov ah, 09h
int 21h
; Read string
lea dx, buffer
mov ah, 0Ah
int 21h
; Print newline
lea dx, newline
mov ah, 09h
int 21h
; Print output message
lea dx, output_msg
mov ah, 09h
int 21h
; Null-terminate the input string
mov bl, buffer+1 ; get actual length
mov bh, 0 ; clear high byte
mov buffer+2[bx], '$' ; add string terminator
; Display string
lea dx, buffer+2 ; offset to actual text
mov ah, 09h
int 21h
; Print newline
lea dx, newline
mov ah, 09h
int 21h
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