-
Notifications
You must be signed in to change notification settings - Fork 0
/
snake.asm
1591 lines (1437 loc) · 26.3 KB
/
snake.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
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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
org 100h
;////////////////////////////////////////////////////////////////////////////////////
;Subroutines THUS FAR Implemented inorder
; grow: >increase the size of snake by one char, takes no parameters,
; can be called N times to increase the size by N chars
; disp_snake:> displays snake
;
; disp_score:> displays score
;
; delay:> hmmm......delay I suppose...
; check_valid:> checks whether head is going to a valid place
; shift_body: > shifts the body along, used in conjunction with snake movement subroutines
; snake,up,down,left and right: >move the snake in implied direction
; Overlap: > a versatile subroutine,takes the overlapper, the thing being overlapped and
; the size of the overlapped objects as parameters, basically a linear search
; which returns a bool value
; can be used to check if the food to be placed is being overlapped by snake's body
; or an obstacle, if the snake's head is overlapping with its body
; or an obtacle, snake's head is overlapping food.....etc.
; play_sound:> takes two parameters from the stack and plays a sound on the speakers.
; the first one (bp+6) is the duration for beep
; the second one (bp+4) is the frequency of the beep
;kbisr: >overloads WASD keys to trigger movement flags, press Q to close program
;interface:> only contains a heart at the moment :)
;heart:> prints a heart, takes offset on the screen as parameter
;clrscr:> clears screen
;generatefood:> generates a random food position and stores the position in a global variable
;eating:> checks if the snake can eat the food and if it can, ingest the food and grow the snake
;scoreupdating:> if the snake has eaten the food, update the score
;////////////////////////////////////////////////////////////////////////////////////
;///////////////////////////////////////////////////////////////////////////////////
;SUGGESTED Subroutins
; Take_a_life:> a wrapper for Overlap and decrementing lives variable
;Gen_StageN:> will generate a stage with obstacles, Gen_Stage1 can simply be a box....
;Timer(A TSR)
; Speed:> next gen of Delay, optimizes the speed along columns and rows, create a Speed global variable
;Increase_Speed:> change the Speed variable to increase the speed and runs every 5 seconds (hooked with timer maybe)
;TO BE CONTINUED.............
;/////////////////////////////////////////////////////////////////////////////////
jmp start
oldisr: dd 0
nos:db 3;no. of stages
;////////FLAGS////////////////
close: db 0
left: db 0
right: db 0
up: db 0
down: db 0
foodplaced: db 0
validfood: db 1
;//////SNAKE-PARAMETERS/////////////////////
reincarnation:dw 1672,1674,1676,1678,1680,1682,1684,1686,1688,1690,1692,1694,1696,1698,1700,1702,1704,1706,1708,1710,0xffff; these will be the values of di-offset
snake: dw 1672,1674,1676,1678,1680,1682,1684,1686,1688,1690,1692,1694,1696,1698,1700,1702,1704,1706,1708,1710,0xffff; these will be the values of di-offset
extension:times 228 dw 0
sizeS: dw 20
lives: db 3
Score: dw 0
SpeedConstant: dw 4096
SpeedFlag: db 1
SpeedNum:dw 60
;//////POISON-PARAMETER/////////////////////
poisonpos: dw 0
poisonitem: dw 0x1632 ;cursed remains of old snakes, black magic
poisonplaced: db 0
;//////FOOD-PARAMETERS//////////////////////
foodpos: dw 0
fooditem: dw 0x1625 ;%
fooditem2: dw 0x2340;@
fooditem3: dw 0x3426;&
fooditem4: dw 0x467E ;~
currentfood: dw 0x1625
cycle: dw 0
req: dw 25
;//////AUDIO-PARAMETERS//////////////////////
eatS: dw 4560
deathS: dw 9121
initializationS: dw 1917
initializationT: dw 65000
normalT: dw 1500
; G D G A A# F6 F5 A A# G6 D F A A# C6 F A A#
notes: dw 3043,4063,3043,2711,2559,1715,3416,2711,2559,1521,4063,3416,2711,2559,2280,3416,2711,2559
note_off: dw 0
;////////////INTERFACE-COMPONENTS//////////////////////////
heartS: dw 0x0720,0x0720,0x1720,0x1720,0x0720,0x0720,0x1720,0x1720,0x0720
dw 0x0720,0x1720,0x1720,0x1720,0x1720,0x1720,0x1720,0x1720,0x1720
dw 0x0720,0x0720,0x1720,0x1720,0x1720,0x1720,0x1720,0x1720,0x0720
dw 0x0720,0x0720,0x0720,0x0720,0x1720,0x1720,0x0720,0x0720,0x0720
win: dw 'YOU WIN'
lose: dw 'YOU LOSE'
Lives: dw 'Lives Remaining'
Scoredisp: dw 'Score'
time: dw 'Time: : '
oldtime: dd 0
tickcount: dw 0
sec: dw 0
min: dw 0
bkcol: dw 0x002f;0=blk,1=blu,2=gr,3=tr,4=rd,5=pp,6=or,7=wt
obscol: dw 0x2223
sbod: dw 0x7323
head: dw 0x1032
;///////////SNAKE'S BODY RELATED SUBROUTINES//////////////////////////////////
;//////////////////GROW///////////////
grow:
push ax
push bx
mov bx,[sizeS]
shl bx,1
sub bx,2
mov ax,[snake+bx]
add bx,2
mov [snake+bx],ax
add bx,2
mov ax,0xffff
mov [snake+bx],ax
mov ax,1
add [sizeS],ax
pop bx
pop ax
ret
;//////////////////// POISON-E///////////////
poison_E:
push ax
push di
push bx
push 0xb800
pop es
cmp word [sizeS],0
jb kill
mov di,[sizeS]
sub di,5
mov [sizeS],di
shl di,1
mov word [snake+di],0xffff
mov ax,[bkcol]
mov bx,[di]
mov [es:bx],ax
add di, 2
add di,snake
erase:cmp word [di],0xFFFF
je endpe
mov ax,[bkcol]
mov bx,[di]
mov [es:bx],ax
add di,2
jmp erase
kill:
dec byte [lives]
endpe:
mov [es:bx],ax
pop bx
pop di
pop ax
ret
;//////////////////DISP_SNAKE///////////////
disp_snake:
push ax
push di
push bx
mov ax,0xb800
mov es,ax
mov ax,[head];head
mov di,[snake]
mov bx,2
mov [es:di],ax
mov ax,[sbod];body
loop1:
mov di,[snake+bx]
cmp di,0xffff
je out1
add bx,2
mov [es:di],ax
jmp loop1
out1:
sub bx,2
mov di,[snake+bx]
mov bx,di;CHANGED THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
cmp word [currentfood],bx
je dontplace
mov bx,[bkcol]
mov word [es:di],bx
dontplace:
pop bx
pop di
pop ax
ret
;//////////delay///////////////
;////////////SPEED//////////////////
delayL:
push ax
push bx
push dx
push cx
cmp word [SpeedConstant],0
je nes
call incrementspeedL
nes:
mov dx,[cs:SpeedConstant]
kl:
mov cx, 0xFF
loopdelay:
dec cx
jnz loopdelay
dec dx
cmp dx, 0
jg kl
pop cx
pop dx
pop bx
pop ax
ret
incrementspeedL:
push dx
push ax
mov ax, [cs:sec]
mov dl,20
div dl
cmp ah,0
jne setagain
cmp byte [cs:SpeedFlag],1
je incrementspeedpops
shr word [cs:SpeedConstant],1
or byte [cs:SpeedFlag],1
jmp incrementspeedpops
setagain:
and byte [cs:SpeedFlag],0
incrementspeedpops:
pop ax
pop dx
ret
;/////////////////////////////////////////////////////////
delay:
push ax
push bx
push dx
push cx
cmp word [SpeedNum],0
je nes2
call incrementspeed
nes2:
mov dx,[cs:SpeedNum]
kl2:
mov cx, 0xfff
loopdelay2:
dec cx
jnz loopdelay2
dec dx
cmp dx, 0
jg kl2
pop cx
pop dx
pop bx
pop ax
ret
incrementspeed:
push dx
push ax
mov ax, [cs:sec]
mov dl,20
div dl
cmp ah,0
jne setagain1
cmp byte [cs:SpeedFlag],1
je incrementspeedpops1
sub word [cs:SpeedNum],4
or byte [cs:SpeedFlag],1
jmp incrementspeedpops1
setagain1:
and byte [cs:SpeedFlag],0
incrementspeedpops1:
pop ax
pop dx
ret
;////////////////CHECK_VALID////////////////
check_valid:
push bp
mov bp,sp
push di
mov di,[bp+4]
mov ax,[es:di]
cmp byte al,0x23
jne validspace
mov ax,0
jmp endc
validspace:
mov ax,1
endc:
pop di
pop bp
ret 2
;//////////////////SHIFT_BODY///////////////
shift_body:
mov di,[snake+bx]
cmp di,0xffff
je exitu
mov [snake+bx],si
add bx,2
mov si,[snake+bx]
cmp si,0xffff
je exitu
mov [snake+bx],di
add bx,2
jmp shift_body
exitu:
ret
;//////////////////SNAKEUP///////////////
snakeup:
push ax
push di
push bx
mov bx,[snake] ; moving the head
mov di,160
cmp bx,960
jnb nowrapu
add bx,3200
nowrapu:
sub bx,di
push bx
call check_valid
cmp ax,0
je dead1
mov si,[snake]
mov [snake],bx
mov bx,2
call shift_body
jmp endu
dead1:
call body_collision
endu:
pop bx
pop di
pop ax
ret
;//////////////////SNAKEDOWN///////////////
snakedown:
push ax
push di
push bx
mov bx,[snake] ; moving the head
mov di,160
cmp bx,3840
jb nowrapd
sub bx,3200
nowrapd:
add bx,di
push bx
call check_valid
cmp ax,0
je dead2
mov si,[snake]
mov [snake],bx
mov bx,2
call shift_body
jmp endd
dead2:
call body_collision
endd:
pop bx
pop di
pop ax
ret
;//////////////////SNAKELEFT///////////////
snakeleft:
push di
push bx
push ax
push dx
mov bx,[snake] ; moving the head
mov di,2
mov ax,bx
xor dx,dx
mov cx,160
div cx
cmp dx,0
jne nowrapl
add bx,160
nowrapl:
sub bx,di
push bx
call check_valid
cmp ax,0
je dead3
mov si,[snake]
mov [snake],bx
mov bx,2
call shift_body
jmp endl
dead3:
call body_collision
endl:
pop dx
pop ax
pop bx
pop di
ret
;//////////////////SNAKERIGHT///////////////
snakeright:
push di
push bx
push ax
push dx
mov bx,[snake] ; moving the head
mov di,2
mov ax,bx
xor dx,dx
add ax,2
mov cx,160
div cx
cmp dx,0
jne nowrapr
sub bx,160
nowrapr:
add bx,di
push bx
call check_valid
cmp ax,0
je dead4
mov si,[snake]
mov [snake],bx
mov bx,2
call shift_body
jmp endr
dead4:
call body_collision
endr:
pop dx
pop ax
pop bx
pop di
ret
;///////////////////BODY_COLLISION ///////////////////
del:
push cx
mov cx,0xf000
a:
sub cx,1
jnz a
pop cx
ret
body_collision:
push cx
push si
push di
push ax
push bx
push dx
mov bx,snake
mov cx,[sizeS]
mov ax,[bkcol]
loopi:
mov di,[bx]
mov [es:di],ax
add bx,2
call del
loop loopi
mov cx,21
push cs
pop es
mov si,reincarnation
mov di,snake
rep movsw
mov cx,20
mov [sizeS],cx
push word 0xb800
pop es
and byte [up],0
and byte [down],0
and byte [right],0
and byte [left],0
push word [initializationT]
push word [deathS]
call play_sound
call disp_snake
mov ax,1
sub [lives],al
call disp_life
its_fine:
pop dx
pop bx
pop ax
pop di
pop si
pop cx
ret
;/////////////////////OVERLAP///////////////////
;overlap:
; push bp
; mov bp,sp
; push cx
; push bx
; mov cx,[bp+4];size of the array
; mov bx,[bp+6];array
; mov ax,[bp+8];key
; loops:
; cmp ax,[bx]
; je exits
; add bx,2
; loop loops
; jmp nf
; exits:
; mov ax,1
; jmp endo
; nf:
; mov ax,0
; endo:
; pop bx
; pop cx
; pop bp
; ret 6
;///////////////ISRs and TSRs//////////////////////////
;//////////////////KBISR///////////////
kbisr:
push ax
push es
mov ax, 0xb800
mov es, ax
in al, 0x60
mov ah,1
cmp [right],ah
je cmpright
cmp al, 30
jne cmpright
mov al,1
mov byte [left],al
mov al,0
mov byte[right],al
mov byte[up],al
mov byte[down],al
jmp nomatch
cmpright:
cmp [left],ah
je cmpup
cmp al, 32
jne cmpup
mov al,1
mov byte [right],al
mov al,0
mov byte[left],al
mov byte[up],al
mov byte[down],al
jmp nomatch
cmpup:
cmp [down],ah
je cmpdown
cmp al, 17
jne cmpdown
mov al,1
mov byte [up],al
mov al,0
mov byte[right],al
mov byte[left],al
mov byte[down],al
jmp nomatch
cmpdown:
cmp [up],ah
je terminate
cmp al, 31
jne terminate
mov al,1
mov byte [down],al
mov al,0
mov byte[right],al
mov byte[up],al
mov byte[left],al
jmp nomatch
terminate:
cmp al, 16
jne nomatch
or byte [close],1
;call poison_E
nomatch: mov al, 0x20
out 0x20, al ; send EOI to PIC
pop es
pop ax
iret
;/////////////////AUDIO-IMPLEMENTATIONS/////////////////////
play_sound:
push bp
mov bp, sp
push ax
push bx
push cx
mov al, 182
out 43h, al
mov ax, [bp+4] ;move the passed frequency
out 42h, al
mov al, ah
out 42h, al
in al, 61h
or al, 00000011b
out 61h, al
mov bx, 25
;pause1:
; mov cx, [bp+6]
;pause2:
; dec cx
; jne pause2
; dec bx
;jne pause1
;in al, 61h
;and al, 11111100b
;out 61h, al
pop cx
pop bx
pop ax
pop bp
ret 4
;//////////////////GRAPHICAL-IMPLEMENTATIONS/////////////////////
;///////////////////GEN-STAGE-1//////////////////////////////////////
gen_s1:
push ax
mov word [bkcol], 0x772f;0=blk,1=blu,2=gr,3=tr,4=rd,5=pp,6=or,7=wt
mov word [obscol], 0x2223
mov word [sbod], 0x5223
mov word [head], 0x1032
call clrscr
push word [obscol]
push word 800
push word 79
push word 20
call rectangle
mov ax,[bkcol]
or ah,0x0f
or byte [currentfood+1],0xf0
and [currentfood+1],ah
or byte [fooditem+1],0xf0
and [fooditem+1],ah
or byte [fooditem2+1],0xf0
and [fooditem2+1],ah
or byte [fooditem3+1],0xf0
and [fooditem3+1],ah
or byte [fooditem4+1],0xf0
and [fooditem4+1],ah
pop ax
ret
;///////////////////LINE/////////////////////////////////////////
line:
push bp
mov bp,sp
push ax
push cx
push di
mov di,[bp+8];ini
mov cx,[bp+6];fin
mov ax,[bp+10];col
loopll:
mov [es:di],ax
add di,[bp+4]
cmp di,cx
jne loopll
pop di
pop cx
pop ax
pop bp
ret 8
;///////////////////GEN-STAGE-2//////////////////////////////////////
gen_s2:
push ax
mov word [bkcol], 0x222f;0=blk,1=blu,2=gr,3=tr,4=rd,5=pp,6=or,7=wt
mov word [obscol], 0x7723
mov word [sbod], 0x5223
mov word [head], 0x1032
call clrscr
push word [obscol]
push word 800
push word 79
push word 20
call rectangle
mov ax,[bkcol]
or ah,0x0f
or byte [currentfood+1],0xf0
and [currentfood+1],ah
or byte [fooditem+1],0xf0
and [fooditem+1],ah
or byte [fooditem2+1],0xf0
and [fooditem2+1],ah
or byte [fooditem3+1],0xf0
and [fooditem3+1],ah
or byte [fooditem4+1],0xf0
and [fooditem4+1],ah
push word [obscol]
push word 1440
push word 1560
push word 2
call line
push word [bkcol]
push word 3840
push word 3900
push word 2
call line
push word [bkcol]
push word 840
push word 870
push word 2
call line
push word [bkcol]
push word 1600
push word 160*18
push word 160
call line
push word [bkcol]
push word 1758
push word 160*19-2
push word 160
call line
push word [obscol]
push word 920
push word 3960
push word 160
call line
pop ax
ret
;//////////////////INTERFACE///////////////
interface:
push cx
push di
mov di,640
push word 0xb800
pop es
push ax
mov ax,0x3420
mov cx,80
rep stosw
call disp_life
call disp_score
call timee
pop ax
pop di
pop cx
ret
;////////////////DISP_SCORE//////////////
printsc:
push bp
mov bp, sp
push es
push ax
push bx
push cx
push dx
push di
mov ax, 0xb800
mov es, ax
mov ax, [bp+4]
mov bx, 10
mov cx, 0
nextdigit:
xor dx, dx
div bx
add dl, 0x30
push dx
inc cx
cmp ax, 0
jnz nextdigit
xor di, di
mov di, [bp + 6]
nextpos:
pop dx
mov dh, 0x07
mov word [es:di], dx
add di, 2
loop nextpos
pop di
pop dx
pop cx
pop bx
pop ax
pop es
pop bp
ret 4
disp_score:
push si
push cx
push di
push ax
mov di, 280
mov si, Scoredisp
mov cx, 5
scloop:
mov ax, [si]
mov ah, 0x07
stosw
add si, 1
loop scloop
add di, 2
push di
mov ax, [Score]
push ax
call printsc
pop ax
pop di
pop cx
pop si
ret
;////////////////DISP_WIN///////////////
disp_win:
push ax
push bx
push cx
push bp
mov ah, 0x13 ; service 13 - print string
mov al, 1 ; subservice 01 – update cursor
mov bh, 0 ; output on page 0
mov bl, 7 ; normal attrib
mov dx, 0x0103 ; row 10 column 3
mov cx, 7 ; length of string
push cs
pop es ; segment of string
mov bp, win ; offset of string
int 0x10 ; call BIOS video service
pop bp
pop cx
pop bx
pop ax
ret
;////////////////DISP_LOSE/////////////
disp_lose:
push ax
push bx
push cx
push bp
mov ah, 0x13 ; service 13 - print string
mov al, 1 ; subservice 01 – update cursor
mov bh, 0 ; output on page 0
mov bl, 6 ; normal attrib
mov dx, 0x0103 ; row 10 column 3
mov cx, 8 ; length of string
push cs
pop es ; segment of string
mov bp, lose ; offset of string
int 0x10 ; call BIOS video service
pop bp
pop cx
pop bx
pop ax
ret
;/////////////////TIMEE/////////////////
timee:
push ax
push bx
push cx
push bp
mov ah, 0x13 ; service 13 - print string
mov al, 0 ; subservice 01 – update cursor
mov bh, 0 ; output on page 0
mov bl, 7 ; normal attrib
mov dx, 0x003F ; row 10 column 3
mov cx, 8 ; length of string
push cs
pop es ; segment of string
mov bp, time ; offset of string
int 0x10 ; call BIOS video service
pop bp
pop cx
pop bx
pop ax
ret
;////////////////DISP_LIFE//////////////
disp_life:
push si
push cx
push di
mov di,440
mov si,Lives
mov cx,15
loopl:
mov ax,[si]
mov ah,0x07
stosw
add si,1
loop loopl
mov cx,[lives]
add cx,0x30
mov ch,0x07
add di,2
mov [es:di],cx
pop di
pop cx
pop si
ret
;////////////RECTANGLE////////////////
rectangle:
push bp
mov bp,sp
push ax
push di
push si
push cx
push dx
mov dx,[bp+10]
mov ax,0xb800
mov es,ax
shl word [bp+6],1
mov ax,[bp+4]
sub ax,1
mov [bp+4],ax
mov di,[bp+8]
mov ax,[bp+8]
mov cx,[bp+6]
add [bp+6],ax
loopre:
mov word [es:di],dx
add di,2