forked from Samiha-Sadek/Microprocessor-Simulation-Game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoOpS.inc
More file actions
1222 lines (825 loc) · 37.6 KB
/
TwoOpS.inc
File metadata and controls
1222 lines (825 loc) · 37.6 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
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
.286
TwoOpS MACRO command, operand1, operand2, valid2Chk
pusha
pushf
mov DI, offset command ; The variable containing the command
; fy 7alet el no operands, h-skip el kalam dh kolo, w nroo7 lel execution of command
; skipping the command part
; skipping some spaces
SkipSpaceOP2: ; Skips spaces before the command
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipLettersOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
; and reached the beginning of the command
inc DI
jmp SkipSpaceOP2 ; in case it didn't jump to SkipLetters, then it's a space, skip it
SkipLettersOP2: ; skips the command itself
; Code will reach this part when DI points to the start of the command
; We should skip all chars till we reach a space
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jz SkipSpace2OP2S ; jumps if it has a space
; if it has a space, then we have skipped all letters,
; and reached the beginning of the operands
inc DI
jmp SkipLettersOP2 ; in case it didn't jump to SkipSpace2, then it's a letter, skip it
SkipSpace2OP2S: ; Skips spaces after the command, and before the operand
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipIncOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
; and reached the beginning of the command
; pushf ; 3lshan a7tafez bl value of zero flag abl el inc DI
inc DI
; popf ; 3lshan arg3o tany
jmp SkipSpace2OP2S ; if it's a space, skip it
SkipIncOP2:
; Having reached this part, DI now points at the beginning of the first operand
; In case of commands having 2 operands:
; ADD - ADC- SUB - SBB - MOV - XOR - AND - OR ; dol lyhom nafs el sheroot (fl valid operands y3ny)
; SHR - SHL - ROR ; dol lyhom nafs el sheroot (fl valid operands y3ny)
TwoOperandsSecondTypeOP2: ; handles operands of SHR - SHL - ROR
; ST y3ny Second Type
mov bl, 65 ; ASCII of 'A'
cmp bl,[DI]
jnz skipJump26STOP2
jmp XorHorLSTOP2 ; 1st operand is AX or AH or AL
skipJump26STOP2:
mov bl, 66 ; ASCII of 'B'
cmp bl,[DI]
jnz skipJump27STOP2
jmp XorHorL2STOP2 ; 1st operand is BX or BH or BL or BP
skipJump27STOP2:
mov bl, 67 ; ASCII of 'C'
cmp bl,[DI]
jnz skipJump28STOP2
jmp XorHorLSTOP2 ; 1st operand is CX or CH or CL
skipJump28STOP2:
mov bl, 68 ; ASCII of 'D'
cmp bl,[DI]
jnz skipJump29STOP2
jmp XorHorL3STOP2 ; 1st operand is DX or DH or DL or DI
skipJump29STOP2:
; lw 3ada mn kol dh, yb2a msh byebda2 b A,B,C,D
mov bl, 83 ; ASCII of 'S'
cmp bl,[DI]
jnz skipJump30STOP2
jmp SIorSPSTOP2 ; 1st operand is SI or SP
skipJump30STOP2:
mov bl, 91 ; ASCII of '['
cmp bl,[DI]
jnz skipJump31STOP2
jmp SquareBracketSTOP2 ; 1st operand is [SP],[SI],[DI],[BP]
skipJump31STOP2:
; lw wsl l7d hena, yb2a msh byebda2 b A,B,C,D,S,[
; yb2a invalid
jmp InvalidOPOP2
XorHorLSTOP2: ; first letter is A,C
inc DI ; DI dlw2ty btshawer 3la X, H, L
mov bl, 88 ; ASCII of 'X'
cmp bl,[DI]
jnz skipJump44STOP2
jmp ValidateSecondOP2 ; 1st op is AX or CX (16 bits)
skipJump44STOP2:
mov bl, 72 ; ASCII of 'H'
cmp bl,[DI]
jnz skipJump44ST1OP2
jmp ValidateSecondOP2 ; 1st op is AH or CH (8 bits)
skipJump44ST1OP2:
mov bl, 76 ; ASCII of 'L'
cmp bl,[DI]
jnz skipJump44ST2OP2
jmp ValidateSecondOP2 ; 1st op is AL or CL (8 bits)
skipJump44ST2OP2:
; lw wesel hena, yb2a bada2 b A aw C, bs msh AL,AH,AX,Cl,Ch,CX
; yb2a invalid
jmp InvalidOPOP2
XorHorL2STOP2:
inc DI ; DI dlw2ty btshawer 3la X, H, L, P
mov bl, 88 ; ASCII of 'X'
cmp bl,[DI]
jnz skipJump45STOP2
jmp ValidateSecondOP2 ; 1st op is BX (16 bits)
skipJump45STOP2:
mov bl, 72 ; ASCII of 'H'
cmp bl,[DI]
jnz skipJump44ST3OP2
jmp ValidateSecondOP2 ; 1st op is BH (8 bits)
skipJump44ST3OP2:
mov bl, 76 ; ASCII of 'L'
cmp bl,[DI]
jnz skipJump54STOP2
jmp ValidateSecondOP2 ; 1st op is BL (8 bits)
skipJump54STOP2:
mov bl, 80 ; ASCII of 'P'
cmp bl,[DI]
jnz skipJump46STOP2
jmp ValidateSecondOP2 ; 1st op is BP (16 bits)
skipJump46STOP2:
; lw wesel hena, yb2a bada2 b B, bs msh BL,BH,BX,BP
; yb2a invalid
jmp InvalidOPOP2
XorHorL3STOP2:
inc DI ; DI dlw2ty btshawer 3la X, H, L, I
mov bl, 88 ; ASCII of 'X'
cmp bl,[DI]
jnz skipJump47STOP2
jmp ValidateSecondOP2 ; 1st op is DX (16 bits)
skipJump47STOP2:
mov bl, 72 ; ASCII of 'H'
cmp bl,[DI]
jnz skipJump53STOP2
jmp ValidateSecondOP2 ; 1st op is DH (8 bits)
skipJump53STOP2:
mov bl, 76 ; ASCII of 'L'
cmp bl,[DI]
jnz skipJump52STOP2
jmp ValidateSecondOP2 ; 1st op is DL (8 bits)
skipJump52STOP2:
mov bl, 73 ; ASCII of 'I'
cmp bl,[DI]
jnz skipJump48STOP2
jmp ValidateSecondOP2 ; 1st op is DI (16 bits)
skipJump48STOP2:
; lw wesel hena, yb2a bada2 b D, bs msh DL,DH,DX,DI
; yb2a invalid
jmp InvalidOPOP2
SIorSPSTOP2:
inc DI ; DI dlw2ty btshawer 3la I, P
mov bl, 73 ; ASCII of 'I'
cmp bl,[DI]
jnz skipJump49STOP2
jmp ValidateSecondOP2 ; 1st op is SI (16 bits)
skipJump49STOP2:
mov bl, 80 ; ASCII of 'P'
cmp bl,[DI]
jnz skipJump50STOP2
jmp ValidateSecondOP2 ; 1st op is SP (16 bits)
skipJump50STOP2:
; lw wesel hena, yb2a bada2 b S, bs msh SI,SP
; yb2a invalid
jmp InvalidOPOP2
SquareBracketSTOP2:
inc DI ; DI dlw2ty btshawer 3la SI,DI,SP,BP, aw shwyt spaces, aw memory
SkipSpace3STOP2: ; Skips spaces after the [, and before the letter
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipInc6STOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
inc DI
jmp SkipSpace3STOP2 ; if it's a space, skip it
SkipInc6STOP2:
; DI dlw2ty btshawer 3la SI,DI,SP,BP, aw memory 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
mov bl, 83 ; ASCII of 'S'
cmp bl,[DI]
jz SIorSP2STOP2 ; 1st operand is [SI] or [SP]
mov bl, 66 ; ASCII of 'B'
cmp bl,[DI]
jz bracketBPSTOP2 ; 1st operand is [BP] or [B]
mov bl, 68 ; ASCII of 'D'
cmp bl,[DI]
jnz skipJump2STOP2
jmp bracketDISTOP2 ; 1st operand is [DI] or [D]
skipJump2STOP2:
mov bl, 48 ; ASCII of '0'
cmp bl,[DI]
jnz skipJump3STOP2
jmp checkbracketmemorySTOP2 ; 1st operand is [0]
skipJump3STOP2:
mov bl, 49 ; ASCII of '1'
cmp bl,[DI]
jnz skipJump4STOP2
jmp checkbracketmemorySTOP2 ; 1st operand is [1]
skipJump4STOP2:
mov bl, 50 ; ASCII of '2'
cmp bl,[DI]
jnz skipJump5STOP2
jmp checkbracketmemorySTOP2 ; 1st operand is [2]
skipJump5STOP2:
mov bl, 51 ; ASCII of '3'
cmp bl,[DI]
jnz skipJump6STOP2
jmp checkbracketmemorySTOP2 ; 1st operand is [3]
skipJump6STOP2:
mov bl, 52 ; ASCII of '4'
cmp bl,[DI]
jnz skipJump51STOP2
jmp checkbracketmemorySTOP2 ; 1st operand is [4]
skipJump51STOP2:
mov bl, 53 ; ASCII of '5'
cmp bl,[DI]
jz checkbracketmemorySTOP2 ; 1st operand is [5]
mov bl, 54 ; ASCII of '6'
cmp bl,[DI]
jz checkbracketmemorySTOP2 ; 1st operand is [6]
mov bl, 55 ; ASCII of '7'
cmp bl,[DI]
jz checkbracketmemorySTOP2 ; 1st operand is [7]
mov bl, 56 ; ASCII of '8'
cmp bl,[DI]
jz checkbracketmemorySTOP2 ; 1st operand is [8]
mov bl, 57 ; ASCII of '9'
cmp bl,[DI]
jz checkbracketmemorySTOP2 ; 1st operand is [9]
mov bl, 65 ; ASCII of 'A'
cmp bl,[DI]
jz checkbracketmemorySTOP2 ; 1st operand is [A]
mov bl, 67 ; ASCII of 'C'
cmp bl,[DI]
jz checkbracketmemorySTOP2 ; 1st operand is [C]
mov bl, 69 ; ASCII of 'E'
cmp bl,[DI]
jz checkbracketmemorySTOP2 ; 1st operand is [E]
mov bl, 70 ; ASCII of 'F'
cmp bl,[DI]
jz checkbracketmemorySTOP2 ; 1st operand is [F]
; lw 3ada mn dol, yb2a invalid
jmp InvalidOPOP2
SIorSP2STOP2:
inc DI ; DI dlw2ty btshawer 3la I, P
mov bl, 73 ; ASCII of 'I'
cmp bl,[DI]
jz checkbracketSTOP2 ; 1st op is [SI]
mov bl, 80 ; ASCII of 'P'
cmp bl,[DI]
jz checkbracketSTOP2 ; 1st op is [SP]
; lw msh I aw P, yb2a invalid
jmp InvalidOPOP2
bracketBPSTOP2:
inc DI ; DI dlw2ty btshawer 3la P, aw hya 5lst 5las
mov bl, 80 ; ASCII of 'P'
cmp bl,[DI]
jz checkbracketSTOP2 ; 1st op is [BP]
; lw msh BP, yb2a invalid, aw [B] lel memory
; lw hya [B] lel memory, yb2a el mfrood dlw2ty yb2a bracket, aw shwyt spaces
; h-check lw fy spaces, a3mlohom skip, b3dein el mfrood ala2y bracket, lw la yb2a invalid
SkipSpace5STOP2: ; Skips spaces before the ]
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipInc7STOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
inc DI
jmp SkipSpace5STOP2 ; if it's a space, skip it
SkipInc7STOP2:
; kda el DI btshawer 3la ] aw invalid
mov bl, 93 ; ASCII of ']'
cmp bl,[DI]
; modtar a3ml el jump bl shakl el mo3aq dh
; 3lshan myenfa3sh a3ml jz far ValidOp16
jnz skipJumpSTOP2 ; lw closed bracket, hy-jump lel invalid
jmp ValidateSecondOP2 ; 1st op is [B]
skipJumpSTOP2:
; lw wesel le hena, yb2a msh closed bracket, yb2a invalid
jmp InvalidOPOP2
bracketDISTOP2:
inc DI ; DI dlw2ty btshawer 3la I, aw hya 5lst 5las
mov bl, 73 ; ASCII of 'I'
cmp bl,[DI]
jz checkbracketSTOP2 ; 1st op is [DI]
; lw msh DI, yb2a invalid, aw [D] lel memory
; lw hya [D] lel memory, yb2a el mfrood dlw2ty yb2a bracket, aw shwyt spaces
; h-check lw fy spaces, a3mlohom skip, b3dein el mfrood ala2y bracket, lw la yb2a invalid
SkipSpace6STOP2: ; Skips spaces before the ]
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipInc8STOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
inc DI
jmp SkipSpace6STOP2 ; if it's a space, skip it
SkipInc8STOP2:
; kda el DI btshawer 3la ] aw invalid
mov bl, 93 ; ASCII of ']'
cmp bl,[DI]
; modtar a3ml el jump bl shakl el mo3aq dh
; 3lshan myenfa3sh a3ml jz far ValidOp16
jnz skipJump7STOP2 ; lw closed bracket, hy-jump lel invalid
jmp ValidateSecondOP2 ; 1st op is [D]
skipJump7STOP2:
; lw wesel le hena, yb2a msh closed bracket, yb2a invalid
jmp InvalidOPOP2
checkbracketmemorySTOP2:
inc DI ; DI dlw2ty btshawer 3la ] aw shwyt spaces
SkipSpace7STOP2: ; Skips spaces after the letter, and before the ]
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipInc9STOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
inc DI
jmp SkipSpace7STOP2 ; if it's a space, skip it
SkipInc9STOP2:
mov bl, 93 ; ASCII of ']'
cmp bl,[DI]
; modtar a3ml el jump bl shakl el mo3aq dh
; 3lshan myenfa3sh a3ml jz far ValidOp16
jnz skipJump9STOP2 ; lw closed bracket, hy-jump
jmp ValidateSecondOP2 ; 1st op is memory: [0],[1],...[D],[E],[F]
skipJump9STOP2:
; lw wesel le hena, yb2a msh closed bracket, yb2a invalid
; lw msh ], yb2a invalid
jmp InvalidOPOP2
checkbracketSTOP2:
inc DI ; DI dlw2ty btshawer 3la ] aw shwyt spaces
SkipSpace4STOP2: ; Skips spaces after the [, and before the letter
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipInc10STOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
inc DI
jmp SkipSpace4STOP2 ; if it's a space, skip it
SkipInc10STOP2:
mov bl, 93 ; ASCII of ']'
cmp bl,[DI]
; modtar a3ml el jump bl shakl el mo3aq dh
; 3lshan myenfa3sh a3ml jz far ValidOp16
jnz skipJump8STOP2 ; lw closed bracket, hy-jump
jmp ValidateSecondOP2 ; 1st op is [SI],[DI],[SP],[BP]
skipJump8STOP2:
; lw wesel le hena, yb2a msh closed bracket, yb2a invalid
; lw msh ], yb2a invalid
jmp InvalidOPOP2
; h5osh fl 2nd operand b2a
ValidateSecondOP2:
;VS means validate second
; 2nd operand is either CL, or a byte worth of
; immediate values ranging from 00 to 0FF
mov ch,9 ; dh el flag bta3 el zero (hyban ta7t aktr)
inc DI
; el mfrood DI dlw2ty btshawer 3la space, aw comma, lw la yb2a invalid
; skipping some spaces
SkipSpacesecondVSOP2: ; Skips spaces before the command
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz skipCommaVSOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
; and reached the beginning of the 2nd operand
inc DI
jmp SkipSpacesecondVSOP2 ; in case it didn't jump to SkipComma, then it's a space, skip it
skipCommaVSOP2:
mov bl, 44 ; ASCII of ','
cmp bl,[DI]
jz skipJump32VSOP2
jmp InvalidOPOP2 ; if the spaces aren't followed with a comma, then it's invalid
skipJump32VSOP2:
inc DI ; lw wesel hena, yb2a el operand el awlany tmam l7d el comma, hbtdy fl tany b2a
; hshoof lw fy spaces el awl
; skipping some spaces
SkipSpacesecond2VSOP2: ; Skips spaces before the 2nd operand
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz startOfSecondOperandVSOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
; and reached the beginning of the 2nd operand
inc DI
jmp SkipSpacesecond2VSOP2 ; in case it didn't jump to SkipComma, then it's a space, skip it
startOfSecondOperandVSOP2:
;DI now points to the beginning of the 2nd operand
; habos el awl, lw la2eit DI btshawer 3la $, yb2a howa mkatabsh 7aga fl 2nd operand
; yb2a invalid
mov bl,36 ; ASCII of '$'
cmp bl,[DI]
jnz skipJump33VSOP2
jmp InvalidOPOP2 ; baroo7 aktb b2a el 2 operands
skipJump33VSOP2:
; deft dh (5)
mov bl,13 ; ASCII of 'Enter'
cmp bl,[DI]
jnz skipJump33VSOP2EN
jmp InvalidOPOP2 ; baroo7 aktb b2a el 2 operands
skipJump33VSOP2EN:
; dlw2ty DI btshawer 3la bdayet el 2nd operand
mov bl, 67 ; ASCII of 'C'
cmp bl,[DI]
jnz skipJump28VSOP2
jmp XorHorLVSOP2 ; 1st operand is CL
skipJump28VSOP2:
; lw msh C, habos lw howa value
mov bl, 65 ; ASCII of 'A'
cmp bl,[DI]
jnz skipJump37EAOP2
jmp InvalidOPOP2 ; Invalid as it starts with A not 0A
skipJump37EAOP2:
mov bl, 66 ; ASCII of 'B'
cmp bl,[DI]
jnz skipJump37FBOP2
jmp InvalidOPOP2 ; Invalid as it starts with B not 0B
skipJump37FBOP2:
mov bl, 68 ; ASCII of 'D'
cmp bl,[DI]
jnz skipJump37EDOP2
jmp InvalidOPOP2 ; Invalid as it starts with D not 0D
skipJump37EDOP2:
mov bl, 69 ; ASCII of 'E'
cmp bl,[DI]
jnz skipJump37EEOP2
jmp InvalidOPOP2 ; Invalid as it starts with E not 0E
skipJump37EEOP2:
mov bl, 70 ; ASCII of 'F'
cmp bl,[DI]
jnz skipJump37FFOP2
jmp InvalidOPOP2 ; Invalid as it starts with F not 0F
skipJump37FFOP2:
; skipping some zeros
mov ch,9 ; ba7ot ay value fl ch hena, w h8yrha lw 3mlt skip le 3la el a2al 1 zero
SkipzerosVSOP2: ; Skips zeros at the beginning of 2nd operand
mov bl, 48 ; ASCII of zero
cmp bl,[DI] ; checks if the DI currently has a zero
jnz startOfImmediateValueVSOP2 ; jumps if DI doesn't have a zero
; if it doesn't have a zero, then we have skipped all zeros,
; and reached the beginning of the immediate value
mov ch,7 ; 7atet hena value tanya, lw el ch=7 dlw2ty, dh kda m3nah eny 3mlt skip le 3l a2al 1 zero
inc DI
jmp SkipzerosVSOP2 ; in case it didn't jump to startOfImmediateValue, then it's a zero, skip it
startOfImmediateValueVSOP2: ; lama awsl hena, ana kda tanesht kol el zeros elly fl awl, w ebtadeit fl value nafsaha
;bs el fekra en el value momkn tb2a zero asln, fana kda 3mltlha skip, lazem a-handle el 7eta dyh
; 3mltlo handle bl flag el zwdto (ch=9 aw ch=7)
dec DI ; b3mlo decrement hena, 3lshan azwdo awl ma a5osh el loop
mov cl,5 ; 2a5ry 3lshan dh 16 bits, 2a5ry a7ot 4 arkam, lw 7at 5, yb2a size mismatch
CheckimmediateVSOP2:
inc DI ; b-check kol mra, el immediate value = kam
dec cl ; lw dh wesel eno b2a =0, yb2a invalid, l2no kda da5al 5 arkam
mov bl, 48 ; ASCII of '0'
cmp bl,[DI]
jnz skipJump10VSOP2
jmp CheckimmediateVSOP2 ; 2nd operand is 0
skipJump10VSOP2:
mov bl, 49 ; ASCII of '1'
cmp bl,[DI]
jnz skipJump11VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is 1
skipJump11VSOP2:
mov bl, 50 ; ASCII of '2'
cmp bl,[DI]
jnz skipJump12VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is 2
skipJump12VSOP2:
mov bl, 51 ; ASCII of '3'
cmp bl,[DI]
jnz skipJump13VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is 3
skipJump13VSOP2:
mov bl, 52 ; ASCII of '4'
cmp bl,[DI]
jnz skipJump14VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is 4
skipJump14VSOP2:
mov bl, 53 ; ASCII of '5'
cmp bl,[DI]
jnz skipJump15VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is 5
skipJump15VSOP2:
mov bl, 54 ; ASCII of '6'
cmp bl,[DI]
jnz skipJump16VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is 6
skipJump16VSOP2:
mov bl, 55 ; ASCII of '7'
cmp bl,[DI]
jnz skipJump17VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is 7
skipJump17VSOP2:
mov bl, 56 ; ASCII of '8'
cmp bl,[DI]
jnz skipJump18VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is 8
skipJump18VSOP2:
mov bl, 57 ; ASCII of '9'
cmp bl,[DI]
jnz skipJump19VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is 9
skipJump19VSOP2:
mov bl, 65 ; ASCII of 'A'
cmp bl,[DI]
jnz skipJump20VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is A
skipJump20VSOP2:
mov bl, 67 ; ASCII of 'B'
cmp bl,[DI]
jnz skipJump21VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is B
skipJump21VSOP2:
mov bl, 67 ; ASCII of 'C' ; dyh msh hywsalaha, 8eir lw kan bady b shwyt zeros fl awl
cmp bl,[DI]
jnz skipJump22VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is C
skipJump22VSOP2:
mov bl, 67 ; ASCII of 'D'
cmp bl,[DI]
jnz skipJump23VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is D
skipJump23VSOP2:
mov bl, 69 ; ASCII of 'E'
cmp bl,[DI]
jnz skipJump24VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is E
skipJump24VSOP2:
mov bl, 70 ; ASCII of 'F'
cmp bl,[DI]
jnz skipJump25VSOP2
jmp CheckimmediateVSOP2 ; 1st operand is F
skipJump25VSOP2:
; checking if the end of the 2nd operand has been reached
mov bl,36 ; ASCII of '$'
cmp bl,[DI]
jnz skipJump40VSOP2
jmp WriteOperandsOP2 ; baroo7 aktb b2a el 2 operands
skipJump40VSOP2:
; deft dh (5)
mov bl,13 ; ASCII of 'Enter'
cmp bl,[DI]
jnz skipJump40VSOP2EN
jmp WriteOperandsOP2 ; baroo7 aktb b2a el 2 operands
skipJump40VSOP2EN:
; lw wesel hena, yb2a ya 2ema invalid, ya 2ema kan immediate value
; kan 7atet esfar, wana 3mltlha skip. lw kda, yb2a ch=7, fa h-check bl ch
; aw 3amel spaces b3d el arkam
;h-handle el spaces el awl
; skipping some spaces
SkipSpaceafterVSOP2: ; Skips spaces after the immediate value
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipspaceincVSOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
; and reached the beginning of the command
inc DI
jmp SkipSpaceafterVSOP2 ; in case it didn't jump to SkipLetters, then it's a space, skip it
SkipspaceincVSOP2:
; checking if the end of the 2nd operand has been reached
mov bl,36 ; ASCII of '$'
cmp bl,[DI]
jnz skipJump40againVSOP2
jmp WriteOperandsOP2 ; baroo7 aktb b2a el 2 operands
skipJump40againVSOP2:
; deft dh (5)
mov bl,13 ; ASCII of 'Enter'
cmp bl,[DI]
jnz skipJump40againVSOP2EN
jmp WriteOperandsOP2 ; baroo7 aktb b2a el 2 operands
skipJump40againVSOP2EN:
; lw wesel hena, yb2a ya 2ema invalid, ya 2ema kan immediate value
; kan 7atet esfar, wana 3mltlha skip. lw kda, yb2a ch=7, fa h-check bl ch
mov bl,7
cmp ch,bl ; lw zero, yb2a valid w howa kan mda5al immediate value=0, wana 3mltlha skip
jnz skipJump41VSOP2
jmp WriteOperandsOP2 ; baroo7 aktb b2a el 2 operands
skipJump41VSOP2:
; lw wesel hena, yb2a invalid
jmp InvalidOPOP2
; lw kan ebtda b C 3la tool b2a, yb2a howa ya 2ema immediate value 5lst 3la kda
; ya 2ema register CL, fa dlw2ty habos howa L wala la
XorHorLVSOP2: ; first letter is C
inc DI ; DI dlw2ty btshawer 3la L, aw shwyt spaces, aw $
mov bl, 76 ; ASCII of 'L'
cmp bl,[DI]
jz skipJumpa8VSOP2
jmp InvalidOPOP2 ; 2nd op is not CL, yb2a invalid
skipJumpa8VSOP2:
;lw hena 5aletha badal invalidOP, 5aletha WriteOperands. htozbot; la nvm 8lt
; lw wesel hena, yb2a howa dlw2ty CL, el gy b2a hyb2a
; ya 2ema spaces, ya 2ema 5eles, ya 2ema invalid
inc DI ; kda bshawer 3la el ba3d el CL
SkipSpace2op3VSOP2: ; Skips spaces after the CL
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipInc5opVSOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces
inc DI
jmp SkipSpace2op3VSOP2 ; if it's a space, skip it
SkipInc5opVSOP2:
; kda 3mlt skip lel spaces, el mfrood yb2a 5eles dlw2ty
; checking if the end of the 2nd operand has been reached
mov bl,36 ; ASCII of '$'
cmp bl,[DI]
jnz skipJump40vmVSOP2
jmp WriteOperandsOP2 ; baroo7 aktb b2a el 2 operands
skipJump40vmVSOP2:
; deft dh (5)
mov bl,13 ; ASCII of 'Enter'
cmp bl,[DI]
jnz skipJump40vmVSOP2EN
jmp WriteOperandsOP2 ; baroo7 aktb b2a el 2 operands
skipJump40vmVSOP2EN:
; lw wesel le hena, yb2a msh bady bl C, w msh immediate
; yb2a invalid
jmp InvalidOPOP2
WriteOperandsOP2: ; dh b3d ma et2kd en kolo valid, b-save el operands fy variable b2a 3lshan tron yst3mlhom
;3ayez a-handle 7war eno myektebsh el zeros el zyada elly fl awl, wala el 7roof elly b3d el 2nd operands
; el 7roof handled kda 5las
; wl zero kaman
; dlw2ty DI byshawer 3la 2a5er correct character fl 2nd operand, el mfrood 3lshan tb2a valid
; lazem ala2y b3deeh $, aw spaces b3dein $, lw la yb2a invalid l2no mzwd 7roof 8lt b3d el command
inc DI ; kda DI btshawer 3la awl 7aga b3d el 2nd operand
; skipping some spaces
SkipSpaceaftervmcheckOP2: ; Skips spaces after the immediate value
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipspaceincvmcheckOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
; and reached the beginning of the command
inc DI
jmp SkipSpaceaftervmcheckOP2 ; in case it didn't jump to SkipLetters, then it's a space, skip it
SkipspaceincvmcheckOP2:
; checking if the end of the 2nd operand has been reached
mov bl,36 ; ASCII of '$'
cmp bl,[DI]
jz skipJump40vmcheckOP2
; deft dh (3)
mov bl,13 ; ASCII of 'enter'
cmp bl,[DI]
jz skipJump40vmcheckOP2
jmp InvalidOPOP2 ; hyb2a invalid lw mfeesh $ fl 2a5er
skipJump40vmcheckOP2:
mov SI, offset operand1 ; el variable elly hktb fyh el operands
mov DI, offset command ; el variable elly shayel el command
; skipping the command part
; skipping some spaces
SkipSpaceopOP2: ; Skips spaces before the command
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipLettersopOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
; and reached the beginning of the command
inc DI
jmp SkipSpaceopOP2 ; in case it didn't jump to SkipLettersop, then it's a space, skip it
SkipLettersopOP2: ; skips the command itself
; Code will reach this part when DI points to the start of the command
; We should skip all chars till we reach a space
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jz SkipSpace2opOP2 ; jumps if it has a space
; if it has a space, then we have skipped all letters,
; and reached the beginning of the operands
inc DI
jmp SkipLettersopOP2 ; in case it didn't jump to SkipSpace2, then it's a letter, skip it
SkipSpace2opOP2: ; Skips spaces after the command, and before the operand
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipInc4OP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,
inc DI
jmp SkipSpace2opOP2 ; if it's a space, skip it
SkipInc4OP2:
; Having reached this part, DI now points at the beginning of the first operand
; lw howa immediate value, momkn yb2a bade2 b shwyt zeros, fa h3mlha skip
;3ayez azwd hena eny asheel el zeros elly fl awl [DONE]
; skipping some zeros
;mov ch,9 ; ba7ot ay value fl ch hena, w h8yrha lw 3mlt skip le 3la el a2al 1 zero
; mloosh lazma hena, l2n kda w kda el bta3 valid f3ln
SkipzeroszeroroOP2: ; Skips zeros at the beginning of 1st operand
mov bl, 48 ; ASCII of zero
cmp bl,[DI] ; checks if the DI currently has a zero
jnz startOfImmediateValuezeroroOP2 ; jumps if DI doesn't have a zero
; if it doesn't have a zero, then we have skipped all zeros,
; and reached the beginning of the immediate value
;mov ch,7 ; 7atet hena value tanya, lw el ch=7 dlw2ty, dh kda m3nah eny 3mlt skip le 3l a2al 1 zero
inc DI
jmp SkipzeroszeroroOP2 ; in case it didn't jump to startOfImmediateValue, then it's a zero, skip it
startOfImmediateValuezeroroOP2:
; lama awsal hena, ana kda 3mlt skip le kol el zeros, w dlw2ty ya 2ema wa2ef 3la space aw comma
; ya 2ema wa2ef 3la char tany 3ady
; lw wa2ef 3la spaces, yb2a h3mlha skip, wl mfrood ala2y b3deeha comma
; yb2a kda el value kanet 0, wana 3mltlha skip, fa hktb zerohaya fy operand1, w yb2a kda 5las
; aroo7 3la operand2 b2a
SkipSpace2op2zeroroOP2: ; Skips spaces after the 1st operand
mov bl, 32 ; ASCII of space
cmp bl,[DI] ; checks if the DI currently has a space
jnz SkipInc5zeroroOP2 ; jumps if DI doesn't have a space
; if it doesn't have a space, then we have skipped all spaces,