-
Notifications
You must be signed in to change notification settings - Fork 0
/
guess.asm
108 lines (91 loc) · 2.31 KB
/
guess.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
.MODEL SMALL
.STACK 100H
.DATA
STRING_1 DB 'Enter your number:$'
STRING_2 DB 'guess?$'
STRING_3 DB 'correct $'
STRING_4 DB 'more than $'
STRING_5 DB 'less than $'
.CODE
MAIN PROC
MOV AX,@DATA ;initialize DS
MOV DS,AX
LEA DX,STRING_1 ; 'Enter your number:'
MOV AH,9
INT 21H
MOV AH,1 ;input number
INT 21H
MOV BL,AL
MOV AH,2 ;carriage return
MOV DL,0DH
INT 21H
MOV DL,0AH ;line feed
INT 21H
LEA DX,STRING_2 ; 'guess?'
MOV AH,9
INT 21H
MOV AH,2 ;carriage return
MOV DL,0DH
INT 21H
MOV DL,0AH ;line feed
INT 21H
MOV AH,1 ;input guess number
INT 21H
MOV BH,AL
CMP BL,BH ;Compare BL,BH
JL b ;more than
JE c
a:
MOV AH,2 ;carriage return
MOV DL,0DH
INT 21H
MOV DL,0AH ;line feed
INT 21H
LEA DX,STRING_5 ;load & display 'less than '
MOV AH,9
INT 21H
MOV AH,2 ;carriage return
MOV DL,0DH
INT 21H
MOV DL,0AH ;line feed
INT 21H
MOV AH,1 ;input new guess number
INT 21H
MOV BH,AL
CMP BL,BH ;Compare BL,BH
JG a ;less than
JE c
b:
MOV AH,2 ;carriage return
MOV DL,0DH
INT 21H
MOV DL,0AH ;line feed
INT 21H
LEA DX,STRING_4 ;load & display 'more than'
MOV AH,9
INT 21H
MOV AH,2 ;carriage return
MOV DL,0DH
INT 21H
MOV DL,0AH ;line feed
INT 21H
MOV AH,1 ;input guess number
INT 21H
MOV BH,AL
CMP BL,BH ;Compare BL,BH
JG a ;less than
JL b ;more than
c:
MOV AH,2 ;carriage return
MOV DL,0DH
INT 21H
MOV DL,0AH ;line feed
INT 21H
LEA DX,STRING_3 ;''correct''
MOV AH,9
INT 21H
; return to DOS
MOV AH,4CH
INT 21H ; DOS exit
MAIN ENDP
END MAIN