-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel9.asm.html
executable file
·724 lines (540 loc) · 41 KB
/
kernel9.asm.html
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
<html>
<head>
<title>source code: kernel9.asm</title>
<meta name="description" content="source code">
<style>
a:link {text-decoration: none}
a:visited {text-decoration: none}
a:hover {text-decoration: none; color:#ff0000}
</style>
</head>
<body leftmargin=110 rightmargin=110 topmargin=20 bgcolor=#FFFFFF text=#000000 link=blue vlink=blue alink=blue>
<!-- * -->
<center> <font color=#FFFFFF> ;</font> <font size=2 face="Lucida Console"> kernel9.asm </font></center>
<!-- START AUTOMATIC ASM TO HTML EXPORT -->
<pre><font size=2 face="Lucida Console">
<font color=#C0C0C0>; This kernel is assumed to be loaded at memory location 0800:0000 </font>
<font color=#C0C0C0>; </font>
<font color=#000064>org</font> 0000h <font color=#C0C0C0>; loaded at 0800:0000 by loader </font>
<font color=#0000A0>jmp</font> start <font color=#C0C0C0>; first instruction must be jmp </font>
<font color=#C0C0C0>;-------------------------------------------------------------------- </font>
<font color=#C0C0C0>;-------------------------------------------------------------------- </font>
attrib <font color=#000064>db</font> 0110_1111b <font color=#C0C0C0>;cyan background, bright white foreground </font>
<font color=#C0C0C0>;-------------------------------------------- </font>
black <font color=#000064>equ</font> 0000b <font color=#C0C0C0>; black </font>
green <font color=#000064>equ</font> 0010b <font color=#C0C0C0>; green </font>
red <font color=#000064>equ</font> 0100b <font color=#C0C0C0>; red </font>
white <font color=#000064>equ</font> 1111b <font color=#C0C0C0>; white </font>
<font color=#C0C0C0>;-------------------------------------------- </font>
<font color=#C0C0C0>;-------------------------------------------- </font>
black_white <font color=#000064>equ</font> 0000_1111b <font color=#C0C0C0>; white text on black background </font>
blue_yellow <font color=#000064>equ</font> 0001_1110b <font color=#C0C0C0>; yellow text on blue background </font>
gray_black <font color=#000064>equ</font> 0111_0000b <font color=#C0C0C0>; black text on light gray background </font>
default <font color=#000064>equ</font> 0110_1111b <font color=#C0C0C0>; cyan background, bright white text </font>
<font color=#C0C0C0>;--------------------------------------------- </font>
option <font color=#000064>db</font> 0 <font color=#C0C0C0>; used for get input </font>
temp <font color=#000064>dw</font> 0
temp1 <font color=#000064>db</font> 0 <font color=#C0C0C0>; a temporary variable </font>
msg <font color=#000064>db</font> <font color=#800080>"Welcome to The Mini OS Kernel"</font>
msg_end:
invalid_msg <font color=#000064>db</font> 0dh,0ah,<font color=#800080>"Invalid option, Press Correct Letter"</font>
invalid_msg_end:
prompt <font color=#000064>db</font> 0dh,0ah,<font color=#800080>"What do you want to do ?"</font>
<font color=#000064>db</font> 0dh,0ah,<font color=#800080>"(R)Reverse Print - Input your string and get its reverse"</font>
<font color=#000064>db</font> 0dh,0ah,<font color=#800080>"(C)Colorized print - Print your string with your favorite color"</font>
<font color=#000064>db</font> 0dh, 0ah, <font color=#800080>"(A)Change Color Attribute - Change the background and font color"</font>
<font color=#000064>db</font> 0dh,0ah,<font color=#800080>"(S)Screen clear - Clear the entire screen"</font>
<font color=#000064>db</font> 0dh, 0ah, <font color=#800080>"(E)Exit - Exit the system (reboot)"</font>
prompt_end:
pr_str <font color=#000064>db</font> <font color=#800080>"Enter your string (Upto 80 characters): "</font>
pr_str_end:
color_sel <font color=#000064>db</font> 0ah, 0dh,<font color=#800080>"Select Color: (B)Black, (G)Green, (R)Red, (W)White "</font>
color_sel_end:
profile_select <font color=#000064>db</font> 0ah, 0dh, <font color=#800080>"Choose a profile: (1) - White font on black background"</font>
<font color=#000064>db</font> 0ah, 0dh, <font color=#800080>" (2) - Yellow font on blue background"</font>
<font color=#000064>db</font> 0ah, 0dh, <font color=#800080>" (3) - Black font on light gray background"</font>
<font color=#000064>db</font> 0ah, 0dh, <font color=#800080>" (4) - Default"</font>
profile_select_end:
reboot_msg <font color=#000064>db</font> 0dh,0ah,0dh,0ah, <font color=#800080>"Press any key to reboot...."</font>
reboot_msg_end:
str <font color=#000064>db</font> 80 dup(<font color=#800080>'$'</font>)
end_str:
<font color=#C0C0C0>;------------------------------------- MACROS----------------------------------------- </font>
<font color=#C0C0C0>;------------------------------------------------------------------------------------ </font>
<font color=#C0C0C0>; Macro: move_cursor </font>
move_cursor <font color=#00FF00>macro</font> col, row
<font color=#C0C0C0>; save register state </font>
<font color=#0000A0>push</font> <font color=#800000>ax</font>
<font color=#0000A0>push</font> <font color=#800000>bx</font>
<font color=#C0C0C0>; cursor move function </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 2
<font color=#0000A0>mov</font> <font color=#800000>dh</font>, row
<font color=#0000A0>mov</font> <font color=#800000>dl</font>, col
<font color=#0000A0>mov</font> <font color=#800000>bh</font>, 0 <font color=#C0C0C0>; page </font>
<font color=#0000A0>int</font> 10h
<font color=#C0C0C0>;restore register state </font>
<font color=#0000A0>pop</font> <font color=#800000>bx</font>
<font color=#0000A0>pop</font> <font color=#800000>ax</font>
endm
<font color=#C0C0C0>; Macro : move_next_line </font>
<font color=#C0C0C0>;-------------------------- </font>
move_next_line <font color=#00FF00>macro</font>
<font color=#0000A0>inc</font> <font color=#800000>dh</font>
<font color=#0000A0>mov</font> <font color=#800000>dl</font>, 0
move_cursor <font color=#800000>dl</font>, <font color=#800000>dh</font>
endm
<font color=#C0C0C0>;Macro : move_next_col </font>
<font color=#C0C0C0>;--------------------------- </font>
move_next_col <font color=#00FF00>macro</font>
<font color=#0000A0>inc</font> <font color=#800000>dl</font>
move_cursor <font color=#800000>dl</font>, <font color=#800000>dh</font>
endm
<font color=#C0C0C0>; macro : print_all </font>
<font color=#C0C0C0>;------------------ </font>
print_all <font color=#00FF00>macro</font>
<font color=#C0C0C0>; save regs </font>
<font color=#0000A0>push</font> <font color=#800000>ax</font>
<font color=#0000A0>push</font> <font color=#800000>bx</font>
<font color=#0000A0>push</font> <font color=#800000>cx</font>
<font color=#0000A0>push</font> <font color=#800000>dx</font>
<font color=#0000A0>push</font> <font color=#800000>bp</font>
<font color=#C0C0C0>; print </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 13h <font color=#C0C0C0>; function select </font>
<font color=#0000A0>mov</font> <font color=#800000>al</font>, 1 <font color=#C0C0C0>; update cursor </font>
<font color=#C0C0C0>;attribute </font>
<font color=#0000A0>mov</font> <font color=#800000>bl</font>, attrib
<font color=#0000A0>mov</font> <font color=#800000>bh</font>, 0 <font color=#C0C0C0>; page 0 </font>
<font color=#0000A0>int</font> 10h
<font color=#C0C0C0>; restore register </font>
<font color=#0000A0>pop</font> <font color=#800000>bp</font>
<font color=#0000A0>pop</font> <font color=#800000>dx</font>
<font color=#0000A0>pop</font> <font color=#800000>cx</font>
<font color=#0000A0>pop</font> <font color=#800000>bx</font>
<font color=#0000A0>pop</font> <font color=#800000>ax</font>
endm
<font color=#C0C0C0>; Macro : echo </font>
<font color=#C0C0C0>;------------------------ </font>
echo <font color=#00FF00>macro</font>
<font color=#C0C0C0>; store the value of ah </font>
<font color=#0000A0>mov</font> temp1, <font color=#800000>ah</font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 0eh <font color=#C0C0C0>; display char function </font>
<font color=#0000A0>int</font> 10h <font color=#C0C0C0>; display and progress cursor </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, temp1
endm
<font color=#C0C0C0>; Macro : scroll_down_line </font>
<font color=#C0C0C0>;----------------------------- </font>
scroll_down_line <font color=#00FF00>macro</font>
<font color=#0000A0>push</font> <font color=#800000>ax</font>
<font color=#0000A0>push</font> <font color=#800000>bx</font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 7 <font color=#C0C0C0>; scroll down </font>
<font color=#0000A0>mov</font> <font color=#800000>al</font> , 1 <font color=#C0C0C0>; one line </font>
<font color=#0000A0>mov</font> <font color=#800000>bh</font> , 0110b <font color=#C0C0C0>; cyan </font>
<font color=#0000A0>int</font> 10h
<font color=#0000A0>pop</font> <font color=#800000>bx</font>
<font color=#0000A0>pop</font> <font color=#800000>ax</font>
endm
<font color=#C0C0C0>;----------------------Code Section--------------------------------- </font>
<font color=#C0C0C0>;------------------------------------------------------------------- </font>
start:
<font color=#C0C0C0>; initialize ds and es with cs, and stack </font>
<font color=#0000A0>mov</font> <font color=#800000>ax</font>, 07c0h
<font color=#0000A0>mov</font> <font color=#800000>ss</font>, <font color=#800000>ax</font>
<font color=#0000A0>mov</font> <font color=#800000>sp</font>, 03feh
<font color=#0000A0>push</font> <font color=#800000>cs</font>
<font color=#0000A0>push</font> <font color=#800000>cs</font>
<font color=#0000A0>pop</font> <font color=#800000>ds</font>
<font color=#0000A0>pop</font> <font color=#800000>es</font>
<font color=#C0C0C0>;clear bx and dx register </font>
<font color=#0000A0>xor</font> <font color=#800000>bx</font>, <font color=#800000>bx</font>
<font color=#0000A0>xor</font> <font color=#800000>dx</font>, <font color=#800000>dx</font>
<font color=#C0C0C0>; set display mode </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 0h
<font color=#0000A0>mov</font> <font color=#800000>al</font>, 03h
<font color=#0000A0>int</font> 10h
<font color=#C0C0C0>;set blinking text-cursor </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 1h
<font color=#0000A0>mov</font> <font color=#800000>ch</font>, 7 <font color=#C0C0C0>; ending row </font>
<font color=#0000A0>mov</font> <font color=#800000>cl</font>, 6 <font color=#C0C0C0>; starting row </font>
<font color=#0000A0>int</font> 10h
<font color=#C0C0C0>;--------- print welcome --------- </font>
<font color=#0000A0>call</font> clear_window
<font color=#0000A0>mov</font> <font color=#800000>si</font>, <font color=#000064>offset</font> msg <font color=#C0C0C0>; si points to msg address </font>
<font color=#0000A0>mov</font> <font color=#800000>cx</font>, msg_end <font color=#0064C8>-</font> <font color=#000064>offset</font> msg <font color=#C0C0C0>; cx contain total chars in string </font>
move_cursor 0 , 0 <font color=#C0C0C0>; move at line 0 </font>
<font color=#0000A0>call</font> print_normal
move_cursor 0 , 1 <font color=#C0C0C0>; move at line 3 </font>
question:
<font color=#C0C0C0>;------------ prompt for option----------- </font>
<font color=#0000A0>mov</font> <font color=#800000>bp</font>, <font color=#000064>offset</font> prompt<font color=#C0C0C0>; </font>
<font color=#0000A0>mov</font> <font color=#800000>cx</font>, prompt_end <font color=#0064C8>-</font> <font color=#000064>offset</font> prompt <font color=#C0C0C0>; </font>
print_all
<font color=#C0C0C0>;---------- get the option selection -------- </font>
<font color=#0000A0>call</font> getchar <font color=#C0C0C0>; 'option' will contain the code </font>
<font color=#C0C0C0>; process selected option </font>
<font color=#0000A0>call</font> process_option
<font color=#C0C0C0>; move cursor to the next line </font>
<font color=#0000A0>inc</font> <font color=#800000>dh</font>
move_cursor <font color=#800000>dl</font>, <font color=#800000>dh</font>
<font color=#C0C0C0>; start again </font>
<font color=#0000A0>jmp</font> question
<font color=#C0C0C0>;------------- PROCEDURES ----------------- </font>
<font color=#C0C0C0>;------------------------------------------- </font>
<font color=#C0C0C0>; proc : getchar </font>
<font color=#C0C0C0>;--------------------------- </font>
getchar <font color=#00FF00>proc</font>
<font color=#0000A0>push</font> <font color=#800000>ax</font>
<font color=#C0C0C0>;get cursor position </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 3h
<font color=#0000A0>mov</font> <font color=#800000>bh</font>, 0
<font color=#0000A0>int</font> 10h
<font color=#C0C0C0>; go to next line </font>
<font color=#C0C0C0>; dh - row, dl-col </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 2h
<font color=#0000A0>mov</font> <font color=#800000>bh</font>, 0
<font color=#0000A0>inc</font> <font color=#800000>dh</font> <font color=#C0C0C0>; next line </font>
<font color=#0000A0>mov</font> <font color=#800000>dl</font>, 0 <font color=#C0C0C0>; go at left </font>
<font color=#0000A0>int</font> 10h
<font color=#C0C0C0>; get char </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 0h
<font color=#0000A0>int</font> 16h
<font color=#C0C0C0>;echo </font>
<font color=#0000A0>mov</font> option, <font color=#800000>al</font> <font color=#C0C0C0>; store in option </font>
<font color=#C0C0C0>; restore regs </font>
<font color=#0000A0>pop</font> <font color=#800000>ax</font>
<font color=#0000A0>ret</font>
endp
<font color=#C0C0C0>; Procedure : print_normal </font>
<font color=#C0C0C0>;----------------------------------------------------- </font>
print_normal <font color=#00FF00>proc</font>
<font color=#0000A0>push</font> <font color=#800000>ax</font> <font color=#C0C0C0>; save ax </font>
<font color=#0000A0>push</font> <font color=#800000>cx</font> <font color=#C0C0C0>; save cx </font>
<font color=#0000A0>push</font> <font color=#800000>si</font> <font color=#C0C0C0>; save si </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 0eh <font color=#C0C0C0>; teletype output select </font>
repeat:
<font color=#0000A0>mov</font> <font color=#800000>al</font>, <font color=#0064C8>[</font><font color=#800000>si</font><font color=#0064C8>]</font> <font color=#C0C0C0>; get the char </font>
<font color=#0000A0>int</font> 10h
<font color=#0000A0>inc</font> <font color=#800000>si</font> <font color=#C0C0C0>; increament si </font>
<font color=#0000A0>loop</font> repeat <font color=#C0C0C0>; repeat until all chars have printed </font>
<font color=#C0C0C0>; restore the registers </font>
<font color=#0000A0>pop</font> <font color=#800000>si</font>
<font color=#0000A0>pop</font> <font color=#800000>cx</font>
<font color=#0000A0>pop</font> <font color=#800000>ax</font>
<font color=#C0C0C0>; return </font>
<font color=#0000A0>ret</font>
endp <font color=#C0C0C0>; end process </font>
<font color=#C0C0C0>; Procedure : clear_window </font>
<font color=#C0C0C0>;----------------------------------------------------- </font>
clear_window <font color=#00FF00>proc</font>
<font color=#0000A0>push</font> <font color=#800000>ax</font>
<font color=#0000A0>push</font> <font color=#800000>cx</font>
<font color=#0000A0>push</font> <font color=#800000>dx</font>
<font color=#0000A0>push</font> <font color=#800000>bx</font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 07h <font color=#C0C0C0>; scroll up </font>
<font color=#0000A0>mov</font> <font color=#800000>al</font>, 0 <font color=#C0C0C0>; clear entire window </font>
<font color=#0000A0>mov</font> <font color=#800000>ch</font> , 0 <font color=#C0C0C0>; row </font>
<font color=#0000A0>mov</font> <font color=#800000>cl</font> , 0 <font color=#C0C0C0>; column </font>
<font color=#0000A0>mov</font> <font color=#800000>dh</font> , 24 <font color=#C0C0C0>; 25th row </font>
<font color=#0000A0>mov</font> <font color=#800000>dl</font> , 79 <font color=#C0C0C0>; 80th column </font>
<font color=#0000A0>mov</font> <font color=#800000>bh</font> , attrib <font color=#C0C0C0>; cyan background, bright white foreground </font>
<font color=#0000A0>int</font> 10h
<font color=#C0C0C0>; move cursor at top left </font>
move_cursor 0, 0
<font color=#0000A0>pop</font> <font color=#800000>bx</font>
<font color=#0000A0>pop</font> <font color=#800000>dx</font>
<font color=#0000A0>pop</font> <font color=#800000>cx</font>
<font color=#0000A0>pop</font> <font color=#800000>ax</font>
<font color=#0000A0>ret</font>
endp <font color=#C0C0C0>; end process </font>
<font color=#C0C0C0>; procedure : process_option </font>
<font color=#C0C0C0>;----------------------------- </font>
process_option <font color=#00FF00>proc</font>
<font color=#0000A0>push</font> <font color=#800000>ax</font>
<font color=#0000A0>push</font> <font color=#800000>cx</font>
<font color=#0000A0>push</font> <font color=#800000>si</font>
<font color=#0000A0>mov</font> <font color=#800000>al</font>, option
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'R'</font> <font color=#C0C0C0>; is it reverse string option </font>
<font color=#0000A0>JE</font> reverse <font color=#C0C0C0>; if yes, OK </font>
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'C'</font> <font color=#C0C0C0>; no?, is it colorize option </font>
<font color=#0000A0>JE</font> colorize <font color=#C0C0C0>; if yes, OK </font>
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'S'</font> <font color=#C0C0C0>; is it clear screen option </font>
<font color=#0000A0>JE</font> clearscr
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'E'</font> <font color=#C0C0C0>; is it Exit request? </font>
<font color=#0000A0>JE</font> exit <font color=#C0C0C0>; yes. OK </font>
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'A'</font> <font color=#C0C0C0>; change color attribute </font>
<font color=#0000A0>JE</font> change_attrib
<font color=#C0C0C0>; all options fails, so invalid option </font>
<font color=#C0C0C0>; print invalid message </font>
<font color=#0000A0>mov</font> <font color=#800000>bp</font>, <font color=#000064>offset</font> invalid_msg
<font color=#0000A0>mov</font> <font color=#800000>cx</font>, invalid_msg_end <font color=#0064C8>-</font> <font color=#000064>offset</font> invalid_msg
print_all
<font color=#0000A0>jmp</font> end_validate
<font color=#C0C0C0>; option is reverse string </font>
reverse:
<font color=#0000A0>call</font> print_reverse
<font color=#0000A0>jmp</font> end_validate
<font color=#C0C0C0>; option is colorized printing </font>
colorize:
<font color=#0000A0>call</font> colorized_print
<font color=#0000A0>jmp</font> end_validate
<font color=#C0C0C0>; option is change attribute of system </font>
change_attrib:
<font color=#0000A0>call</font> change_attribute
<font color=#0000A0>jmp</font> end_validate
<font color=#C0C0C0>; option is clear screen </font>
clearscr:
<font color=#0000A0>call</font> clear_window
<font color=#C0C0C0>; move cursor at top left </font>
<font color=#0000A0>mov</font> <font color=#800000>dl</font>, 0 <font color=#C0C0C0>; column 0 </font>
<font color=#0000A0>mov</font> <font color=#800000>dh</font>, 0 <font color=#C0C0C0>; row 0 </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 2 <font color=#C0C0C0>; function </font>
<font color=#0000A0>mov</font> <font color=#800000>bh</font>, 0 <font color=#C0C0C0>; page 0 </font>
<font color=#0000A0>int</font> 10h
<font color=#C0C0C0>; after clearing window print the welcome message </font>
<font color=#0000A0>mov</font> <font color=#800000>bp</font>, <font color=#000064>offset</font> msg <font color=#C0C0C0>; si points to msg address </font>
<font color=#0000A0>mov</font> <font color=#800000>cx</font>, msg_end <font color=#0064C8>-</font> <font color=#000064>offset</font> msg <font color=#C0C0C0>; cx contain total chars in string </font>
<font color=#0000A0>mov</font> <font color=#800000>al</font>,1
<font color=#0000A0>mov</font> <font color=#800000>bh</font>, 0
<font color=#0000A0>mov</font> <font color=#800000>bl</font>, attrib
<font color=#0000A0>mov</font> <font color=#800000>dl</font>, 0
<font color=#0000A0>mov</font> <font color=#800000>dh</font>, 0
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 13h
<font color=#0000A0>int</font> 10h
<font color=#0000A0>jmp</font> end_validate
<font color=#C0C0C0>; option is REBOOT </font>
exit:
<font color=#0000A0>mov</font> <font color=#800000>bp</font>, <font color=#000064>offset</font> reboot_msg
<font color=#0000A0>mov</font> <font color=#800000>cx</font>, reboot_msg_end <font color=#0064C8>-</font> <font color=#000064>offset</font> reboot_msg
print_all
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 0
<font color=#0000A0>int</font> 16h <font color=#C0C0C0>; wait for pressing key </font>
<font color=#0000A0>int</font> 19h <font color=#C0C0C0>; reboot </font>
<font color=#0000A0>jmp</font> end_validate
end_validate:
<font color=#0000A0>pop</font> <font color=#800000>cx</font>
<font color=#0000A0>pop</font> <font color=#800000>si</font>
<font color=#0000A0>pop</font> <font color=#800000>ax</font>
<font color=#0000A0>ret</font>
endp
<font color=#C0C0C0>; proc : print_reverse </font>
<font color=#C0C0C0>;----------------------------------- </font>
print_reverse <font color=#00FF00>proc</font>
<font color=#0000A0>push</font> <font color=#800000>ax</font>
<font color=#0000A0>push</font> <font color=#800000>bx</font>
<font color=#0000A0>push</font> <font color=#800000>bp</font>
<font color=#0000A0>push</font> <font color=#800000>cx</font>
<font color=#0000A0>mov</font> <font color=#800000>bp</font>, <font color=#000064>offset</font> pr_str
<font color=#0000A0>mov</font> <font color=#800000>cx</font>, pr_str_end <font color=#0064C8>-</font> <font color=#000064>offset</font> pr_str
print_all
<font color=#0000A0>mov</font> <font color=#800000>ah</font>,0
<font color=#C0C0C0>; set up counter </font>
<font color=#0000A0>xor</font> <font color=#800000>cx</font>,<font color=#800000>cx</font>
rev_get:
<font color=#0000A0>int</font> 16h <font color=#C0C0C0>; get char </font>
echo <font color=#C0C0C0>; echo the char </font>
<font color=#C0C0C0>; if enter, stop and get from stack </font>
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, 0dh
<font color=#0000A0>je</font> get_reverse
<font color=#C0C0C0>; otherwise store in stack </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 0
<font color=#0000A0>push</font> <font color=#800000>ax</font>
<font color=#0000A0>inc</font> <font color=#800000>cx</font> <font color=#C0C0C0>; increase counter </font>
<font color=#0000A0>jmp</font> rev_get
get_reverse:
<font color=#C0C0C0>; move ahead two line, for long string </font>
move_next_line
move_next_line
<font color=#C0C0C0>; display function </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 0eh
<font color=#C0C0C0>; page 0 </font>
<font color=#0000A0>mov</font> <font color=#800000>bh</font>, 0
<font color=#C0C0C0>; bl = foreground color </font>
<font color=#0000A0>mov</font> <font color=#800000>bl</font>, attrib
pop_r:
<font color=#C0C0C0>; pop and display </font>
<font color=#0000A0>pop</font> <font color=#800000>ax</font>
<font color=#C0C0C0>; display function </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 0eh
<font color=#C0C0C0>;mov al, byte ptr temp </font>
<font color=#0000A0>int</font> 10h
<font color=#0000A0>loop</font> pop_r <font color=#C0C0C0>; loop until cx 0 </font>
end_rev:
<font color=#0000A0>pop</font> <font color=#800000>cx</font>
<font color=#0000A0>pop</font> <font color=#800000>bp</font>
<font color=#0000A0>pop</font> <font color=#800000>bx</font>
<font color=#0000A0>pop</font> <font color=#800000>ax</font>
<font color=#0000A0>ret</font>
endp<font color=#C0C0C0>; </font>
<font color=#C0C0C0>; Proc : colorized_print </font>
<font color=#C0C0C0>;--------------------------------------------- </font>
colorized_print <font color=#00FF00>proc</font>
<font color=#0000A0>push</font> <font color=#800000>ax</font>
<font color=#0000A0>push</font> <font color=#800000>bx</font>
<font color=#0000A0>push</font> <font color=#800000>bp</font>
<font color=#0000A0>push</font> <font color=#800000>cx</font>
<font color=#C0C0C0>; prompt for string </font>
<font color=#0000A0>mov</font> <font color=#800000>bp</font>, <font color=#000064>offset</font> pr_str
<font color=#0000A0>mov</font> <font color=#800000>cx</font>, pr_str_end <font color=#0064C8>-</font> <font color=#000064>offset</font> pr_str
print_all
<font color=#C0C0C0>; read until 'Enter' </font>
<font color=#0000A0>xor</font> <font color=#800000>bx</font>,<font color=#800000>bx</font> <font color=#C0C0C0>; index </font>
rep_c:
<font color=#C0C0C0>; function select </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 0
<font color=#C0C0C0>; execute interrupt </font>
<font color=#0000A0>int</font> 16h
<font color=#C0C0C0>; echo </font>
echo
<font color=#C0C0C0>; compare, </font>
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, 0dh
<font color=#C0C0C0>;if 'Enter' end input </font>
<font color=#0000A0>je</font> print_color
<font color=#C0C0C0>; else, store the character </font>
<font color=#0000A0>mov</font> str<font color=#0064C8>[</font><font color=#800000>bx</font><font color=#0064C8>]</font>, <font color=#800000>al</font>
<font color=#C0C0C0>; increase counter </font>
<font color=#0000A0>inc</font> <font color=#800000>bx</font>
<font color=#C0C0C0>; read another </font>
<font color=#0000A0>jmp</font> rep_c
print_color:
<font color=#0000A0>mov</font> total_char, <font color=#800000>bl</font>
get_select:
<font color=#C0C0C0>; prompt for color sel </font>
<font color=#0000A0>lea</font> <font color=#800000>bp</font>, color_sel
<font color=#0000A0>mov</font> <font color=#800000>cx</font>, color_sel_end <font color=#0064C8>-</font> <font color=#000064>offset</font> color_sel
move_next_line <font color=#C0C0C0>; for long string </font>
print_all
<font color=#0000A0>call</font> getchar <font color=#C0C0C0>; get the option </font>
<font color=#0000A0>mov</font> <font color=#800000>al</font>, option <font color=#C0C0C0>; get option </font>
<font color=#C0C0C0>; compare and validate </font>
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'W'</font>
<font color=#0000A0>je</font> white_s
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'R'</font>
<font color=#0000A0>je</font> red_s
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'B'</font>
<font color=#0000A0>je</font> black_s
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'G'</font>
<font color=#0000A0>je</font> green_s
<font color=#C0C0C0>; else invalid selection </font>
<font color=#C0C0C0>;print warning and get selection again </font>
<font color=#C0C0C0>; invalid </font>
<font color=#0000A0>mov</font> <font color=#800000>bp</font>, <font color=#000064>offset</font> invalid_msg
<font color=#0000A0>mov</font> <font color=#800000>cx</font>, invalid_msg_end <font color=#0064C8>-</font> <font color=#000064>offset</font> invalid_msg
print_all
<font color=#0000A0>jmp</font> get_select
white_s:
<font color=#C0C0C0>; get current background </font>
<font color=#0000A0>mov</font> <font color=#800000>al</font>, 0
<font color=#0000A0>mov</font> <font color=#800000>al</font>, attrib <font color=#C0C0C0>; current profile </font>
<font color=#0000A0>and</font> <font color=#800000>al</font>, 0f0h <font color=#C0C0C0>; clear low nibble, font color </font>
<font color=#0000A0>or</font> <font color=#800000>al</font>, white <font color=#C0C0C0>; get user selected text color </font>
<font color=#0000A0>mov</font> user_attrib, <font color=#800000>al</font>
<font color=#0000A0>jmp</font> print
black_s:
<font color=#C0C0C0>; get current background </font>
<font color=#0000A0>mov</font> <font color=#800000>al</font>, 0
<font color=#0000A0>mov</font> <font color=#800000>al</font>, attrib <font color=#C0C0C0>; current profile </font>
<font color=#0000A0>and</font> <font color=#800000>al</font>, 0f0h <font color=#C0C0C0>; clear low nibble </font>
<font color=#0000A0>or</font> <font color=#800000>al</font>, black <font color=#C0C0C0>; get user selected text color </font>
<font color=#0000A0>mov</font> user_attrib, <font color=#800000>al</font>
<font color=#0000A0>jmp</font> print
green_s:
<font color=#C0C0C0>; get current background </font>
<font color=#0000A0>mov</font> <font color=#800000>al</font>, 0
<font color=#0000A0>mov</font> <font color=#800000>al</font>, attrib <font color=#C0C0C0>; current profile </font>
<font color=#0000A0>and</font> <font color=#800000>al</font>, 0f0h <font color=#C0C0C0>; clear low nibble </font>
<font color=#0000A0>or</font> <font color=#800000>al</font>, green <font color=#C0C0C0>; get user selected text color </font>
<font color=#0000A0>mov</font> user_attrib, <font color=#800000>al</font>
<font color=#0000A0>jmp</font> print
red_s:
<font color=#C0C0C0>; get current background </font>
<font color=#0000A0>mov</font> <font color=#800000>al</font>, 0
<font color=#0000A0>mov</font> <font color=#800000>al</font>, attrib <font color=#C0C0C0>; current profile </font>
<font color=#0000A0>and</font> <font color=#800000>al</font>, 0f0h <font color=#C0C0C0>; clear low nibble </font>
<font color=#0000A0>or</font> <font color=#800000>al</font>, red <font color=#C0C0C0>; get user selected text color </font>
<font color=#0000A0>mov</font> user_attrib, <font color=#800000>al</font>
<font color=#0000A0>jmp</font> print
print:
<font color=#0000A0>mov</font> <font color=#800000>al</font>,1
<font color=#C0C0C0>; page 0 </font>
<font color=#0000A0>mov</font> <font color=#800000>bh</font>, 0
<font color=#C0C0C0>; attribute </font>
<font color=#0000A0>mov</font> <font color=#800000>bl</font>, user_attrib
<font color=#C0C0C0>; total char </font>
<font color=#0000A0>xor</font> <font color=#800000>cx</font>,<font color=#800000>cx</font>
<font color=#0000A0>mov</font> <font color=#800000>cl</font>, total_char
<font color=#C0C0C0>; function select </font>
<font color=#0000A0>mov</font> <font color=#800000>ah</font>, 13h
<font color=#C0C0C0>; load bp with offset </font>
<font color=#0000A0>mov</font> <font color=#800000>bp</font> , <font color=#000064>offset</font> str
<font color=#C0C0C0>; execute </font>
<font color=#0000A0>int</font> 10h
end_print_c:
<font color=#0000A0>pop</font> <font color=#800000>cx</font>
<font color=#0000A0>pop</font> <font color=#800000>bp</font>
<font color=#0000A0>pop</font> <font color=#800000>bx</font>
<font color=#0000A0>pop</font> <font color=#800000>ax</font>
<font color=#0000A0>ret</font>
<font color=#C0C0C0>; varible for procedure </font>
user_attrib <font color=#000064>db</font> ?
total_char <font color=#000064>db</font> ?
endp
<font color=#C0C0C0>; Proc: change_attrib </font>
<font color=#C0C0C0>;------------------------------------------- </font>
change_attribute <font color=#00FF00>proc</font>
<font color=#0000A0>push</font> <font color=#800000>ax</font>
<font color=#0000A0>push</font> <font color=#800000>bp</font>
<font color=#0000A0>push</font> <font color=#800000>cx</font>
get_selection:
<font color=#C0C0C0>; prompt and get option </font>
<font color=#0000A0>mov</font> <font color=#800000>bp</font>, <font color=#000064>offset</font> profile_select
<font color=#0000A0>mov</font> <font color=#800000>cx</font>, profile_select_end <font color=#0064C8>-</font> <font color=#000064>offset</font> profile_select
print_all
<font color=#0000A0>call</font> getchar <font color=#C0C0C0>; selection is in option var </font>
<font color=#C0C0C0>; compare, validate and change </font>
<font color=#0000A0>mov</font> <font color=#800000>al</font>, option
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'1'</font>
<font color=#0000A0>je</font> black_W <font color=#C0C0C0>; black-W </font>
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'2'</font>
<font color=#0000A0>je</font> blue_Y <font color=#C0C0C0>; blue-Yellow </font>
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'3'</font> <font color=#C0C0C0>; lightgray_black </font>
<font color=#0000A0>je</font> gray_B
<font color=#0000A0>cmp</font> <font color=#800000>al</font>, <font color=#800080>'4'</font>
<font color=#0000A0>je</font> cyan_W <font color=#C0C0C0>; cyan-White </font>
<font color=#C0C0C0>; if invalid, display invalid msg </font>
<font color=#0000A0>mov</font> <font color=#800000>bp</font>, <font color=#000064>offset</font> invalid_msg
<font color=#0000A0>mov</font> <font color=#800000>cx</font>, invalid_msg_end <font color=#0064C8>-</font> <font color=#000064>offset</font> invalid_msg
print_all
move_next_line <font color=#C0C0C0>; move the cursor next line </font>
<font color=#C0C0C0>; get the input, again </font>
<font color=#0000A0>jmp</font> get_selection
<font color=#C0C0C0>; option valid, so process </font>
black_W:
<font color=#0000A0>mov</font> attrib, black_white
<font color=#0000A0>call</font> clear_window
<font color=#0000A0>jmp</font> end_change_attrib
blue_Y:
<font color=#0000A0>mov</font> attrib, blue_yellow
<font color=#0000A0>call</font> clear_window
<font color=#0000A0>jmp</font> end_change_attrib
cyan_W:
<font color=#0000A0>mov</font> attrib, default
<font color=#0000A0>call</font> clear_window
<font color=#0000A0>jmp</font> end_change_attrib
gray_B:
<font color=#0000A0>mov</font> attrib, gray_black
<font color=#0000A0>call</font> clear_window
<font color=#0000A0>jmp</font> end_change_attrib
end_change_attrib:
<font color=#C0C0C0>; processing complete, pop the registers </font>
<font color=#0000A0>pop</font> <font color=#800000>cx</font>
<font color=#0000A0>pop</font> <font color=#800000>bp</font>
<font color=#0000A0>pop</font> <font color=#800000>ax</font>
<font color=#0000A0>ret</font>
endp
<font color=#C0C0C0>; © Mohammad Anwar Shah </font>
</font></pre>
<center> <font color=#FFFFFF>;</font> <a href="http://www.emu8086.com" target="_blank"><font face=verdana size=1 color=#000000> - asm2html - </font></a> </center>
<!-- emu8086 version 4.07 -->
<!-- STOP AUTOMATIC ASM TO HTML EXPORT -->
<!-- *** -->
</body>
</html>