-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem1.asm
197 lines (136 loc) · 2.65 KB
/
problem1.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
.MODEL SMALL
.STACK 100H
.DATA
CR EQU 0DH
LF EQU 0AH
NEWLINE DB CR, LF , '$'
PROMPT1 DB 'First Number = ? $'
PROMPT2 DB 'Second Number = ? $'
PROMPT3 DB 'Thrid Number = ? $'
OPT1 DB 'All the numbers are equal $'
OPT2 DB 'Second Maximum Number = $'
X DB ?
Y DB ?
Z DB ?
MX1 DB ?
MX2 DB ?
.CODE
MAIN PROC
;DATA SEGMENT INITIALIZATION
MOV AX, @DATA
MOV DS, AX
;INPUT X
;print user prompt
LEA DX, PROMPT1
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
; TRANSFER input to variable
SUB AL, 30H
MOV X, AL ; output is stored in AX
; OUTPUT NEWLINE
LEA DX, NEWLINE
MOV AH,9
INT 21H
;INPUT Y
;print user prompt
LEA DX, PROMPT2
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
; TRANSFER input to variable
SUB AL, 30H
MOV Y, AL ; output is stored in AX
; OUTPUT NEWLINE
LEA DX, NEWLINE
MOV AH,9
INT 21H
;INPUT Z
;print user prompt
LEA DX, PROMPT3
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
; TRANSFER input to variable
SUB AL, 30H
MOV Z, AL ; output is stored in AX
; OUTPUT NEWLINE
LEA DX, NEWLINE
MOV AH,9
INT 21H
IS_ALL_EQ:
MOV AL,X
CMP AL,Y
JNE IF_1
CMP AL,Z
JNE IF_1
JMP DISPLAY_ALL_EQUAL
;OPERATION
IF_1:
MOV AL,X
CMP AL,Y ;
JNG ELSE_1 ; write opposite condition here
MOV AL,X ; X > Y
MOV MX1,AL
MOV AL,Y
MOV MX2,AL
JMP IF_2
ELSE_1:
MOV AL,Y ; Y >= X
MOV MX1,AL
MOV AL,X
MOV MX2,AL
IF_2:
MOV AL,Z
CMP AL,MX1
JNG IF_3
; Z > MX1
MOV AL,MX1
MOV MX2,AL ; MX2 = MX1
MOV AL,Z
MOV MX1,AL ; MX1 = Z
JMP DISPLAY
IF_3:
MOV AL,Z
CMP AL,MX2
JNG IF_4
; Z > MX2
MOV AL,Z
MOV MX2,AL
JMP DISPLAY
IF_4:
; Z < MX2 , now we need to check if MX1 are MX2 are same , in that case MX2 is Z
MOV AL,MX1
CMP AL,MX2
JE TWO_MAX_SAME
JMP DISPLAY
TWO_MAX_SAME:
MOV AL,Z
MOV MX2,AL ; Z is the MX2
JMP DISPLAY
DISPLAY_ALL_EQUAL:
;print string
LEA DX, OPT1
MOV AH, 9
INT 21H
JMP EXIT
DISPLAY:
;print string
LEA DX, OPT2
MOV AH, 9
INT 21H
;display Z
MOV AH, 2
ADD MX2,30H
MOV DL, MX2
INT 21H
JMP EXIT
EXIT:
;DOS EXIT
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN