-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProject_G_apple.asm
More file actions
212 lines (171 loc) · 4.24 KB
/
Project_G_apple.asm
File metadata and controls
212 lines (171 loc) · 4.24 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
org 100h
.model small
.stack 100h
.data
menu: DB 0Dh,0Ah,"- Apple Application -",0Dh,0Ah
DB "************************",0Dh,0Ah
DB "1- Make an order",0Dh,0Ah
DB "2- Display the Bill",0Dh,0Ah
DB "3- Check for a Price",0Dh,0Ah,
DB "4- Exit",0Dh,0Ah,'$'
CrLf db 13,10,'$' ; print newline
applemenu:
DB 0Dh,0Ah,"No. Device Price",0Dh,0Ah
DB "1- Mac 2000 S.R.",0Dh,0Ah
DB "2- iphone 4000 S.R.",0Dh,0Ah
DB "3- ipad 1700 S.R.",0Dh,0Ah
DB "4- Watch 1500 S.R.",0Dh,0Ah,
DB "Enter the order number (max 10 orders), 0 to go back to the menu: ",'$'
bill: DB 0Dh,0Ah,"the total bill is: ",'$'
price: DB 0Dh,0Ah,"You got a price because your bill is above 1500 S.R.",0Dh,0Ah,'$'
no_price:DB 0Dh,0Ah,"You didn't win a price",0Dh,0Ah,'$'
Mac DD 2000
iphone DD 4000
ipad DD 1700
Watch DD 1500
res DB 10 DUP ('$')
order DB 10 DUP ('$')
result DD 0
ticket_type DB 0
order_num DB 0
.code
begin:
mov ax,@data
mov ds,ax
start:
; Code to display the menu
mov dx, offset menu
mov ah, 09h
int 21h
;code to choose one choice from the menu
get_choice:
; read the user choice
mov ah, 7
int 21h
; first choice
cmp al, '1'
je FIRST_CHOICE
; second choice
cmp al, '2'
je SECOND_CHOICE
; third choice
cmp al, '3'
je THIRD_CHOICE
; third choice
cmp al, '4'
je FORTH_CHOICE
; loop back to get_choice until the user choose
jmp get_choice
;===== Make an order =====
FIRST_CHOICE:
; Code to display the info message
mov dx, offset CRLF
mov ah, 9
int 21h
mov dx, offset applemenu
mov ah, 9
int 21h
LEA SI, order
mov bl, 0
get_order:
; read the user choice (What device?)
mov ah, 1
int 21h
; if enter ZERO go back to menu
cmp al, '0'
je finish_order
; store the user input in order array
mov [SI], al
INC SI
INC bl
jmp get_order
finish_order:
INC bl
mov order_num, bl
mov dx, offset CRLF
mov ah, 9
int 21h
jmp start
SECOND_CHOICE:
; Code to display the ticket message
mov dx, offset bill
mov ah, 9
int 21h
LEA SI, order
mov bl, 0
mov cx, 0
; read from the order
read_order:
mov al, [SI]
INC SI
INC bl
cmp bl, order_num
je PRINT_RESULT
; calculate Mac order and add it to result
cmp al, '1' ; Mac
mov cx, mac
je calculate
; calculate Iphone order and add it to result
cmp al, '2' ; Iphone
mov cx, Iphone
je calculate
; calculate Ipad order and add it to result
cmp al, '3' ; Ipad
mov cx, Ipad
je calculate
; calculate Watch order and add it to result
cmp al, '4' ; Watch
mov cx, Watch
je calculate
calculate:
add cx, result
mov result, cx
jmp read_order
THIRD_CHOICE:
mov ax, result
mov result, 0
cmp ax, 1500
jg win_Price
mov dx, offset no_price
MOV AH,9
INT 21H
jmp start
win_Price:
mov dx, offset price
MOV AH,9
INT 21H
jmp start
;===== Print the result =====
PRINT_RESULT:
mov ax, result
; convert decimal to hex to print result
LEA SI, res
MOV CX,0
MOV BX,10
LOOP1:
MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1
ADD AL,30H
MOV [SI],AL
LOOP2:
POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
LEA DX,RES
MOV AH,9
INT 21H
;printing new line
mov dx, offset CRLF
MOV AH,9
INT 21H
jmp start
;===== Handle exit =====
FORTH_CHOICE:
mov ah,4Ch
int 21h