-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgasm.cpp
More file actions
2342 lines (1938 loc) · 84.2 KB
/
gasm.cpp
File metadata and controls
2342 lines (1938 loc) · 84.2 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
// GASM Source Code, Gareth Owen, gaz@athene.co.uk, http://gasm.cjb.net
// YOU MUST READ LICENSE.TXT BEFORE USE OF THE SOURCE CODE IS PERMITTED,
// IF YOU DO NOT HAVE LICENSE.TXT THEN EITHER GET A COPY OF
// DELETE THIS SOURCE CODE
/*
GASM Assembler
Copyright (C) 1999 Gareth Owen <gaz@athene.co.uk>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "gasm.h"
// Prototypes
int gstrnicmp(char *string1, char *string2, unsigned int n);
int gstricmp(char *string1, char *string2);
void gstrlwr(char *string);
t_instruction Parseline(char *orig_line);
t_dynamic_instruction FindDynamicInstruction(char *ins_name, unsigned int parm1, unsigned int parm2);
unsigned long Eval2(char *e_string, char brackets, unsigned int evaluated);
unsigned char FindModRM(unsigned long &modrm_evaluated);
void GetDisplacement(char *d_string, char *displacement);
void fatal_error(char *error_msg);
t_instruction Handledesc(char *line);
char isHex(char *string);
t_dynamic_instruction AutoModify(unsigned int &parm1_evaluated, unsigned int &parm2_evaluated, char *parm1, char *parm2, char *temp_p);
t_dynamic_instruction Parm1_Modify(unsigned int &parm1_evaluated, unsigned int &parm2_evaluated, char *parm1, char *parm2, char *temp_p);
t_dynamic_instruction Parm2_Modify(unsigned int &parm1_evaluated, unsigned int &parm2_evaluated, char *parm1, char *parm2, char *temp_p);
signed long GetRelative(char *address, unsigned long instructionend);
unsigned char CheckValidLabel(char *label_name);
unsigned int GetSegment(char *s_string);
unsigned long GetOffset(char *s_string);
char Contains(char *c_string, char c); // Does the character contain c?
t_fixed_instruction FindFixedInstruction(char *instruction);
unsigned long SolveEquation(char *equation);
char isInstruction(char *i_string);
char isRelativeInstruction(char *instruction);
void Command(char *line);
void Preprocessor(char *line);
t_instruction Handletimes(char *line);
t_instruction Handletss(char *line);
char isSegmentRegister(char *seg_reg);
char SegmentRegister(char *seg_reg);
char isControlRegister(char *control_reg);
char ControlRegister(char *control_reg);
char isDebugRegister(char *debug_reg);
char DebugRegister(char *debug_reg);
void HandleEQU(char *line);
int remstring(char *str, char *rem);
unsigned char FindRegister(char *reg);
void ExtractBrackets(char *string);
t_instruction DataType(char *line);
t_instruction popSeg(char *seg_reg);
t_instruction pushSeg(char *seg_reg);
void Parsefile(char writeoutput);
unsigned long line_number = 0; // Current line number of current file
unsigned long offset = 0; // Binary offset (of output file)
unsigned char pass_number = 1, BITS = 16; // Current pass
unsigned int prefixes = 0;
unsigned char address_override_disable = 0, address_override_force = 0, size_override_force = 0;
char *temp_p=0; // Stores instruction, sorry, un-imaginative name :)
char filename[255];
FILE *out;
//**************************************
// MAIN FUNCTION -=- PROGRAM ENTRY POINT
//**************************************
void main(int argc, char **argv)
{
char tempstring[500], *newline;
int loop=0;
tempstring[0] = '\0';
// Initialise label array
for(loop=0; loop<=MAX_LABELS; loop++) {
labels[loop].active = FALSE;
labels[loop].pass_number = 0;
}
memcpy(&labels, &predefines, sizeof(predefines));
printf("GASM --- Gaz's Assembler v0.55, by Gareth Owen.\n(C)Copyright 1998 by Gareth Owen. All rights reserved\n");
printf("http://gasm.cjb.net -=- Contact Gareth Owen at gaz@athene.co.uk\n");
if(argc != 2)
{
printf("\n\nUsage: gasm <source.asm>\n");
exit(1);
}
for(loop=0; argv[1][loop]!='.' && argv[1][loop]!=(char)NULL; loop++)
tempstring[loop] = argv[1][loop];
tempstring[loop] = (char)NULL;
strcat(tempstring, ".bin");
// Open output file
if((out = fopen(tempstring, "wb"))==(char)NULL)
{
perror(tempstring);
exit(1);
}
// Initialize variables for Pass 1
pass_number = 1;
offset = 0;
line_number = 0;
for(;pass_number <= 3; pass_number++)
{
strcpy(filename, argv[1]);
if(pass_number!=3) Parsefile(FALSE);
else Parsefile(TRUE);
offset = 0;
line_number = 0;
BITS = 16;
}
fclose(out);
}
void Parsefile(char writeoutput)
{
char line[500], *newline=0;
FILE *in;
t_instruction instruction; // Stores assembled/compiled instruction
line[0] = '\0';
instruction.length = 0;
// Open source file
if((in = fopen(filename, "rt"))==(char)NULL)
{
printf("Error opening %s\n", filename);
perror(filename);
exit(1);
}
while(!feof(in))
{
instruction.length = 0; // Clear instruction length
line[0] = '\0';
fgets(line, 500, in); // Read in Line
line_number++; // Increase line number count
// Remove any \r's and \n's and make ;s the line terminator
for(int loop=0; line[loop]; loop++) if(line[loop]=='\r' || line[loop]=='\n' || line[loop]==';') line[loop]=(char)(char)NULL;
newline = line;
for(; newline[0]==' ' || newline[0]=='\t'; newline++);
instruction = Parseline(newline); // Parse line to assembler
prefixes = 0;
// Write assembled/compiled instruction to out file
if(writeoutput == TRUE && instruction.length!=0) for(int loop=0; loop<instruction.length; loop++) fputc(instruction.i[loop], out);
offset += instruction.length; // Add instruction length to current offset
free(instruction.i); // Free instruction data
}
fclose (in);
}
//***************************************************
// Assembles/compiles instruction from text to binary
//***************************************************
t_instruction Parseline(char *line)
{
// Just a load of variables that are going to be used
t_instruction instruction;
t_fixed_instruction finstruction;
char *parm1=0, *parm2=0, temp_char=0, temp_modrm=0, temp_string[255], *orig_line;
unsigned int parm1_evaluated=0, parm2_evaluated=0;
unsigned int loop = 0, temp_count=0, temp_int=0;
unsigned long temp_long = 0, modrm_eval;
temp_p = 0;
address_override_disable = 0;
address_override_force = 0;
size_override_force = 0;
signed char temp_schar = 0; // for the relative instructions
signed int temp_sint = 0;
signed long temp_slong = 0;
t_dynamic_instruction find_dyn_instruction; // Used searching for dynamic instruction
find_dyn_instruction.opcode_length = 0; // Set to zero..
orig_line = (char *) malloc(strlen(line) + 1);
strcpy(orig_line, line);
temp_count = 0;
// Initialize final instruction variables
instruction.length = 0;
instruction.i = (unsigned char *) malloc(100);
if(strstr(line, "s:"))
{
if(strstr(line, "cs:")) { prefixes |= PREFIX_CS; remstring(line, "cs:"); instruction.i[temp_count] = 0x2E; temp_count++; parm1_evaluated = Evaluator(line);}
if(strstr(line, "ds:")) { prefixes |= PREFIX_DS; remstring(line, "ds:"); instruction.i[temp_count] = 0x3E; temp_count++; parm1_evaluated = Evaluator(line);}
if(strstr(line, "es:")) { prefixes |= PREFIX_ES; remstring(line, "es:"); instruction.i[temp_count] = 0x26; temp_count++; parm1_evaluated = Evaluator(line);}
if(strstr(line, "fs:")) { prefixes |= PREFIX_FS; remstring(line, "fs:"); instruction.i[temp_count] = 0x64; temp_count++; parm1_evaluated = Evaluator(line);}
if(strstr(line, "gs:")) { prefixes |= PREFIX_GS; remstring(line, "gs:"); instruction.i[temp_count] = 0x65; temp_count++; parm1_evaluated = Evaluator(line);}
if(strstr(line, "ss:")) { prefixes |= PREFIX_SS; remstring(line, "ss:"); instruction.i[temp_count] = 0x36; temp_count++; parm1_evaluated = Evaluator(line);}
}
// override prefixes
if(prefixes & PREFIX_REPNZ) { instruction.i[temp_count] = 0xF2; temp_count++; }
if(prefixes & PREFIX_REPZ) { instruction.i[temp_count] = 0xF3; temp_count++; }
if(prefixes & PREFIX_LOCK) { instruction.i[temp_count] = 0xF0; temp_count++; }
if(prefixes & PREFIX_REP) { instruction.i[temp_count] = 0xF3; temp_count++; }
temp_p = strtok(line, " \t"); // temp_p stores instruction name, i couldn't think of a more imaginative name, sorry :-)
if(!temp_p) return instruction;
// Get parameter one to the instruction
parm1 = strtok((char)NULL, ",");
if(parm1) while((parm1[0] == ' ' || parm1[0] == '\t') && parm1[0]!=(char)NULL) if (parm1[0]==' ' || parm1[0]=='\t') parm1++;
if(parm1) for(loop=(strlen(parm1)-1); loop!=0 && (parm1[loop]==' ' || parm1[loop]=='\t'); loop--) if(parm1[loop] == ' ' || parm1[loop] == '\t') parm1[loop]=(char)NULL;
if(!gstrnicmp(parm1, "equ", 3)) { HandleEQU(orig_line); return instruction; }
if(!gstrnicmp(parm1, "tss", 3)) return Handletss(orig_line);
if(isInstruction(temp_p)==FALSE || !gstrnicmp(temp_p, "rep", 3)) goto notinstruction;
if(parm1)
{
// Process any size overrides
if(strstr(parm1, "byte"))
{
remstring(parm1, "byte");
parm1_evaluated = Evaluator(parm1);
if(parm1_evaluated == EVALUATE_REGM32) { parm1_evaluated = EVALUATE_REGM8; address_override_force = TRUE; }
if(parm1_evaluated == EVALUATE_REGM16) parm1_evaluated = EVALUATE_REGM8;
}
else if(strstr(parm1, "word") && !strstr(parm1, "dword"))
{
remstring(parm1, "word");
parm1_evaluated = Evaluator(parm1);
if(parm1_evaluated == EVALUATE_IMM8) parm1_evaluated = EVALUATE_IMM16;
}
else if(strstr(parm1, "dword"))
{
remstring(parm1, "dword");
parm1_evaluated = Evaluator(parm1);
if(parm1_evaluated == EVALUATE_REGM16) { parm1_evaluated = EVALUATE_REGM32; address_override_disable = TRUE; }
if(parm1_evaluated == EVALUATE_PTR16_PTR16) parm1_evaluated = EVALUATE_PTR16_PTR32;
}
else parm1_evaluated = Evaluator(parm1);
} else parm1_evaluated = EVALUATE_NONE;
if(parm1) while((parm1[0] == ' ' || parm1[0] == '\t') && parm1[0]!=(char)NULL) if (parm1[0]==' ' || parm1[0]=='\t') parm1++;
if(parm1) for(loop=(strlen(parm1)-1); loop!=0 && (parm1[loop]==' ' || parm1[loop]=='\t'); loop--) if(parm1[loop] == ' ' || parm1[loop] == '\t') parm1[loop]=(char)NULL;
// Get parameter two of instruction
parm2 = strtok((char)NULL, ",");
if(parm2)
{
// Process any size overrides
if(strstr(parm2, "byte"))
{
remstring(parm2, "byte");
parm2_evaluated = Evaluator(parm2);
if(parm2_evaluated == EVALUATE_REGM16) parm2_evaluated = EVALUATE_REGM8;
if(parm2_evaluated == EVALUATE_REGM32) { parm2_evaluated = EVALUATE_REGM8; address_override_force = TRUE; }
}
else if(strstr(parm2, "word") && !strstr(parm2, "dword"))
{
remstring(parm2, "word");
parm2_evaluated = Evaluator(parm2);
if(parm2_evaluated == EVALUATE_IMM8) parm2_evaluated = EVALUATE_IMM16;
}
else if(strstr(parm2, "dword"))
{
remstring(parm2, "dword");
parm2_evaluated = Evaluator(parm2);
if(parm2_evaluated == EVALUATE_REGM16) { parm2_evaluated = EVALUATE_REGM32; address_override_disable = TRUE; }
if(parm1_evaluated == EVALUATE_PTR16_PTR16) parm1_evaluated = EVALUATE_PTR16_PTR32;
}
else parm2_evaluated = Evaluator(parm2);
} else parm2_evaluated = EVALUATE_NONE;
if(parm2) while((parm2[0] == ' ' || parm2[0] == '\t') && parm2[0]!=(char)NULL) if(parm2[0]==' ' || parm2[0]=='\t') parm2++;
if(parm2) for(loop=(strlen(parm2)-1); loop!=0 && (parm2[loop]==' ' || parm2[loop]=='\t'); loop--) if(parm2[loop] == ' ' || parm2[loop] == '\t') parm2[loop]=(char)NULL;
loop = 0;
// If the instruction has no parameters, then its a fixed instruction
if(parm1_evaluated == EVALUATE_NONE && parm2_evaluated == EVALUATE_NONE)
{
fixed_instruction:
finstruction = FindFixedInstruction(temp_p); // Try and find it...
if((BITS == 16 && finstruction.bits == 32) || (BITS == 32 && finstruction.bits == 16)) { instruction.i[temp_count] = 0x66; instruction.i[temp_count+1] = 0x67; temp_count+=2; }
// Return it if it was found
if(finstruction.length!=0)
{
instruction.length = finstruction.length + temp_count;
instruction.i[temp_count] = finstruction.c1; temp_count++;
if(finstruction.length == 2 || finstruction.length == 3) { instruction.i[temp_count] = finstruction.c2; temp_count++; }
if(finstruction.length == 3) { instruction.i[temp_count] = finstruction.c3; temp_count++; }
return instruction;
}
}
// Use some intelligence to realise that if the parameter is
// an IMM8, and the instruction only supports IMM16, then we can still
// do it....(this function does a lot more too!)
find_dyn_instruction = AutoModify(parm1_evaluated, parm2_evaluated, parm1, parm2, temp_p);
// Looks like that variation of the instruction wasn't found, possibly because
// of invalid parameters, or something
notinstruction:
if(find_dyn_instruction.opcode_length == 0)
{
if(!gstricmp(temp_p, "pop") && parm1_evaluated == EVALUATE_SREG) return popSeg(parm1);
if(!gstricmp(temp_p, "push") && parm1_evaluated == EVALUATE_SREG) return pushSeg(parm1);
if(!gstricmp(temp_p, "desc")) return Handledesc(orig_line);
if(!gstricmp(temp_p, "repne") || !gstricmp(temp_p, "repnz")) prefixes |= PREFIX_REPNZ;
if(!gstricmp(temp_p, "repe") || !gstricmp(temp_p, "repz")) prefixes |= PREFIX_REPZ;
if(!gstricmp(temp_p, "rep")) prefixes |= PREFIX_REP;
if(!gstricmp(temp_p, "lock")) prefixes |= PREFIX_LOCK;
if(!gstricmp(temp_p, "repne") || !gstricmp(temp_p, "repnz") || !gstricmp(temp_p, "repz") || !gstricmp(temp_p, "repe") || !gstricmp(temp_p, "rep") || !gstricmp(temp_p, "lock"))
{
for(;orig_line[0]!=(char)' ' && orig_line[0]!=(char)'\t' && orig_line[0]!=(char)(char)NULL; orig_line++);
for(;(orig_line[0]==(char)' ' || orig_line[0]==(char)'\t') && orig_line[0]!=(char)(char)NULL; orig_line++);
if(orig_line[0] == (char)NULL) goto fixed_instruction;
return Parseline(orig_line);
}
if(isInstruction(temp_p)==TRUE) // Is there an instruction by that name?
fatal_error("You have entered arguments not possible for the instruction");
if(!gstricmp(temp_p, "db") || !gstricmp(temp_p, "dd") || !gstricmp(temp_p, "dw")) return DataType(orig_line);
if(!gstricmp(temp_p, "times")) return Handletimes(orig_line);
if(temp_p[0]=='[') { Command(orig_line); return instruction; }
if(temp_p[0]=='%') { Preprocessor(orig_line); return instruction; }
// If the instruction wasn't found as dynamic or fixed, then we
// must assume its a label
if(temp_p[strlen(temp_p)-1]==':')
{
temp_p[strlen(temp_p)-1]=(char)(char)NULL;
Addlabel(temp_p, offset);
temp_p[strlen(temp_p)] = ':';
}
else Addlabel(temp_p, offset);
for(;orig_line[0]!=(char)' ' && orig_line[0]!=(char)'\t' && orig_line[0]!=(char)(char)NULL; orig_line++);
for(;(orig_line[0]==(char)' ' || orig_line[0]==(char)'\t') && orig_line[0]!=(char)(char)NULL; orig_line++);
if(orig_line[0]==(char)(char)NULL)
{
instruction.length = 0;
return instruction;
}
return Parseline(orig_line);
}
// By now, we have found the instruction in our database, now to assemble it
// with operands etc..
// Does the instruction need the 32bit overrides?
if((parm1_evaluated == EVALUATE_IMM32 || parm1_evaluated == EVALUATE_REG32 || parm2_evaluated == EVALUATE_IMM32 || parm2_evaluated == EVALUATE_REG32 || parm1_evaluated == EVALUATE_EAX || parm2_evaluated == EVALUATE_EAX || Evaluator(parm1)==EVALUATE_REG32 || Evaluator(parm2)==EVALUATE_REG32 || parm1_evaluated == EVALUATE_PTR16_PTR32 || parm2_evaluated == EVALUATE_PTR16_PTR32) && BITS == 16)
{
if(parm1_evaluated!=EVALUATE_CREG && parm2_evaluated!=EVALUATE_CREG)
{
instruction.i[temp_count] = 0x66;
temp_count++;
}
}
if((((parm1_evaluated == EVALUATE_REGM32 || parm2_evaluated == EVALUATE_REGM32 || (find_dyn_instruction.format & FORMAT_REL32)) && address_override_disable == FALSE) && BITS == 16) || address_override_force == TRUE)
{
if(parm1_evaluated!=EVALUATE_CREG && parm2_evaluated!=EVALUATE_CREG)
{
instruction.i[temp_count] = 0x67;
temp_count++;
address_override_force = 0;
}
}
if(!(parm1_evaluated == EVALUATE_IMM32 || parm1_evaluated == EVALUATE_REG32 || parm2_evaluated == EVALUATE_IMM32 || parm2_evaluated == EVALUATE_REG32 || parm1_evaluated == EVALUATE_EAX || parm2_evaluated == EVALUATE_EAX || Evaluator(parm1)==EVALUATE_REG32 || Evaluator(parm2)==EVALUATE_REG32 || parm1_evaluated == EVALUATE_PTR16_PTR32 || parm2_evaluated == EVALUATE_PTR16_PTR32) && BITS == 32)
{
if(parm1_evaluated!=EVALUATE_CREG && parm2_evaluated!=EVALUATE_CREG)
{
instruction.i[temp_count] = 0x66;
temp_count++;
}
}
if((!((parm1_evaluated == EVALUATE_REGM32 || parm2_evaluated == EVALUATE_REGM32 || (find_dyn_instruction.format & FORMAT_REL32)) && address_override_disable == FALSE) && BITS == 32) || address_override_force == TRUE)
{
if(parm1_evaluated!=EVALUATE_CREG && parm2_evaluated!=EVALUATE_CREG)
{
instruction.i[temp_count] = 0x67;
temp_count++;
address_override_force = 0;
}
}
// Now put the opcode in..
instruction.i[temp_count] = find_dyn_instruction.c1;
temp_count++;
if(find_dyn_instruction.opcode_length == 2) { instruction.i[temp_count] = find_dyn_instruction.c2; temp_count++; }
if(find_dyn_instruction.opcode_length == 3) { instruction.i[temp_count] = find_dyn_instruction.c3; temp_count+=2; }
if(find_dyn_instruction.format & FORMAT_REGPLUSOP) // Do we have to add the register to the opcode ?
{
if(parm1_evaluated == EVALUATE_REG8 || parm1_evaluated == EVALUATE_REG16 || parm1_evaluated == EVALUATE_REG32) instruction.i[temp_count-1] += FindRegister(parm1);
if(parm2_evaluated == EVALUATE_REG8 || parm2_evaluated == EVALUATE_REG16 || parm2_evaluated == EVALUATE_REG32) instruction.i[temp_count-1] += FindRegister(parm2);
}
// If we need a MOD-RM byte, then calculate what it is....
// *********************** MOD-RM BYTE CALCULATOR ***************************
if(find_dyn_instruction.format & FORMAT_MODRM)
{
// We cannot have two REGMs for one instruction...
if((parm1_evaluated == EVALUATE_REGM8 || parm1_evaluated == EVALUATE_REGM16) && (parm2_evaluated == EVALUATE_REGM8 || parm2_evaluated == EVALUATE_REGM16))
fatal_error("You cannot have two memory operands per instruction!");
// We cannot have two REGs for one instruction... or can we?
// Yes we can, we'll use the REGM part of the MODRM byte
if(parm1_evaluated == EVALUATE_REG8 && (parm2_evaluated == EVALUATE_REG8 || parm2_evaluated == EVALUATE_REG16))
parm1_evaluated = EVALUATE_REGM8;
if(parm1_evaluated == EVALUATE_REG16 && (parm2_evaluated == EVALUATE_REG8 || parm2_evaluated == EVALUATE_REG16))
parm1_evaluated = EVALUATE_REGM16;
modrm_eval = 0;
temp_modrm = 0;
// Now calculate the MODRM part for the REGM (if applicable)
if(parm1_evaluated == EVALUATE_REGM16 || parm1_evaluated == EVALUATE_REGM8 || parm1_evaluated == EVALUATE_REGM32)
{
modrm_eval = Eval2(parm1, 0, parm1_evaluated);
temp_modrm += FindModRM(modrm_eval);
}
// Now to the registers..
if(parm1_evaluated == EVALUATE_REG8 || parm1_evaluated == EVALUATE_REG16 || parm1_evaluated == EVALUATE_REG32)
{
if(!gstricmp("ax", parm1) || !gstricmp("al", parm1) || !gstricmp("eax", parm1)) temp_modrm |= 0x00;
if(!gstricmp("bx", parm1) || !gstricmp("bl", parm1) || !gstricmp("ebx", parm1)) temp_modrm |= 0x18;
if(!gstricmp("cx", parm1) || !gstricmp("cl", parm1) || !gstricmp("ecx", parm1)) temp_modrm |= 0x08;
if(!gstricmp("dx", parm1) || !gstricmp("dl", parm1) || !gstricmp("edx", parm1)) temp_modrm |= 0x10;
if(!gstricmp("si", parm1) || !gstricmp("dh", parm1) || !gstricmp("esi", parm1)) temp_modrm |= 0x30;
if(!gstricmp("di", parm1) || !gstricmp("bh", parm1) || !gstricmp("edi", parm1)) temp_modrm |= 0x38;
if(!gstricmp("bp", parm1) || !gstricmp("ch", parm1) || !gstricmp("ebp", parm1)) temp_modrm |= 0x28;
if(!gstricmp("sp", parm1) || !gstricmp("ah", parm1) || !gstricmp("esp", parm1)) temp_modrm |= 0x20;
}
// Now do the REGM part of the MODRM for parameter two (if applicable)
if(parm2_evaluated == EVALUATE_REGM16 || parm2_evaluated == EVALUATE_REGM8 || parm2_evaluated == EVALUATE_REGM32)
{
modrm_eval = Eval2(parm2, 0, parm2_evaluated);
temp_modrm += FindModRM(modrm_eval);
}
// Now do the REGs
if(parm2_evaluated == EVALUATE_REG8 || parm2_evaluated == EVALUATE_REG16 || parm2_evaluated == EVALUATE_REG32)
{
if(!gstricmp("ax", parm2) || !gstricmp("al", parm2) || !gstricmp("eax", parm2)) temp_modrm |= 0x00;
if(!gstricmp("bx", parm2) || !gstricmp("bl", parm2) || !gstricmp("ebx", parm2)) temp_modrm |= 0x18;
if(!gstricmp("cx", parm2) || !gstricmp("cl", parm2) || !gstricmp("ecx", parm2)) temp_modrm |= 0x08;
if(!gstricmp("dx", parm2) || !gstricmp("dl", parm2) || !gstricmp("edx", parm2)) temp_modrm |= 0x10;
if(!gstricmp("si", parm2) || !gstricmp("dh", parm2) || !gstricmp("esi", parm2)) temp_modrm |= 0x30;
if(!gstricmp("di", parm2) || !gstricmp("bh", parm2) || !gstricmp("edi", parm2)) temp_modrm |= 0x38;
if(!gstricmp("bp", parm2) || !gstricmp("ch", parm2) || !gstricmp("ebp", parm2)) temp_modrm |= 0x28;
if(!gstricmp("sp", parm2) || !gstricmp("ah", parm2) || !gstricmp("esp", parm2)) temp_modrm |= 0x20;
}
if(parm1_evaluated == EVALUATE_SREG)
temp_modrm += SegmentRegister(parm1);
if(parm2_evaluated == EVALUATE_SREG)
temp_modrm += SegmentRegister(parm2);
if(parm1_evaluated == EVALUATE_CREG)
temp_modrm += ControlRegister(parm1);
if(parm2_evaluated == EVALUATE_CREG)
temp_modrm += ControlRegister(parm2);
if(parm1_evaluated == EVALUATE_DREG)
temp_modrm += DebugRegister(parm1);
if(parm2_evaluated == EVALUATE_DREG)
temp_modrm += DebugRegister(parm2);
// Add the initial modrm byte to the calculated one
temp_modrm += find_dyn_instruction.initial_modrm;
instruction.i[temp_count] = temp_modrm; // put it into the instruction
temp_count++; // Increase our instruction size count
// Get any displacement that might exist (REGM only)
if((modrm_eval & MODRM_FORMAT_DISP8) || (modrm_eval & MODRM_FORMAT_DISP16) || (modrm_eval & MODRM_FORMAT_DISP32)) GetDisplacement(parm1, temp_string);
if(((modrm_eval & MODRM_FORMAT_DISP8) || (modrm_eval & MODRM_FORMAT_DISP16) || (modrm_eval & MODRM_FORMAT_DISP32)) && !gstricmp(temp_string, "")) GetDisplacement(parm2, temp_string);
// Put them into the instruction
if(modrm_eval & MODRM_FORMAT_DISP8)
{
temp_char = StringtoChar(temp_string);
instruction.i[temp_count] = temp_char;
temp_count++;
}
else if(modrm_eval & MODRM_FORMAT_DISP16)
{
temp_int = StringtoInt(temp_string);
memcpy(&instruction.i[temp_count], &temp_int, 2);
temp_count+=2;
}
else if(modrm_eval & MODRM_FORMAT_DISP32)
{
temp_long = StringtoLong(temp_string);
memcpy(&instruction.i[temp_count], &temp_long, 4);
temp_count+=4;
}
}
//*************************** MOD-RM BYTE CALCULATOR END *********************************
// Now calculate any parameters that are NOT relative to itself
if(!(find_dyn_instruction.format & FORMAT_REL8 || find_dyn_instruction.format & FORMAT_REL16 || find_dyn_instruction.format & FORMAT_REL32))
{
switch(parm1_evaluated)
{
case EVALUATE_IMM8: temp_char = StringtoChar(parm1);
instruction.i[temp_count] = temp_char;
temp_count++;
break;
case EVALUATE_IMM16: temp_int = StringtoInt(parm1);
memcpy(&instruction.i[temp_count], &temp_int, 2);
temp_count+=2;
break;
case EVALUATE_IMM32: temp_long = StringtoLong(parm1);
memcpy(&instruction.i[temp_count], &temp_long, 4);
temp_count+=4;
break;
case EVALUATE_PTR16_PTR16:
temp_int = (unsigned int)GetOffset(parm1);
memcpy(&instruction.i[temp_count], &temp_int, 2);
temp_count+=2;
temp_int = (unsigned int) GetSegment(parm1);
memcpy(&instruction.i[temp_count], &temp_int, 2);
temp_count+=2;
break;
case EVALUATE_PTR16_PTR32:
temp_long = GetOffset(parm1);
memcpy(&instruction.i[temp_count], &temp_long, 4);
temp_count+=4;
temp_int = GetSegment(parm1);
memcpy(&instruction.i[temp_count], &temp_int, 2);
temp_count+=2;
break;
default: break;
}
switch(parm2_evaluated)
{
case EVALUATE_IMM8: temp_char = StringtoChar(parm2);
instruction.i[temp_count] = temp_char;
temp_count++;
break;
case EVALUATE_IMM16: temp_int = StringtoInt(parm2);
memcpy(&instruction.i[temp_count], &temp_int, 2);
temp_count+=2;
break;
case EVALUATE_IMM32: temp_long = StringtoLong(parm2);
memcpy(&instruction.i[temp_count], &temp_long, 4);
temp_count+=4;
break;
case EVALUATE_PTR16_PTR16:
temp_int = (unsigned int)GetOffset(parm1);
memcpy(&instruction.i[temp_count], &temp_int, 2);
temp_count+=2;
temp_int = (unsigned int) GetSegment(parm1);
memcpy(&instruction.i[temp_count], &temp_int, 2);
temp_count+=2;
break;
case EVALUATE_PTR16_PTR32:
temp_long = GetOffset(parm1);
memcpy(&instruction.i[temp_count], &temp_long, 4);
temp_count+=4;
temp_int = GetSegment(parm1);
memcpy(&instruction.i[temp_count], &temp_int, 2);
temp_count+=2;
break;
default: break;
}
}
// Now add any RELATIVES
if(find_dyn_instruction.format & FORMAT_REL8 || find_dyn_instruction.format & FORMAT_REL16 || find_dyn_instruction.format & FORMAT_REL32)
{
switch(parm1_evaluated)
{
case EVALUATE_IMM8:
temp_char = StringtoChar(parm1);
temp_schar = (offset+temp_count+1) - temp_char;
temp_schar = 0 - temp_schar;
instruction.i[temp_count] = temp_schar;
temp_count++;
break;
case EVALUATE_IMM16: temp_int = StringtoInt(parm1);
temp_sint = (offset+temp_count+2) - temp_int; // relative to end of instruction...
temp_sint = 0 - temp_sint;
memcpy(&instruction.i[temp_count], &temp_sint, 2);
temp_count += 2;
break;
case EVALUATE_IMM32: temp_long = StringtoLong(parm1);
temp_slong = (offset+temp_count+4) - temp_long; // relative to end of instruction...
temp_slong = 0 - temp_slong;
memcpy(&instruction.i[temp_count], &temp_slong, 4);
temp_count += 4;
break;
}
switch(parm2_evaluated)
{
case EVALUATE_IMM8: temp_char = StringtoChar(parm2);
temp_schar = (offset+temp_count+1) - temp_char;
temp_schar = 0 - temp_schar;
instruction.i[temp_count] = temp_schar;
temp_count++;
break;
case EVALUATE_IMM16: temp_int = StringtoInt(parm2);
temp_sint = (offset+temp_count+2) - temp_int; // relative to end of instruction...
temp_sint = 0 - temp_sint;
memcpy(&instruction.i[temp_count], &temp_sint, 2);
temp_count += 2;
break;
case EVALUATE_IMM32: temp_long = StringtoLong(parm2);
temp_slong = (offset+temp_count+4) - temp_long; // relative to end of instruction...
temp_slong = 0 - temp_slong;
memcpy(&instruction.i[temp_count], &temp_slong, 4);
temp_count += 4;
break;
}
}
// Now just return the data
instruction.length = temp_count;
return instruction;
}
//**********************************************
// StringtoInt: Converts a string to an integer.
// Can be a label, equation, decimal, hex, etc..
//**********************************************
unsigned int StringtoInt(char *string)
{
char *endp;
char temp_string[255];
t_label label;
int loop=0;
while((string[0]==' ' || string[0]=='\t') && string[0]!=(char)NULL) if(string[0]==' ' || string[0]=='\t') string++;
for(loop=(strlen(string)-1); loop!=0 && (string[loop]==' ' || string[loop]=='\t'); loop--) if(string[loop] == ' ' || string[loop] == '\t') string[loop]=(char)NULL;
if(!gstricmp(string, "")) return 0;
if(!gstricmp(string, "$")) return (int) offset;
if(string[0]=='-')
{
strcpy(temp_string, string+1);
return 0 - StringtoInt(temp_string);
}
if(Contains(string, '+') || Contains(string, '-') || Contains(string, '*') || Contains(string, '/'))
return (unsigned int) SolveEquation(string);
if(!gstrnicmp(string, "0x", 2))
{
return (unsigned int) strtol(string, &endp, 0);
}
if(string[strlen(string)-1]=='h' && isHex(string))
{
strcpy(temp_string, "0x");
string[strlen(string)-1]=(char)(char)NULL;
strcat(temp_string, string);
string[strlen(string)]='h'; // NOTE: string length has decreased
return (unsigned int) strtol(temp_string, &endp, 0);
}
if(string[0]==39 && string[2]==39) // 'a', 'b', etc
{
return (unsigned int) string[1];
}
if(isdigit(string[0]))
{
return atoi(string);
}
// Not normal number, most probably label..
gstrlwr(string);
label = Findlabel(string);
if(label.active == TRUE) return (int) label.m_offset;
if(pass_number > 1)
fatal_error("Undefined label/identifier");
return 0x1; // Return smallest possible value instead if not found... not 0 to avoid divide by 0
}
//**********************************************
// StringtoChar: Converts a string to an char.
// Can be a label, equation, decimal, hex, etc..
//**********************************************
unsigned char StringtoChar(char *string)
{
char *endp;
char temp_string[255];
t_label label;
int loop=0;
while((string[0]==' ' || string[0]=='\t') && string[0]!=(char)NULL) if(string[0]==' ' || string[0]=='\t') string++;
for(loop=(strlen(string)-1); loop!=0 && (string[loop]==' ' || string[loop]=='\t'); loop--) if(string[loop] == ' ' || string[loop] == '\t') string[loop]=(char)NULL;
if(!gstricmp(string, "")) return 0;
if(!gstricmp(string, "$")) return (char) offset;
if(string[0]=='-')
{
strcpy(temp_string, string+1);
return 0 - StringtoChar(temp_string);
}
if(Contains(string, '+') || Contains(string, '-') || Contains(string, '*') || Contains(string, '/'))
return (unsigned char) SolveEquation(string);
if(!gstrnicmp(string, "0x", 2))
{
return (unsigned char) strtol(string, &endp, 0);
}
if(string[strlen(string)-1]=='h' && isHex(string))
{
strcpy(temp_string, "0x");
string[strlen(string)-1]=(char)(char)NULL;
strcat(temp_string, string);
string[strlen(string)]='h'; // NOTE: string length has decreased
return (unsigned char) strtol(temp_string, &endp, 0);
}
if(string[0]==39 && string[2]==39) // 'a', 'b', etc
{
return string[1];
}
if(isdigit(string[0]))
{
return (unsigned char) atoi(string);
}
// Not normal number, most probably label..
gstrlwr(string);
label = Findlabel(string);
if(label.active == TRUE) return (char) label.m_offset;
if(pass_number > 1)
fatal_error("Undefined label/identifier");
return 0x1; // Return smallest possible value instead if not found... not 0 to avoid divide by 0
}
//**********************************************
// StringtoLong: Converts a string to an long.
// Can be a label, equation, decimal, hex, etc..
//**********************************************
unsigned long StringtoLong(char *string)
{
char *endp;
char temp_string[255];
t_label label;
int loop=0;
while((string[0]==' ' || string[0]=='\t') && string[0]!=(char)NULL) if(string[0]==' ' || string[0]=='\t') string++;
for(loop=(strlen(string)-1); loop!=0 && (string[loop]==' ' || string[loop]=='\t'); loop--) if(string[loop] == ' ' || string[loop] == '\t') string[loop]=(char)NULL;
if(!gstricmp(string, "")) return 0;
if(!gstricmp(string, "$")) return offset;
if(string[0]=='-')
{
strcpy(temp_string, string+1);
return 0 - StringtoLong(temp_string);
}
if(Contains(string, '(') || Contains(string, ')') || Contains(string, '+') || Contains(string, '-') || Contains(string, '*') || Contains(string, '/'))
return SolveEquation(string);
if(!gstrnicmp(string, "0x", 2))
{
return strtol(string, &endp, 0);
}
if(string[strlen(string)-1]=='h' && isHex(string))
{
strcpy(temp_string, "0x");
string[strlen(string)-1]=(char)(char)NULL;
strcat(temp_string, string);
string[strlen(string)]='h'; // NOTE: string length has decreased
return strtol(temp_string, &endp, 0);
}
if(string[0]==39 && string[2]==39) // 'a', 'b', etc
{
return (unsigned long) string[1];
}
if(isdigit(string[0]))
{
return atol(string);
}
// Not normal number, most probably label..
gstrlwr(string);
label = Findlabel(string);
if(label.active == TRUE) return label.m_offset;
if(pass_number > 1)
fatal_error("Undefined label/identifier");
return 0x01; // Return smallest possible value instead if not found... not 0 to avoid divide by 0
}
//**********************************************************
// Evaluator: Evaluates a parameter
// Finds out whether it is an immediate, REGM, pointer, etc.
//**********************************************************
unsigned int Evaluator(char *e_string)
{
unsigned int loop=0, loop2=0, temp=0;
t_label labell;
char temp_string[255], *endp;
unsigned long temp_long=0;
signed long temp_slong = 0;
char temp_bracket_string[255], eval1=0;
// Just make sure that the string isn't (char)NULL, crashes otherwise :-/
if(!e_string) return EVALUATE_NONE;
for(loop=0; e_string[loop]!=(char)(char)NULL && (e_string[loop]==(char)' ' || e_string[loop]==(char)'\t'); loop++);
if(e_string[loop]==(char)(char)NULL) return EVALUATE_ERROR;
loop=0;
while((e_string[0] == ' ' || e_string[0] == '\t') && e_string[0]!=(char)NULL) if(e_string[0]==' ' || e_string[0]=='\t') e_string++;
for(loop=(strlen(e_string)-1); loop!=0 && (e_string[loop]==' ' || e_string[loop]=='\t'); loop--) if(e_string[loop] == ' ' || e_string[loop] == '\t') e_string[loop]=(char)NULL;
if(!gstricmp(e_string, "ax") || !gstricmp(e_string, "bx") || !gstricmp(e_string, "cx") || !gstricmp(e_string, "dx") ||
!gstricmp(e_string, "sp") || !gstricmp(e_string, "bp") || !gstricmp(e_string, "si") || !gstricmp(e_string, "di"))
return EVALUATE_REG16;
if(!gstricmp(e_string, "al") || !gstricmp(e_string, "cl") || !gstricmp(e_string, "dl") || !gstricmp(e_string, "bl") ||
!gstricmp(e_string, "ah") || !gstricmp(e_string, "ch") || !gstricmp(e_string, "dh") || !gstricmp(e_string, "bh"))
return EVALUATE_REG8;
if(!gstricmp(e_string, "eax") || !gstricmp(e_string, "ecx") || !gstricmp(e_string, "edx") || !gstricmp(e_string, "ebx") ||
!gstricmp(e_string, "esp") || !gstricmp(e_string, "ebp") || !gstricmp(e_string, "esi") || !gstricmp(e_string, "edi"))
return EVALUATE_REG32;
if(isSegmentRegister(e_string)==TRUE) return EVALUATE_SREG;
if(isControlRegister(e_string)==TRUE) return EVALUATE_CREG;
if(isDebugRegister(e_string)==TRUE) return EVALUATE_DREG;
if((!gstrnicmp(e_string, "0x", 2) || e_string[strlen(e_string)-1]=='h' || (e_string[0]==39 && e_string[2]==39) || isdigit(e_string[0])) && (Contains(e_string, ':')==FALSE) && isRelativeInstruction(temp_p)==TRUE)
{
temp_long = StringtoLong(e_string);
temp_slong = (offset+5) - temp_long;
temp_slong = 0 - temp_slong;
if(temp_slong>-128 && temp_slong<128) return EVALUATE_IMM8;
else if(temp_slong>-65536 && temp_slong<65536) return EVALUATE_IMM16;
else if(temp_slong<-65536 || temp_slong>65536) return EVALUATE_IMM32;
}
if((e_string[0]=='{' || !gstrnicmp(e_string, "0x", 2) || e_string[strlen(e_string)-1]=='h' || (e_string[0]==39 && e_string[2]==39) || isdigit(e_string[0]) || strchr(e_string, '+') || strchr(e_string, '-') || strchr(e_string, '*') || strchr(e_string, '/')) && ((Contains(e_string, ':')==FALSE) && !strchr(e_string, ']') && !strchr(e_string, '[')))
{
/*temp_long = StringtoLong(e_string);
if(temp_long <=0xFF) return EVALUATE_IMM8;
if(temp_long >=0x100 && temp_long <=0xFFFF) return EVALUATE_IMM16;
if(temp_long >=0x10000) return EVALUATE_IMM32;*/
temp_slong = StringtoLong(e_string);
if(temp_slong >=-127 && temp_slong <=127) return EVALUATE_IMM8;
if(temp_slong >= -65535 && temp_slong <= 65535) return EVALUATE_IMM16;
if(temp_slong < -65535 || temp_slong > 65535) return EVALUATE_IMM32;
return EVALUATE_ERROR;
}
if(e_string[0]=='[')
{
for(loop=1;e_string[loop]!=']' && e_string[loop]!=(char)NULL;loop++)
{
for(loop2=0; e_string[loop]!='+' && e_string[loop]!='*' && e_string[loop]!='-' && e_string[loop]!=(char)NULL && e_string[loop]!=']'; loop2++)
{
temp_string[loop2] = e_string[loop];
loop++;
}
temp_string[loop2] = (char)NULL;
temp = Evaluator(temp_string);
if(temp == EVALUATE_REG8) return EVALUATE_REGM8;
if(temp == EVALUATE_REG16) return EVALUATE_REGM16;
if(temp == EVALUATE_REG32) return EVALUATE_REGM32;
}
if(temp == EVALUATE_IMM8) return EVALUATE_REGM16;
if(temp == EVALUATE_IMM16) return EVALUATE_REGM16;
if(temp == EVALUATE_IMM32) return EVALUATE_REGM32;
}
if(Contains(e_string, ':')==TRUE)
{
// Segment offset something..
int anotherloop = 0;
for(loop=0; e_string[loop]!=':' && e_string[loop]!=(char)(char)NULL; loop++);
loop++;
for(anotherloop=0;e_string[loop]!=(char)(char)NULL; loop++)
{
temp_bracket_string[anotherloop] = e_string[loop];
anotherloop++;
}
temp_bracket_string[anotherloop] = (char)(char)NULL;
eval1 = 0;
eval1 = Evaluator(temp_bracket_string);
if((eval1==EVALUATE_REG8 || eval1==EVALUATE_IMM8) && e_string[0]=='[')
return EVALUATE_REGM8;
if((eval1==EVALUATE_REG16 || eval1==EVALUATE_IMM16) && e_string[0]=='[')
return EVALUATE_REGM16;
if((eval1==EVALUATE_REG32 || eval1==EVALUATE_IMM32) && e_string[0]=='[')
return EVALUATE_REGM32;
if(eval1==EVALUATE_REG8 || eval1==EVALUATE_IMM8)
return EVALUATE_PTR16_PTR16;
if(eval1==EVALUATE_REG16 || eval1==EVALUATE_IMM16)
return EVALUATE_PTR16_PTR16;
if(eval1==EVALUATE_REG32 || eval1==EVALUATE_IMM32)
return EVALUATE_PTR16_PTR32;
return EVALUATE_ERROR;
}
if(labell.active!=FALSE)
{
if(isRelativeInstruction(temp_p)==FALSE)
{
if(labell.m_offset >= 0 && labell.m_offset <=255) return EVALUATE_IMM8;
if(labell.m_offset >=256 && labell.m_offset <=65535) return EVALUATE_IMM16;
if(labell.m_offset >=65536) return EVALUATE_IMM32;
}