Service 0Ah reads a whole line into a buffer. It fills in the number of characters it got, so the program knows how long the text is.
What to build
Read one line of text and print it twice, each time on a line of its own.
Requirements
- Read the line with service 0Ah.
- End the text with
$so that service 9 can print it. - Print the text, a new line (0Dh then 0Ah), and the text again.
Input
One line of 1 to 30 characters, then Enter.
Output
The line, then the same line again, on two lines.
Constraints
The text has letters, digits, spaces and punctuation, but no $.
Example
Input:
hello world
Output:
hello world
hello world
Why it works
The count in byte 1 of the buffer is the index of the first free place after the text, relative to byte 2, so BUF[BX + 2] is the place for the $. Service 9 then prints everything up to it, and since the text is still in memory it can be printed as often as needed.
Examples
hello world
hello world hello world
A
A A
Hints
Hint 1
Define a buffer for service 0Ah: BUF DB 40, ?, 40 DUP(?). Byte 0 is the size you allow, byte 1 is the count that DOS fills in.
Hint 2
After the call, put a $ at BUF + 2 + count so that service 9 knows where the text ends.
Hint 3
Print the text, a new line, the text again. The characters start at BUF + 2.
Solution
Show one correct solution (try it yourself first)
; Say the line twice
.MODEL SMALL
.STACK 100H
.DATA
BUF DB 40, ?, 40 DUP(?)
NL DB 0DH, 0AH, '$'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
LEA DX, BUF
MOV AH, 0AH
INT 21H ; read the line
MOV BL, BUF + 1 ; how many characters
MOV BH, 0
MOV BUF[BX + 2], '$'
LEA DX, BUF + 2
MOV AH, 9
INT 21H ; the first time
LEA DX, NL
INT 21H
LEA DX, BUF + 2
INT 21H ; the second time
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
▶ Open this solution in the compiler, then press Visualize to watch it run step by step