-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab5.asm
205 lines (147 loc) · 4.33 KB
/
lab5.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
; ******************************** SOL Q1 ****************************************************
.model small
.stack 100h
; .data
; .code
; ; connecting the data and code segment
; mov ax,@data
; mov ds,ax
; mov dl,1 ; for starting from 1
; add dl,48 ; adding 0 into it
; mov cx,5
; l1: ; add 2 and you would get even
; mov ah,02 ; printing scenes
; int 21h
; add dl,2
; loop l1
; mov dl,10 ; printing scenes
; mov ah, 2
; int 21h
; mov dl,13
; mov ah, 2
; int 21h
; mov dl,2
; add dl,48
; mov cx,5
; l2: ; add 2 and you would get odd
; mov ah,02
; int 21h
; add dl,2
; loop l2
; mov ah,4ch
; int 21h
; end
; ******************************** Ending SOL Q1 ****************************************************
; ******************************** Starting SOL Q1 ****************************************************
; .data
; sum dw 0 ; initialize variable to store the sum
; .code
; main proc
; mov ax, @data ; initialize data segment
; mov ds, ax
; mov cx, 3 ; initialize loop counter to 3
; mov bx, 1 ; initialize variable to store current number to 1
; loop_start:
; add sum, bx ; add current number to sum
; inc bx ; increment current number by 1
; loop loop_start ; decrement loop counter and loop until it reaches 0
; ; print the sum
; mov ax, sum ; move sum to ax register
; add ax, 30h ; convert sum to ASCII value
; mov ah, 02h ; set AH to 02h for printing character
; mov dl, al ; move ASCII value of sum to DL
; int 21h
; mov ah, 4ch ; exit program
; int 21h
; main endp
; end main
; ******************************** Ending SOL Q2 ****************************************************
; ******************************** SOL Q3 ****************************************************
; .data
; .code
; main proc
; mov ax, @data ; initialize data segment
; mov ds, ax
; ; print capital letters from A to Z
; mov dl, 'A' ; set starting character
; loop_capitals:
; mov ah, 02h ; set AH to 02h for printing character
; int 21h ; output current character
; inc dl ; increment current character
; cmp dl, 'Z' ; compare current character to 'Z'
; jle loop_capitals ; loop until current character is greater than 'Z'
; ; print newline character
; mov dl, 10 ; ASCII value of newline character
; mov ah, 02h ; set AH to 02h for printing character
; int 21h ; output newline character
; ; print small letters from a to z
; mov dl, 'a' ; set starting character
; loop_smalls:
; mov ah, 02h ; set AH to 02h for printing character
; int 21h ; output current character
; inc dl ; increment current character
; cmp dl, 'z' ; compare current character to 'z'
; jle loop_smalls ; loop until current character is greater than 'z'
; ; print newline character
; mov dl, 10 ; ASCII value of newline character
; mov ah, 02h ; set AH to 02h for printing character
; int 21h ; output newline character
; mov ah, 4ch ; exit program
; int 21h
; main endp
; end main
; ******************************** Ending SOL Q3 ****************************************************
; ******************************** SOL Q4 ****************************************************
; .data
; n db 10 ; number of natural numbers to print
; count db 1 ; counter for loop
; .code
; main proc
; mov ax, @data ; initialize data segment
; mov ds, ax
; ; print the first 10 natural numbers using a loop
; mov cx, 10 ; set CX to the value of n
; loop_numbers:
; mov ah, 02h ; set AH to 02h for printing character
; mov dl, count ; move the value of count to DL for printing
; add dl, 48 ; convert DL to its ASCII equivalent
; int 21h ; output the current number
; inc count ; increment the counter
; loop loop_numbers ; repeat the loop until CX is zero
; mov ah, 4ch ; exit program
; int 21h
; main endp
; end main
; ******************************** Ending SOL Q4 ****************************************************
.data
count dw ?
var1 dw ?
.code
main proc
mov ax,@data
mov ds,ax
mov var1 , 48
mov bx, 1
mov cx, 5
L1:
mov count,cx
mov cx, bx
L2:
Mov dl, var1
mov ah,2
int 21h
loop L2
mov dl,10
mov ah, 2
int 21h
inc var1
mov dl,13
mov ah, 2
int 21h
inc bx
mov cx,count ; restoring value
loop L1
mov ah,4ch
int 21h
main endp
end main