A program often prints a fixed message and one value that changes. Here the changing part is a letter that the user types.
What to build
Read one letter and print Hello, followed by the letter and an exclamation mark.
Requirements
- Store the text
Hello,in the data segment and print it with service 9 (it must end with$). - Read the letter with service 1.
- Print the letter, then
!, and nothing else.
Input
One letter, then Enter.
Output
One line, for example Hello, R! for the letter R.
Constraints
The input is one letter, upper or lower case.
Example
Input:
R
Output:
Hello, R!
Why it works
The string service prints the fixed part and the character service prints the part that changes. The letter has to be saved in a register that service 9 does not change, because every INT 21h call is free to overwrite AX.
Examples
R
Hello, R!
a
Hello, a!
Hints
Hint 1
Put the text 'Hello, $' in the data segment, and print it with AH = 9 and LEA DX.
Hint 2
Read the letter with AH = 1 and keep it in another register (such as BL), because the next INT 21h changes AL and AH.
Hint 3
Print the letter with AH = 2, then the character '!' the same way.
Solution
Show one correct solution (try it yourself first)
; Greet by a letter
.MODEL SMALL
.STACK 100H
.DATA
MSG DB 'Hello, $'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
MOV AH, 1
INT 21H ; AL = the letter
MOV BL, AL ; keep it safe
LEA DX, MSG
MOV AH, 9
INT 21H ; print 'Hello, '
MOV DL, BL
MOV AH, 2
INT 21H ; the letter
MOV DL, '!'
INT 21H
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