-
Notifications
You must be signed in to change notification settings - Fork 0
/
13 String input-output.asm
50 lines (42 loc) · 1.17 KB
/
13 String input-output.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
.MODEL SMALL
.STACK 100H
.DATA
STR DB '0'
MSG1 DB 'Enter a string: $'
.CODE
MAIN PROC
MOV AX, @data ; initialize DS
MOV DS, AX
MOV SI, 0 ; input index
MOV CX, 0 ; size of string
MOV AH, 9 ; display MSG1
LEA DX, MSG1
INT 21h
MOV AH, 1 ; set AH to chat input
INPUT:
INT 21H
MOV STR[SI], AL ; put AL in STR[SI]
INC CX
CMP AL, 13 ; check if the input is 'cret'
JE NEW_LINE
INC SI ; increase SI for the next input
JMP INPUT
NEW_LINE:
MOV AH, 2 ; display new line
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
DEC CX ; since we have 'cret' in the last input
MOV SI, 0 ; to use SI as display index
JMP DISPLAY
DISPLAY:
MOV DL, STR[SI] ; display the input
INT 21H
INC SI
LOOP DISPLAY
EXIT:
MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP
END MAIN