-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab09.asm
259 lines (210 loc) · 4.16 KB
/
Lab09.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
; ********************************** SOL Q1 *********************************************
; ******************************** Count no of constants and Vowels *********************************
.model small
.stack 100h
.data
msg1 db 'Enter a string: $'
msg2 db 'Number of vowels: $'
msg3 db 'Number of consonants: $'
inputStr db 100, '$'
vowelsCount dw ?
consonantsCount dw ?
.code
mov ax, @data
mov ds, ax
; Display message to enter a string
mov ah, 09h
lea dx, msg1
int 21h
; Read user input
mov ah, 0Ah
lea dx, inputStr
int 21h
; Call procedure to count vowels and consonants
lea si, inputStr+2
call Vowel_Const_Count
; Display number of vowels
mov ah, 09h
lea dx, msg2
int 21h
mov ax, vowelsCount
call printNumber
; Display number of consonants
mov ah, 09h
lea dx, msg3
int 21h
mov ax, consonantsCount
call printNumber
; Exit program
mov ah, 4ch
int 21h
; Procedure to count the number of vowels and consonants in a string
Vowel_Const_Count proc
mov cx, 0
mov dx, 0
countLoop:
mov al, [si]
cmp al, 0
je countEnd
cmp al, 'a'
jl notLetter
cmp al, 'z'
jg notLetter
cmp al, 'e'
je isVowel
cmp al, 'i'
je isVowel
cmp al, 'o'
je isVowel
cmp al, 'u'
je isVowel
cmp al, 'a'
je isVowel
jmp notVowel
isVowel:
inc cx
jmp nextLetter
notVowel:
inc dx
jmp nextLetter
notLetter:
; skip non-letter characters
nextLetter:
inc si
jmp countLoop
countEnd:
mov vowelsCount, cx
mov consonantsCount, dx
ret
Vowel_Const_Count endp
; Procedure to print a number to the console
printNumber proc
mov bx, 10
mov cx, 0
printLoop:
xor dx, dx
div bx
push dx
inc cx
cmp ax, 0
jne printLoop
printDigits:
pop dx
add dl, '0'
mov ah, 02h
int 21h
loop printDigits
ret
printNumber endp
end
; ********************************** END SOL Q1 *********************************************
; ************************************ Sol Q 2 *********************************************
; .data
; num dw 5
; result dw ?
; counter dw ?
; firststring db 10h,13h,"Please Enter Number", "$"
; outputMsg db 'Factorial: $'
; .code
; main proc
; mov ax, @data
; mov ds, ax
; Factorial MACRO num
; mov result, 1
; mov counter, num
; loopStart:
; cmp counter, 0
; jle loopEnd
; mov ax, result
; mul counter
; mov result, ax
; dec counter
; jmp loopStart
; loopEnd:
; endm
; ; calling the Factorial macro
; Factorial num
; mov ah , 09h
; mov dx , offset firststring
; int 21h
; mov num , dx
; ; print the result
; exit:
; mov ah, 09h
; lea dx, outputMsg
; int 21h
; mov ah , 02h
; mov dx, result
; add dx, 30h
; int 21h
; mov ah ,4ch
; int 21h
; main endp
; end
; ************************************** End Sol Q 2 *****************************************
; student struct
; names db 100 dup(?)
; age dw ?
; marks dw ?
; student ends
; .data
; string1 db "Please Enter the name: $"
; newline db 10, 13, "$"
; string2 db "Please Enter Age: $"
; string3 db "Please Enter marks: $"
; .code
; mov ax, @data
; mov ds, ax
; s1 student <>
; ; Reading student name
; mov ah, 09h
; mov dx, offset string1
; int 21h
; mov ah, 0Ah
; mov dx, offset s1.names
; int 21h
; ; Reading student age
; mov ah, 09h
; mov dx, offset string2
; int 21h
; mov ah, 01h
; int 21h
; sub al, 30h
; mov s1.age, ax
; ; Reading student marks
; mov ah, 09h
; mov dx, offset string3
; int 21h
; mov ah, 01h
; int 21h
; sub al, 30h
; mov s1.marks, ax
; ; Displaying student information
; mov ah, 09h
; mov dx, offset s1.names
; int 21h
; mov dl, ','
; mov ah, 02h
; int 21h
; mov ah, 02h
; mov dl, ' '
; int 21h
; mov ax, s1.age
; add ax, 30h
; mov dl, ah
; mov ah, 02h
; int 21h
; mov dl, ','
; mov ah, 02h
; int 21h
; mov ah, 02h
; mov dl, ' '
; int 21h
; mov ax, s1.marks
; add ax, 30h
; mov dl, ah
; mov ah, 02h
; int 21h
; mov ah, 4ch
; int 21h
; end