-
Notifications
You must be signed in to change notification settings - Fork 0
/
8085 Assembler Final 2.cpp
1868 lines (1522 loc) · 74.5 KB
/
8085 Assembler Final 2.cpp
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
#include<dos.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<ctype.h>
#define N 247 // No of entries in MOT are 246. we are using 1 to 246. We are not using zeroth location of the array.
#define LABEL_LENGTH 11
#define MNEMONIC_LENGTH 9
#define OPERAND1_LENGTH 11
#define OPERAND2_LENGTH 11
#define OPCODE_LENGTH 2
#define LABEL_VALUE_LENGTH 4 // Maximum label value will be FFFF
#define COMMENT_LENGTH 50
#define MAX_NO_OF_ST_ENTRIES 200 // ST stands for Symbol Table
struct MOT // For MachineOp Table
{
char Mnemonic[MNEMONIC_LENGTH + 1];
char Operand1[OPERAND1_LENGTH + 1];
char Operand2[OPERAND2_LENGTH + 1];
char OpCode[OPCODE_LENGTH + 1];
int Length;
int Type;
};
struct PROG // PROG stands for program
{
char Label[LABEL_LENGTH + 1];
char Mnemonic[MNEMONIC_LENGTH + 1];
char Operand1[OPERAND1_LENGTH + 1];
char Operand2[OPERAND2_LENGTH + 1];
};
struct SYMBOLTABLEDEF
{
char Symbol[LABEL_LENGTH + 1];
char Value[LABEL_VALUE_LENGTH + 1];
};
struct DEFP1OUTPUT
{
unsigned int LN;
unsigned int LC;
char Label[LABEL_LENGTH + 1];
char Mnemonic[MNEMONIC_LENGTH + 1];
char Operand1[OPERAND1_LENGTH + 1];
char Operand2[OPERAND2_LENGTH + 1];
char OpCode[OPCODE_LENGTH + 1];
int IType;
char Comment[COMMENT_LENGTH + 1];
};
int Assembler_Pass1( struct MOT MOTInst[], char POT[][6], char SourceFileName[] );
char *SplitInstructionAndComment_Pass1( char str[], char Comment[] );
char *DeleteExcessWhiteSpaces_Pass1( char str[] );
struct PROG GetFields_Pass1( char Instruction[] );
int ReadMachineOpTable( struct MOT MOTInst[] );
int MOTGet_Pass1( struct MOT MOTInst[], char Mnemonic[], unsigned int LN );
void STSTO_Pass1( FILE *fp2, struct PROG SourceInst, unsigned int LC );
int IsPseudoOp_Pass1( char Mnemonic[], char POT[][6] );
int ProcessPseudoOp_Pass1( int p, struct PROG SourceInst, unsigned int *LC, FILE *fp2, unsigned int LN );
int ProcessORGorSTART_Pass1( struct PROG SourceInst, unsigned int *LC, FILE *fp2 , unsigned int LN );
int ProcessEQU_Pass1( struct PROG SourceInst, unsigned int *LC, FILE *fp2, unsigned int LN );
int ProcessDS_Pass1( struct PROG SourceInst, unsigned int *LC, FILE *fp2, unsigned int LN );
int ProcessDB_Pass1( struct PROG SourceInst, unsigned int *LC, FILE *fp2, unsigned int LN );
int ProcessDW_Pass1( struct PROG SourceInst, unsigned int *LC, FILE *fp2, unsigned int LN );
int ProcessEND_Pass1( struct PROG SourceInst, unsigned int *LC, FILE *fp2, unsigned int LN );
int CheckSymbolTableForDuplicates_Pass1( void );
int Write_Pass1_OutputToFile( struct PROG SourceInst, unsigned int LC, char Comment[], FILE *fp3, int Type, unsigned int LN );
///****************************************************************************************************************************************************************
int Assembler_Pass2( struct MOT MOTInst[], char POT[][6] );
struct DEFP1OUTPUT GetP1OutputInst_Pass2( FILE *P1OutputFP );
int ReadSymbolTable_Pass2( struct SYMBOLTABLEDEF ST[] );
int STGet_Pass2( char Operand1[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries );
int ProcessPseudoOp_Pass2( struct DEFP1OUTPUT P1OutputInst, FILE *P2OutputFP, unsigned int p );
int ProcessORGorSTART_Pass2( struct DEFP1OUTPUT P1OutputInst, FILE *P2OutputFP );
int ProcessEND_Pass2( struct DEFP1OUTPUT P1OutputInst, FILE *P2OutputFP );
int ProcessEQU_Pass2( struct DEFP1OUTPUT P1OutputInst, FILE *P2OutputFP );
int ProcessDS_Pass2( struct DEFP1OUTPUT P1OutputInst, FILE *P2OutputFP );
int ProcessDB_Pass2( struct DEFP1OUTPUT Temp, FILE *P2OutputFP );
int ProcessDW_Pass2( struct DEFP1OUTPUT Temp, FILE *P2OutputFP );
int MOTGet_Pass2( struct MOT MOTInst[], char ConcatenatedString[], struct DEFP1OUTPUT P1OutputInst );
int ProcessMachineOpPass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP );
int ProcessMOType1_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], FILE *P2OutputFP );
int ProcessMOType26_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP );
int ProcessMOType3_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP );
int ProcessMOType4_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP );
int ProcessMOType5_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP );
int ProcessMOType7_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP );
int ProcessMOType8_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP );
int ProcessMOType9_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP );
int Error_Pass2( struct DEFP1OUTPUT P1OutputInst );
int ProcessLiteral_Pass2( char *Operand, unsigned int LN );
void SetColor( int ForgC );
///******************************************************* MAIN STARTS HERE **************************************************************************************
int main()
{
struct MOT MOTInst[N];
char SourceFileName[80];
char POT[][6] = {"ZZZZ", "DB", "DS", "DW", "END", "EQU", "ORG", "START", "\0"}; // remember that the zeroth element is dummy ( creating POT )
ReadMachineOpTable( MOTInst ); // Reading MachineOp Table from the text file and store it into a structure
//printf("\nENTER THE FILE NAME OF SOURCE PROGRAM:: ");
//scanf(" %[^\n]", SourceFileName );
strcpy( SourceFileName, "SourceProgram.txt" );
Assembler_Pass1( MOTInst, POT, SourceFileName );
Assembler_Pass2( MOTInst, POT );
}
int Assembler_Pass1( struct MOT MOTInst[], char POT[][6], char SourceFileName[] )
{
FILE *fp, *fp2, *fp3;
unsigned int counter, p;
int MOTIndex, Length;
unsigned int LC, LN;
struct PROG SourceInst;
char str[256], InstructionWithComment[256], Instruction[256], Comment[256];
char *str2; // For recieving purpose
if( ( fp = fopen( SourceFileName, "r" ) ) == NULL ) // Opening a file ( read only ) to read the Source program
{
SetColor(12);
printf( "\nError opening Source Instruction file \n\a" ); //error
SetColor(0);
exit(0);
}
if( ( fp2 = fopen( "SymbolTable.txt","w" ) ) == NULL ) // Opening a file ( write only ) to store the Symbol table
{
SetColor(12);
printf( "Error opening symbol Table for writing purpose \n\a" ); //error
SetColor(0);
exit(0);
}
if( ( fp3 = fopen( "Pass1Output.txt","w" ) ) == NULL ) // Opening a file ( write only ) to store the result of Pass1 in file
{
SetColor(12);
printf( "Error opening Pass1output for writing purpose \n\a" ); //error
SetColor(0);
exit(0);
}
/// Starting pass 1 : preparing symbol table
LC = 0; // Assigning location counter to 2000
LN = 1; // Assigning the line counter to 1
while(!feof(fp))
{
fscanf( fp, " %[^\n]\n", str ); // Read the full sentence from the given file with comment
str2 = DeleteExcessWhiteSpaces_Pass1( str ); // Deletes all the extra spaces and tabs ( no tabs will be present after execution of this function )
strcpy( InstructionWithComment, str2 ); // Store the instruction in the InstructionWithComment variable
if( ( InstructionWithComment[0] == '/' && InstructionWithComment[1] == '/' ) || ( InstructionWithComment[0] == ';' ) )
{
LN = LN + 1;
continue;
}
str2 = SplitInstructionAndComment_Pass1( str, Comment ); // Delete comment from the instruction
strcpy( Instruction, str2 ); // Store the instruction ( without comment and extra spaces ) ie. A proper instruction
SourceInst = GetFields_Pass1(Instruction); // Separating the fields from the Instruction ie. Label, Mnemonic, Operand1, Operand2
/// PASS 1 STARTS HERE
/// Processing PseudoOps and MachineOps
if( ( p = IsPseudoOp_Pass1( SourceInst.Mnemonic, POT ) ) ) // checking if the Mnemonic is pseudoOp if yes then ProcessPseudoOp_Pass1() will be executed
{
Length = ProcessPseudoOp_Pass1( p, SourceInst, &LC, fp2 , LN );
Write_Pass1_OutputToFile( SourceInst, LC, Comment, fp3, -99, LN ); // Storing the result of PASS1 in a file ( Pass1Output.txt ). Sending Dummy Instruction Type, as type is required only for MachineOp
LC = LC + Length;
}
else // If the Mnemonic is not a pseudoOp then it might be machine Op if yes then execute the following functions
{
MOTIndex = MOTGet_Pass1( MOTInst, SourceInst.Mnemonic, LN ); // Identify the index of the Mnemonic in MOT and store it in MOTIndex
if( MOTIndex == N ) // If syntax error in Mnemonic
{
SetColor( 12 );
printf( "\n\n LINE NO:%d :: HAS SYNTAX ERROR IN MNEMONIC.... \n\n\a ", LN ); // error#1 in mnemonic
SetColor( 0 );
exit( 0 );
}
if( ( SourceInst.Label[0] )!= '\0' ) // If label is present then call STSTO_Pass1
{
STSTO_Pass1(fp2, SourceInst, LC); // Store the Label in symbol table file
}
Write_Pass1_OutputToFile( SourceInst, LC, Comment, fp3, MOTInst[MOTIndex].Type, LN ); // Storing the result of PASS1 in a file ( Pass1Output.txt )
LC = LC + MOTInst[MOTIndex].Length; // Increment the location counter by the length of the MachineOp ( length is fetched from the MOT table
}
LN = LN + 1; // Increment the Line counter by 1
}
fclose( fp ); // Closing all the files
fclose( fp2 );
fclose( fp3 );
CheckSymbolTableForDuplicates_Pass1( ); // Checking symbol table for any duplicate ( ie. repeated ) symbols
}
/// MAIN ENDS HERE
int Assembler_Pass2( struct MOT MOTInst[], char POT[][6] )
{
int NoOfSTEntries, i, STIndex;
FILE *P1OutputFP, *P2OutputFP;
struct SYMBOLTABLEDEF ST[MAX_NO_OF_ST_ENTRIES]; // ST for Symbol Table
struct DEFP1OUTPUT P1OutputInst;
unsigned int p, LN;
// Reading Symbol Table from file and store it in a structural array
NoOfSTEntries = ReadSymbolTable_Pass2( ST );
if( ( P1OutputFP = fopen( "Pass1Output.txt", "r" ) ) == NULL )
{
SetColor( 12 );
printf("\nERROR OPENING Pass1Output.txt FILE\n\n\a ");
SetColor( 0 );
exit( 0 );
}
if( ( P2OutputFP = fopen( "Pass2Output.txt", "w" ) ) == NULL )
{
SetColor( 12 );
printf("\nERROR OPENING Pass2Output.txt FILE\n\n\a ");
SetColor( 0 );
exit( 0 );
}
LN = 1;
while( !feof( P1OutputFP ) )
{
P1OutputInst = GetP1OutputInst_Pass2( P1OutputFP );
if( ( p = IsPseudoOp_Pass1( P1OutputInst.Mnemonic, POT ) ) ) // checking if the Mnemonic is pseudoOp if yes then ProcessPseudoOp_Pass1() will be executed
{
ProcessPseudoOp_Pass2( P1OutputInst, P2OutputFP, p );
}
else
{
ProcessMachineOpPass2( P1OutputInst, MOTInst, ST, NoOfSTEntries, P2OutputFP );
}
LN = LN + 1;
}
fclose( P1OutputFP );
fclose( P2OutputFP );
}
int ProcessMachineOpPass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP )
{
char Spaces11[] = " ";
//int MOTIndex; // MOTIndex variable is Local and different than the one used in Pass 1
/*
* If the fields of P1OutputInst ( ie. Label, Mnemonic, Operand1, Operand2, and Comment) are empty ( ie. indicated
* by ? ) then place spaces in those fields in temp variable.
*/
if( P1OutputInst.Label[0] == '?') // If Label is not present
{
strcpy( P1OutputInst.Label, Spaces11 ); // Fill it with 11 blank spaces in the temp variable
P1OutputInst.Label[11] = '\0'; // And terminate the Label string
}
if( P1OutputInst.Operand1[0] == '?') // If Operand 1 is not present
{
strcpy( P1OutputInst.Operand1, Spaces11 ); // Fill it with 14 blank spaces in the temp variable
P1OutputInst.Operand1[11] = '\0'; // And terminate the Operand 1 string
}
if( P1OutputInst.Operand2[0] == '?') // If Operand 2 is not present
{
strcpy( P1OutputInst.Operand2, Spaces11 ); // Fill it with 14 blank spaces in the temp variable
P1OutputInst.Operand2[11] = '\0'; // And terminate the Operand 2 string
}
if( P1OutputInst.Comment[0] == '?') // If Operand 2 is not present
{
strcpy( P1OutputInst.Comment, Spaces11 ); // Fill it with 14 blank spaces in the temp variable
P1OutputInst.Comment[11] = '\0'; // And terminate the Operand 2 string
}
if( P1OutputInst.IType == 1 )
{
ProcessMOType1_Pass2( P1OutputInst, MOTInst, P2OutputFP );
}
else if( P1OutputInst.IType == 2 || P1OutputInst.IType == 6 )
{
ProcessMOType26_Pass2( P1OutputInst, MOTInst, ST, NoOfSTEntries, P2OutputFP );
}
else if( P1OutputInst.IType == 3 )
{
ProcessMOType3_Pass2( P1OutputInst, MOTInst, ST, NoOfSTEntries, P2OutputFP );
}
else if( P1OutputInst.IType == 4 )
{
ProcessMOType4_Pass2( P1OutputInst, MOTInst, ST, NoOfSTEntries, P2OutputFP );
}
else if( P1OutputInst.IType == 5 )
{
ProcessMOType5_Pass2( P1OutputInst, MOTInst, ST, NoOfSTEntries, P2OutputFP );
}
else if( P1OutputInst.IType == 7 )
{
ProcessMOType7_Pass2( P1OutputInst, MOTInst, ST, NoOfSTEntries, P2OutputFP );
}
else if( P1OutputInst.IType == 8 )
{
ProcessMOType8_Pass2( P1OutputInst, MOTInst, ST, NoOfSTEntries, P2OutputFP );
}
else if( P1OutputInst.IType == 9 )
{
ProcessMOType9_Pass2( P1OutputInst, MOTInst, ST, NoOfSTEntries, P2OutputFP );
}
}
int ProcessMOType9_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP )
{
int STIndex, MOTIndex; // MOTIndex variable is Local and different than the one used in Pass 1
char ConcatenatedString[20], SourceOperand1[OPERAND1_LENGTH + 1], SourceOperand2[OPERAND2_LENGTH + 1];
char HigherByte[3], LowerByte[3];
strcpy( SourceOperand1, P1OutputInst.Operand1 );
strcpy( SourceOperand2, P1OutputInst.Operand2 );
if( ( STIndex = STGet_Pass2( P1OutputInst.Operand1, ST, NoOfSTEntries ) ) != -88 ) // To check if there is symbol in OP1 we go to STGet_Pass2, if yes
{
strcpy( P1OutputInst.Operand1, ST[STIndex].Value ); // Copy the Value of symbol in that Operand field ( ie. in P1OutputInst.Operand1 )
}
if( ( STIndex = STGet_Pass2( P1OutputInst.Operand2, ST, NoOfSTEntries ) ) != -88 ) // To check if there is symbol in OP1 we go to STGet_Pass2, if yes
{
strcpy( P1OutputInst.Operand2, ST[STIndex].Value ); // Copy the Value of symbol in that Operand field ( ie. in P1OutputInst.Operand1 )
}
else // Else it is a Literal then process Literal
{
ProcessLiteral_Pass2( &P1OutputInst.Operand2[0], P1OutputInst.LN ); // Process Literal in Operand 1
}
// Making SearchString for the instruction
strcpy( ConcatenatedString, P1OutputInst.Mnemonic ); // Copying the Mnemonic in ConcatenatedString for the searching process
strcat( ConcatenatedString, P1OutputInst.Operand1 );
// Sending the SearchString for searching MOT and getting MOTIndex
MOTIndex = MOTGet_Pass2( MOTInst, ConcatenatedString, P1OutputInst );
P1OutputInst.Operand2[4] = '\0'; // Deleting H from the Operand 2
HigherByte[0] = P1OutputInst.Operand2[0];
HigherByte[1] = P1OutputInst.Operand2[1];
HigherByte[2] = '\0';
LowerByte[0] = P1OutputInst.Operand2[2];
LowerByte[1] = P1OutputInst.Operand2[3];
LowerByte[2] = '\0';
// Writing the processed output to the P2OutputFP File
fprintf( P2OutputFP, "%04X ", P1OutputInst.LC ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%s", MOTInst[MOTIndex].OpCode ); // Put OpCode in P2Output File
fprintf( P2OutputFP, "%-4s", " " ); // Put Spaces for formatting in P2Output File
fprintf( P2OutputFP, "%-15s", P1OutputInst.Label ); // Put Label in P2Output File
fprintf( P2OutputFP, "%-8s", P1OutputInst.Mnemonic ); // Put Mnemonic in P2Output File
fprintf( P2OutputFP, "%-15s", SourceOperand1 ); // Put Operand 1 in P2Output File
fprintf( P2OutputFP, "%-15s", SourceOperand2 ); // Put Operand 2 in P2Output File
fprintf( P2OutputFP, "%s\n", P1OutputInst.Comment ); // Put Comment in P2Output File
fprintf( P2OutputFP, "%04X ", ( P1OutputInst.LC + 1 ) ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%-7s\n", LowerByte ); // Put Operand 1 in P2Output File
fprintf( P2OutputFP, "%04X ", ( P1OutputInst.LC + 2 ) ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%-7s\n", HigherByte ); // Put Operand 1 in P2Output File
}
int ProcessMOType8_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP )
{
int STIndex, MOTIndex; // MOTIndex variable is Local and different than the one used in Pass 1
char ConcatenatedString[20], SourceOperand1[OPERAND1_LENGTH + 1], SourceOperand2[OPERAND2_LENGTH + 1];
strcpy( SourceOperand1, P1OutputInst.Operand1 );
strcpy( SourceOperand2, P1OutputInst.Operand2 );
if( ( STIndex = STGet_Pass2( P1OutputInst.Operand1, ST, NoOfSTEntries ) ) != -88 ) // To check if there is symbol in OP1 we go to STGet_Pass2, if yes
{
strcpy( P1OutputInst.Operand1, ST[STIndex].Value ); // Copy the Value of symbol in that Operand field ( ie. in P1OutputInst.Operand1 )
}
if( ( STIndex = STGet_Pass2( P1OutputInst.Operand2, ST, NoOfSTEntries ) ) != -88 ) // To check if there is symbol in OP1 we go to STGet_Pass2, if yes
{
strcpy( P1OutputInst.Operand2, ST[STIndex].Value ); // Copy the Value of symbol in that Operand field ( ie. in P1OutputInst.Operand1 )
}
else // Else it is a Literal then process Literal
{
ProcessLiteral_Pass2( &P1OutputInst.Operand2[0], P1OutputInst.LN ); // Process Literal in Operand 1
}
// Making SearchString for the instruction
strcpy( ConcatenatedString, P1OutputInst.Mnemonic ); // Copying the Mnemonic in ConcatenatedString for the searching process
strcat( ConcatenatedString, P1OutputInst.Operand1 );
// Sending the SearchString for searching MOT and getting MOTIndex
MOTIndex = MOTGet_Pass2( MOTInst, ConcatenatedString, P1OutputInst );
P1OutputInst.Operand2[2] = '\0'; // Deleting H from the Operand 2
// Writing the processed output to the P2OutputFP File
fprintf( P2OutputFP, "%04X ", P1OutputInst.LC ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%s", MOTInst[MOTIndex].OpCode ); // Put OpCode in P2Output File
fprintf( P2OutputFP, "%-4s", " " ); // Put Spaces for formatting in P2Output File
fprintf( P2OutputFP, "%-15s", P1OutputInst.Label ); // Put Label in P2Output File
fprintf( P2OutputFP, "%-8s", P1OutputInst.Mnemonic ); // Put Mnemonic in P2Output File
fprintf( P2OutputFP, "%-15s", SourceOperand1 ); // Put Operand 1 in P2Output File
fprintf( P2OutputFP, "%-15s", SourceOperand2 ); // Put Operand 2 in P2Output File
fprintf( P2OutputFP, "%s\n", P1OutputInst.Comment ); // Put Comment in P2Output File
fprintf( P2OutputFP, "%04X ", ( P1OutputInst.LC + 1 ) ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%-7s\n", P1OutputInst.Operand2 ); // Put Operand 1 in P2Output File
}
int ProcessMOType7_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP )
{
int STIndex, MOTIndex; // MOTIndex variable is Local and different than the one used in Pass 1
char ConcatenatedString[20], SourceOperand1[OPERAND1_LENGTH + 1], SourceOperand2[OPERAND2_LENGTH + 1];
strcpy( SourceOperand1, P1OutputInst.Operand1 );
strcpy( SourceOperand2, P1OutputInst.Operand2 );
if( ( STIndex = STGet_Pass2( P1OutputInst.Operand1, ST, NoOfSTEntries ) ) != -88 ) // To check if there is symbol in OP1 we go to STGet_Pass2, if yes
{
strcpy( P1OutputInst.Operand1, ST[STIndex].Value ); // Copy the Value of symbol in that Operand field ( ie. in P1OutputInst.Operand1 )
}
if( ( STIndex = STGet_Pass2( P1OutputInst.Operand2, ST, NoOfSTEntries ) ) != -88 ) // To check if there is symbol in OP1 we go to STGet_Pass2, if yes
{
strcpy( P1OutputInst.Operand2, ST[STIndex].Value ); // Copy the Value of symbol in that Operand field ( ie. in P1OutputInst.Operand1 )
}
// Making SearchString for the instruction
strcpy( ConcatenatedString, P1OutputInst.Mnemonic ); // Copying the Mnemonic in ConcatenatedString for the searching process
strcat( ConcatenatedString, P1OutputInst.Operand1 );
strcat( ConcatenatedString, P1OutputInst.Operand2 );
// Sending the SearchString for searching MOT and getting MOTIndex
MOTIndex = MOTGet_Pass2( MOTInst, ConcatenatedString, P1OutputInst );
// Writing the processed output to the P2OutputFP File
fprintf( P2OutputFP, "%04X ", P1OutputInst.LC ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%s", MOTInst[MOTIndex].OpCode ); // Put OpCode in P2Output File
fprintf( P2OutputFP, "%-4s", " " ); // Put Spaces for formatting in P2Output File
fprintf( P2OutputFP, "%-15s", P1OutputInst.Label ); // Put Label in P2Output File
fprintf( P2OutputFP, "%-8s", P1OutputInst.Mnemonic ); // Put Mnemonic in P2Output File
fprintf( P2OutputFP, "%-15s", SourceOperand1 ); // Put Operand 1 in P2Output File
fprintf( P2OutputFP, "%-15s", SourceOperand2 ); // Put Operand 2 in P2Output File
fprintf( P2OutputFP, "%s\n", P1OutputInst.Comment ); // Put Comment in P2Output File
}
int ProcessMOType5_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP )
{
int STIndex, MOTIndex; // MOTIndex variable is Local and different than the one used in Pass 1
char ConcatenatedString[20], HigherByte[3], LowerByte[3], SourceOperand1[OPERAND1_LENGTH + 1];
strcpy( SourceOperand1, P1OutputInst.Operand1 );
if( ( STIndex = STGet_Pass2( P1OutputInst.Operand1, ST, NoOfSTEntries ) ) != -88 ) // To check if there is symbol in OP1 we go to STGet_Pass2, if yes
{
strcpy( P1OutputInst.Operand1, ST[STIndex].Value ); // Copy the Value of symbol in that Operand field ( ie. in P1OutputInst.Operand1 )
}
else // Else it is a Literal then process Literal
{
ProcessLiteral_Pass2( &P1OutputInst.Operand1[0], P1OutputInst.LN ); // Process Literal in Operand 1
}
// Making SearchString for the instruction
strcpy( ConcatenatedString, P1OutputInst.Mnemonic ); // Copying the Mnemonic in ConcatenatedString for the searching process
// Sending the SearchString for searching MOT and getting MOTIndex
MOTIndex = MOTGet_Pass2( MOTInst, ConcatenatedString, P1OutputInst );
HigherByte[0] = P1OutputInst.Operand1[0];
HigherByte[1] = P1OutputInst.Operand1[1];
HigherByte[2] = '\0';
LowerByte[0] = P1OutputInst.Operand1[2];
LowerByte[1] = P1OutputInst.Operand1[3];
LowerByte[2] = '\0';
// Writing the processed output to the P2OutputFP File
fprintf( P2OutputFP, "%04X ", P1OutputInst.LC ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%s", MOTInst[MOTIndex].OpCode ); // Put OpCode in P2Output File
fprintf( P2OutputFP, "%-4s", " " ); // Put Spaces for formatting in P2Output File
fprintf( P2OutputFP, "%-15s", P1OutputInst.Label ); // Put Label in P2Output File
fprintf( P2OutputFP, "%-8s", P1OutputInst.Mnemonic ); // Put Mnemonic in P2Output File
fprintf( P2OutputFP, "%-15s", SourceOperand1 ); // Put Operand 1 in P2Output File
fprintf( P2OutputFP, "%-15s", P1OutputInst.Operand2 ); // Put Operand 2 in P2Output File
fprintf( P2OutputFP, "%s\n", P1OutputInst.Comment ); // Put Comment in P2Output File
fprintf( P2OutputFP, "%04X ", ( P1OutputInst.LC + 1 ) ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%-7s\n", LowerByte ); // Put Operand 1 in P2Output File
fprintf( P2OutputFP, "%04X ", ( P1OutputInst.LC + 2 ) ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%-7s\n", HigherByte ); // Put Operand 1 in P2Output File
}
int ProcessMOType3_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP )
{
int STIndex, MOTIndex; // MOTIndex variable is Local and different than the one used in Pass 1
char ConcatenatedString[20], SourceOperand1[OPERAND1_LENGTH + 1];
strcpy( SourceOperand1, P1OutputInst.Operand1 );
if( ( STIndex = STGet_Pass2( P1OutputInst.Operand1, ST, NoOfSTEntries ) ) != -88 ) // To check if there is symbol in OP1 we go to STGet_Pass2, if yes
{
strcpy( P1OutputInst.Operand1, ST[STIndex].Value ); // Copy the Value of symbol in that Operand field ( ie. in P1OutputInst.Operand1 )
}
else // Else it is a Literal then process Literal
{
ProcessLiteral_Pass2( &P1OutputInst.Operand1[0], P1OutputInst.LN ); // Process Literal in Operand 1
}
// Making SearchString for the instruction
strcpy( ConcatenatedString, P1OutputInst.Mnemonic ); // Copying the Mnemonic in ConcatenatedString for the searching process
// Sending the SearchString for searching MOT and getting MOTIndex
MOTIndex = MOTGet_Pass2( MOTInst, ConcatenatedString, P1OutputInst );
// Writing the processed output to the P2OutputFP File
fprintf( P2OutputFP, "%04X ", P1OutputInst.LC ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%s", MOTInst[MOTIndex].OpCode ); // Put OpCode in P2Output File
fprintf( P2OutputFP, "%-4s", " " ); // Put Spaces for formatting in P2Output File
fprintf( P2OutputFP, "%-15s", P1OutputInst.Label ); // Put Label in P2Output File
fprintf( P2OutputFP, "%-8s", P1OutputInst.Mnemonic ); // Put Mnemonic in P2Output File
fprintf( P2OutputFP, "%-15s", SourceOperand1 ); // Put Operand 1 in P2Output File
fprintf( P2OutputFP, "%-15s", P1OutputInst.Operand2 ); // Put Operand 2 in P2Output File
fprintf( P2OutputFP, "%s\n", P1OutputInst.Comment ); // Put Comment in P2Output File
fprintf( P2OutputFP, "%04X ", ( P1OutputInst.LC + 1 ) ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%-7s\n", P1OutputInst.Operand1 ); // Put Operand 1 in P2Output File
}
int ProcessMOType4_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP )
{
int STIndex, MOTIndex; // MOTIndex variable is Local and different than the one used in Pass 1
char ConcatenatedString[20], SourceOperand1[OPERAND1_LENGTH + 1];
strcpy( SourceOperand1, P1OutputInst.Operand1 );
if( ( STIndex = STGet_Pass2( P1OutputInst.Operand1, ST, NoOfSTEntries ) ) != -88 ) // To check if there is symbol in OP1 we go to STGet_Pass2, if yes
{
strcpy( P1OutputInst.Operand1, ST[STIndex].Value ); // Copy the Value of symbol in that Operand field ( ie. in P1OutputInst.Operand1 )
}
else // Else it is a Literal then process Literal
{
ProcessLiteral_Pass2( &P1OutputInst.Operand1[0], P1OutputInst.LN ); // Process Literal in Operand 1
}
// Making SearchString for the instruction
strcpy( ConcatenatedString, P1OutputInst.Mnemonic ); // Copying the Mnemonic in ConcatenatedString for the searching process
// Sending the SearchString for searching MOT and getting MOTIndex
MOTIndex = MOTGet_Pass2( MOTInst, ConcatenatedString, P1OutputInst );
// Writing the processed output to the P2OutputFP File
fprintf( P2OutputFP, "%04X ", P1OutputInst.LC ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%s", MOTInst[MOTIndex].OpCode ); // Put OpCode in P2Output File
fprintf( P2OutputFP, "%-4s", " " ); // Put Spaces for formatting in P2Output File
fprintf( P2OutputFP, "%-15s", P1OutputInst.Label ); // Put Label in P2Output File
fprintf( P2OutputFP, "%-8s", P1OutputInst.Mnemonic ); // Put Mnemonic in P2Output File
fprintf( P2OutputFP, "%-15s", SourceOperand1 ); // Put Operand 1 in P2Output File
fprintf( P2OutputFP, "%-15s", P1OutputInst.Operand2 ); // Put Operand 2 in P2Output File
fprintf( P2OutputFP, "%s\n", P1OutputInst.Comment ); // Put Comment in P2Output File
fprintf( P2OutputFP, "%04X ", ( P1OutputInst.LC + 1 ) ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%-7s\n", P1OutputInst.Operand1 ); // Put Operand 1 in P2Output File
}
int ProcessLiteral_Pass2( char *Operand, unsigned int LN )
{
int i, j, HexFlag;
char TempOp[OPERAND1_LENGTH + 1];
if( Operand[0] == '=' ) // Is Literal
{
i = 1; // Making provision for deleting '='
j = 0;
while( Operand[i] != '\0' ) // Deleting '=' and blank spaces from Operand
{
if( Operand[i] != ' ' ) // If i'th character is not blank
{
TempOp[j] = Operand[i]; // Copy the i'th character to temp string
++j;
}
++i;
}
TempOp[j] = '\0'; // Terminating temp string
strcpy( Operand, TempOp ); // Operand contains Literal string after deleting '=' and blank spaces
// Is Hex
i = 0;
HexFlag = 0; // For indicate Hex or Decimal Literal
while( Operand[i] != '\0' ) // Till '\0'
{
if( Operand[i] == 'h' || Operand[i] == 'H' ) // Deleting H or h from Operand string
{
HexFlag = 1; // If Hex Literal then HexFlag = 1
Operand[i] = '\0';
}
else
{
i = i + 1;
}
}
if( HexFlag ) // If Hex Literal
{
for( j=0; j<strlen( Operand ); ++j ) // Checking if the digits in the Operand string are all HEXADECIMAL
{
if( !isxdigit( Operand[j] ) ) // If the digits are not HEXADECIAML then print error
{
SetColor( 12 );
printf("\n ERROR IN LINE NO: %d :: LITERAL DOES NOT CONTAIN HEXADECIMAL DIGITS \n\a", LN ); // error
SetColor( 0 );
exit( 0 );
}
}
}
// Processing Decimal Literal
if( !HexFlag ) // If Decimal
{
i = 0;
while( Operand[i] != '\0' )
{
if( Operand[i] == 'd' || Operand[i] == 'D' ) // Deleting H or h from Operand string
{
Operand[i] = '\0';
}
else
{
i = i + 1;
}
}
for( j=0; j<strlen( Operand ); ++j ) // Checking if the digits in the Operand string are all HEXADECIMAL
{
if( !isdigit( Operand[j] ) ) // If the digits are not HEXADECIAML then print error
{
SetColor( 12 );
printf("\n ERROR IN LINE NO: %d :: LITERAL HAS NEITHER HEX NOR DECIMAL DIGITS \n\a", LN ); // error
SetColor( 0 );
exit( 0 );
}
}
if( strlen( Operand ) == 2 ) // If length of Operand is 2
{
i = strtol( Operand, NULL, 10 ); // Convert Operand from string to long integer
sprintf(Operand, "%02X", i); // Convert Long integer to Hex
}
else // If length of Operand is not equal to 2 ( ie. is 4 )
{
i = strtol( Operand, NULL, 10 ); // Convert Operand from string to Long integer
sprintf(Operand, "%04X", i); // Convert Long integer to Hex
}
}
}
}
int ProcessMOType26_Pass2( struct DEFP1OUTPUT P1OutputInst, struct MOT MOTInst[], struct SYMBOLTABLEDEF ST[], int NoOfSTEntries, FILE *P2OutputFP )
{
int STIndex, MOTIndex; // MOTIndex variable is Local and different than the one used in Pass 1
char ConcatenatedString[20], SourceOperand1[OPERAND1_LENGTH + 1];
strcpy( SourceOperand1, P1OutputInst.Operand1 );
if( ( STIndex = STGet_Pass2( P1OutputInst.Operand1, ST, NoOfSTEntries ) ) != -88 ) // To check if there is symbol in OP1 we go to STGet_Pass2, if yes
{
strcpy( P1OutputInst.Operand1, ST[STIndex].Value ); // Copy the Value of symbol in that Operand field ( ie. in P1OutputInst.Operand1 )
}
// Making SearchString for the instruction
strcpy( ConcatenatedString, P1OutputInst.Mnemonic ); // Copying the Mnemonic in ConcatenatedString for the searching process
strcat( ConcatenatedString, P1OutputInst.Operand1 ); // Concatenating P1OutputInst.Operand1 and ConcatenatedString
// Sending the SearchString for searching MOT and getting MOTIndex
MOTIndex = MOTGet_Pass2( MOTInst, ConcatenatedString, P1OutputInst );
// Writing the processed output to the P2OutputFP File
fprintf( P2OutputFP, "%04X ", P1OutputInst.LC ); // Put Location Counter in P2Output File
fprintf( P2OutputFP, "%s", MOTInst[MOTIndex].OpCode ); // Put OpCode in P2Output File
fprintf( P2OutputFP, "%-4s", " " ); // Put Spaces for formatting in P2Output File
fprintf( P2OutputFP, "%-15s", P1OutputInst.Label ); // Put Label in P2Output File
fprintf( P2OutputFP, "%-8s", P1OutputInst.Mnemonic ); // Put Mnemonic in P2Output File
fprintf( P2OutputFP, "%-15s", SourceOperand1 ); // Put Operand 1 in P2Output File
fprintf( P2OutputFP, "%-15s", P1OutputInst.Operand2 ); // Put Operand 2 in P2Output File
fprintf( P2OutputFP, "%s\n", P1OutputInst.Comment ); // Put Comment in P2Output File
}
///****************************************************************************************************************************************************************************************************************
int Error_Pass2( struct DEFP1OUTPUT P1OutputInst )
{
int i, j, Flag, n;
if( P1OutputInst.IType == 2 )
{
char Possibility2[][4] = { "A", "B", "C", "D", "E", "H", "L", "M", "SP", "PSW" };
for( i=0; i<=9; ++i)
{
if( !strcmp( P1OutputInst.Operand1, Possibility2[i] ) )
{
break;
}
}
if( i == 10 )
{
SetColor( 12 );
printf("\n ERROR :: LINE NO: %d HAS ERROR IN OPERAND 1\n\a", P1OutputInst.LN );
printf("\n POSSIBLE REGISTERS SHOULD BE: A, B, C, D, E, H, L, M, SP, PSW \n");
SetColor( 0 );
exit( 0 );
}
}
else if( P1OutputInst.IType == 3 || P1OutputInst.IType == 4 || P1OutputInst.IType == 5 )
{
Flag = 0;
n = strlen( P1OutputInst.Operand1 );
for(i=0; i<n; ++i)
{
if( !isxdigit(P1OutputInst.Operand1[i] ) )
{
Flag = 1;
}
}
if( Flag == 1 )
{
SetColor( 12 );
printf("\n\n ERROR :: LINE NO: %d HAS ERROR IN LABEL OF OPERAND 1\n\n\a", P1OutputInst.LN );
printf("\n POSSIBLY LABEL IN OPERAND 1 MAYBE MISSPELLED OR LITERAL SHOULD BE WRITTEN AS ' =XXH ' OR ' =XXXXH ' \n");
SetColor( 0 );
exit(0);
}
}
else if( P1OutputInst.IType == 6 )
{
char Possibility6[][2] = { "0", "1", "2", "3", "4", "5", "6", "7" };
for( i=0; i<=7; ++i)
{
if( !strcmp( P1OutputInst.Operand1, Possibility6[i] ) )
{
break;
}
}
if( i == 8 )
{
SetColor( 12 );
printf("\n\n ERROR :: LINE NO: %d HAS ERROR IN OPERAND 1 ( SOUULD BE IN BETWEEN RST 0 TO RST 7 )\n\n\a", P1OutputInst.LN );
SetColor( 0 );
exit( 0 );
}
}
else if( P1OutputInst.IType == 7 )
{
char Possibility7[][2] = { "A", "B", "C", "D", "E", "H", "L", "M" };
for( i=0; i<=7; ++i)
{
if( !strcmp( P1OutputInst.Operand1, Possibility7[i] ) )
{
break;
}
}
if( i == 8 )
{
SetColor( 12 );
printf("\n\n ERROR :: LINE NO: %d HAS ERROR IN OPERAND 1\n\n\a", P1OutputInst.LN );
printf("\n POSSIBLE REGISTERS SHOULD BE: A, B, C, D, E, H, L, M \n");
SetColor( 0 );
exit( 0 );
}
for( j=0; j<=7; ++j)
{
if( !strcmp( P1OutputInst.Operand2, Possibility7[j] ) )
{
break;
}
}
if( j == 8 )
{
SetColor( 12 );
printf("\n\n ERROR :: LINE NO: %d HAS ERROR IN OPERAND 2\n\n\a", P1OutputInst.LN );
printf("\n POSSIBLE REGISTERS SHOULD BE: A, B, C, D, E, H, L, M \n");
SetColor( 0 );
exit( 0 );
}
if( i == 7 && j == 7 )
{
SetColor( 12 );
printf("\n\n ERROR :: LINE NO: %d HAS ERROR IN BOTH OPERANDS ( BOTH SHOULD NOT BE M )\n\n\a", P1OutputInst.LN );
SetColor( 0 );
exit( 0 );
}
}
else if( P1OutputInst.IType == 8 )
{
char Possibility8[][2] = { "A", "B", "C", "D", "E", "H", "L", "M" };
for( i=0; i<=7; ++i)
{
if( !strcmp( P1OutputInst.Operand1, Possibility8[i] ) )
{
break;
}
}
if( i == 8 )
{
SetColor( 12 );
printf("\n\n ERROR :: LINE NO: %d HAS ERROR IN OPERAND 1\n\n\a", P1OutputInst.LN );
printf("\n POSSIBLE REGISTERS SHOULD BE: A, B, C, D, E, H, L, M \n");
SetColor( 0 );
exit( 0 );
}
Flag = 0;
n = strlen( P1OutputInst.Operand2 );
for(i=0; i<n; ++i)
{
if( !isxdigit(P1OutputInst.Operand2[i] ) )
{
Flag = 1;
}
}
if( Flag == 1 )
{
SetColor( 12 );
printf("\n\n ERROR :: LINE NO: %d HAS ERROR IN LABEL OF OPERAND 2\n\n\a", P1OutputInst.LN );
printf("\n POSSIBLY LABEL IN OPERAND 2 MAYBE MISSPELLED OR LITERAL SHOULD BE WRITTEN AS ' =XXH ' \n");
SetColor( 0 );
exit(0);
}
}
else if( P1OutputInst.IType == 9 )
{
char Possibility9[][3] = { "B", "D", "H", "SP" };
for( i=0; i<=3; ++i)
{
if( !strcmp( P1OutputInst.Operand1, Possibility9[i] ) )
{
break;
}
}
if( i == 4 )
{
SetColor( 12 );
printf("\n\n ERROR :: LINE NO: %d HAS ERROR IN OPERAND 1\n\n\a", P1OutputInst.LN );
printf("\n POSSIBLE REGISTERS SHOULD BE: B, D, H, SP \n");
SetColor( 0 );
exit( 0 );
}
Flag = 0;
n = strlen( P1OutputInst.Operand2 );
for(i=0; i<n; ++i)
{
if( !isxdigit(P1OutputInst.Operand2[i] ) )
{
Flag = 1;
}
}
if( Flag == 1 )
{
SetColor( 12 );
printf("\n\n ERROR :: LINE NO: %d HAS ERROR IN LABEL OF OPERAND 2\n\n\a", P1OutputInst.LN );
printf("\n POSSIBLY LABEL IN OPERAND 2 MAYBE MISSPELLED OR LITERAL SHOULD BE WRITTEN AS ' =XXXXH ' \n");
SetColor( 0 );
exit(0);
}
}
}
int MOTGet_Pass2( struct MOT MOTInst[], char ConcatenatedString[], struct DEFP1OUTPUT P1OutputInst )
{
int i;
char ConCatinatedMOTString[20];
Error_Pass2( P1OutputInst );
//Searching MOT
for( i=1; i<N; ++i )
{
if( P1OutputInst.IType == 1 || P1OutputInst.IType == 3 || P1OutputInst.IType == 4 || P1OutputInst.IType == 5 )
{
strcpy( ConCatinatedMOTString, MOTInst[i].Mnemonic );
}
else if( P1OutputInst.IType == 2 || P1OutputInst.IType == 6 )
{
// Making ConCatinatedMOTString by appending Operand1 to Mnemonic
strcpy( ConCatinatedMOTString, MOTInst[i].Mnemonic );
strcat( ConCatinatedMOTString, MOTInst[i].Operand1 );
}
else if( P1OutputInst.IType == 7 )
{
strcpy( ConCatinatedMOTString, MOTInst[i].Mnemonic );
strcat( ConCatinatedMOTString, MOTInst[i].Operand1 );
strcat( ConCatinatedMOTString, MOTInst[i].Operand2 );
}
else if( P1OutputInst.IType == 8 )
{
strcpy( ConCatinatedMOTString, MOTInst[i].Mnemonic );
strcat( ConCatinatedMOTString, MOTInst[i].Operand1 );
}
else if( P1OutputInst.IType == 9 )
{
strcpy( ConCatinatedMOTString, MOTInst[i].Mnemonic );
strcat( ConCatinatedMOTString, MOTInst[i].Operand1 );
}
if( !strcmp( ConCatinatedMOTString, ConcatenatedString ) )
{
break;
}
}