source: dev/BasicCompiler32/NumOpe_Relation.cpp@ 26

Last change on this file since 26 was 3, checked in by dai_9181, 18 years ago
File size: 26.3 KB
RevLine 
[3]1#include "../BasicCompiler_Common/common.h"
2#include "Opcode.h"
3
4BOOL Calc_Relation_PE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
5 //value[sp-2]<=value[sp-1]
6
7 int sp;
8 sp=*pStackPointer;
9
10 int AnswerType;
11 AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
12
13 if(IsRealNumberType(AnswerType)){
14 //////////////
15 // 実数演算
16 //////////////
17
18 if(type_stack[sp-1]==DEF_DOUBLE){
19 //fld qword ptr[esp]
20 op_fld_ptr_esp(DEF_DOUBLE);
21
22 //add esp,8
23 op_add_esp(8);
24 }
25 else if(type_stack[sp-1]==DEF_SINGLE){
26 //fld dword ptr[esp]
27 op_fld_ptr_esp(DEF_SINGLE);
28
29 //add esp,4
30 op_add_esp(4);
31 }
32 else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
33 //64ビット整数値
34
35 //fild qword ptr[esp]
36 op_fld_ptr_esp(DEF_INT64);
37
38 //add esp,8
39 op_add_esp(8);
40 }
41 else{
42 //その他整数型
43
44 //fild dword ptr[esp]
45 op_fld_ptr_esp(DEF_LONG);
46
47 //add esp,4
48 op_add_esp(4);
49 }
50
51 if(type_stack[sp-2]==DEF_DOUBLE){
52 //fld qword ptr[esp]
53 op_fld_ptr_esp(DEF_DOUBLE);
54
55 //add esp,4
56 op_add_esp(4);
57 }
58 else if(type_stack[sp-2]==DEF_SINGLE){
59 //fld dword ptr[esp]
60 op_fld_ptr_esp(DEF_SINGLE);
61 }
62 else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
63 //64ビット整数値
64
65 //fild qword ptr[esp]
66 op_fld_ptr_esp(DEF_INT64);
67
68 //add esp,4
69 op_add_esp(4);
70 }
71 else{
72 //その他整数型
73
74 //fild dword ptr[esp]
75 op_fld_ptr_esp(DEF_LONG);
76 }
77
78 //fcompp
79 OpBuffer[obp++]=(char)0xDE;
80 OpBuffer[obp++]=(char)0xD9;
81
82 //fnstsw ax
83 OpBuffer[obp++]=(char)0xDF;
84 OpBuffer[obp++]=(char)0xE0;
85
86 //mov ecx,0xFFFFFFFF
87 OpBuffer[obp++]=(char)0xB9;
88 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
89 obp+=sizeof(long);
90
91 //test ah,41h
92 OpBuffer[obp++]=(char)0xF6;
93 OpBuffer[obp++]=(char)0xC4;
94 OpBuffer[obp++]=(char)0x41;
95
96 //jne 5
97 OpBuffer[obp++]=(char)0x75;
98 OpBuffer[obp++]=(char)0x02;
99
100 //xor ecx,ecx(ecxを0にする)
101 op_zero_reg(REG_ECX);
102
103 //mov dword ptr[esp],ecx
104 OpBuffer[obp++]=(char)0x89;
105 OpBuffer[obp++]=(char)0x0C;
106 OpBuffer[obp++]=(char)0x24;
107 }
108 else if(Is64Type(AnswerType)){
109 ////////////////////
110 // 64ビット整数演算
111 ////////////////////
112 int TrueSchedule,
113 FalseSchedule1,
114 FalseSchedule2;
115
116 // 第1項 <= 第2項
117
118 //第1項 edx:eax
119 //第2項 ecx:ebx
120 GetStackData_ToRegister(type_stack,sp);
121
122 //cmp edx,ecx
123 OpBuffer[obp++]=(char)0x3B;
124 OpBuffer[obp++]=(char)0xD1;
125
126 if(IsSignedType(type_stack[sp-2])==0&&IsSignedType(type_stack[sp-1])==0){
127 //符号なし演算
128
129 //ja FalseSchedule1(偽へジャンプ)
130 OpBuffer[obp++]=(char)0x77;
131 }
132 else{
133 //符号あり演算
134
135 //jg FalseSchedule1(偽へジャンプ)
136 OpBuffer[obp++]=(char)0x7F;
137 }
138 FalseSchedule1=obp;
139 obp++;
140
141 if(IsSignedType(type_stack[sp-2])==0&&IsSignedType(type_stack[sp-1])==0){
142 //符号なし演算
143
144 //jb TrueSchedule(真へジャンプ)
145 OpBuffer[obp++]=(char)0x72;
146 }
147 else{
148 //符号あり演算
149
150 //jl TrueSchedule(真へジャンプ)
151 OpBuffer[obp++]=(char)0x7C;
152 }
153 TrueSchedule=obp;
154 obp++;
155
156 //cmp eax,ebx
157 OpBuffer[obp++]=(char)0x3B;
158 OpBuffer[obp++]=(char)0xC3;
159
160 //ja FalseSchedule2(偽へジャンプ)
161 OpBuffer[obp++]=(char)0x77;
162 FalseSchedule2=obp;
163 obp++;
164
165 //TrueScheduleのジャンプ先の設定
166 OpBuffer[TrueSchedule]=obp-(TrueSchedule+1);
167
168 //mov eax,0FFFFFFFFh
169 OpBuffer[obp++]=(char)0xB8;
170 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
171 obp+=sizeof(long);
172
173 //jmp 2(演算終了位置へジャンプ)
174 OpBuffer[obp++]=(char)0xEB;
175 OpBuffer[obp++]=(char)0x02;
176
177 //FalseScheduleのジャンプ先の設定
178 OpBuffer[FalseSchedule1]=obp-(FalseSchedule1+1);
179 OpBuffer[FalseSchedule2]=obp-(FalseSchedule2+1);
180
181 //xor eax,eax(eaxを0にする)
182 op_zero_reg(REG_EAX);
183
184 //push eax
185 op_push(REG_EAX);
186 }
187 else{
188 ////////////////////
189 // 32ビット整数演算
190 ////////////////////
191
192 //pop ebx
193 op_pop(REG_EBX);
194
195 //pop eax
196 op_pop(REG_EAX);
197
198 //sub esp,4
199 op_sub_esp(4);
200
201 //mov ecx,0FFFFFFFFh
202 OpBuffer[obp++]=(char)0xB9;
203 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
204 obp+=sizeof(long);
205
206 //cmp eax,ebx
207 OpBuffer[obp++]=(char)0x3B;
208 OpBuffer[obp++]=(char)0xC3;
209
210 if(IsSignedType(type_stack[sp-2])==0&&IsSignedType(type_stack[sp-1])==0){
211 //符号なし演算
212
213 //jbe 5(次のmovを飛び越す)
214 OpBuffer[obp++]=(char)0x76;
215 OpBuffer[obp++]=(char)0x05;
216 }
217 else{
218 //符号あり演算
219
220 //jle 5(次のmovを飛び越す)
221 OpBuffer[obp++]=(char)0x7E;
222 OpBuffer[obp++]=(char)0x05;
223 }
224
225 //mov ecx,0
226 OpBuffer[obp++]=(char)0xB9;
227 *((long *)(OpBuffer+obp))=0;
228 obp+=sizeof(long);
229
230 //mov dword ptr[esp],ecx
231 OpBuffer[obp++]=(char)0x89;
232 OpBuffer[obp++]=(char)0x0C;
233 OpBuffer[obp++]=(char)0x24;
234 }
235
236 sp--;
237 type_stack[sp-1]=DEF_LONG;
238
239 *pStackPointer=sp;
240 return 1;
241}
242
243BOOL Calc_Relation_QE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
244 //value[sp-2]>=value[sp-1]
245
246 int sp;
247 sp=*pStackPointer;
248
249 int AnswerType;
250 AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
251
252 if(IsRealNumberType(AnswerType)){
253 //浮動小数点演算
254 if(type_stack[sp-1]==DEF_DOUBLE){
255 //fld qword ptr[esp]
256 op_fld_ptr_esp(DEF_DOUBLE);
257
258 //add esp,8
259 op_add_esp(8);
260 }
261 else if(type_stack[sp-1]==DEF_SINGLE){
262 //fld dword ptr[esp]
263 op_fld_ptr_esp(DEF_SINGLE);
264
265 //add esp,4
266 op_add_esp(4);
267 }
268 else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
269 //64ビット整数値
270
271 //fild qword ptr[esp]
272 op_fld_ptr_esp(DEF_INT64);
273
274 //add esp,8
275 op_add_esp(8);
276 }
277 else{
278 //その他整数型
279
280 //fild dword ptr[esp]
281 op_fld_ptr_esp(DEF_LONG);
282
283 //add esp,4
284 op_add_esp(4);
285 }
286
287 if(type_stack[sp-2]==DEF_DOUBLE){
288 //fld qword ptr[esp]
289 op_fld_ptr_esp(DEF_DOUBLE);
290
291 //add esp,4
292 op_add_esp(4);
293 }
294 else if(type_stack[sp-2]==DEF_SINGLE){
295 //fld dword ptr[esp]
296 op_fld_ptr_esp(DEF_SINGLE);
297 }
298 else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
299 //64ビット整数値
300
301 //fild qword ptr[esp]
302 op_fld_ptr_esp(DEF_INT64);
303
304 //add esp,4
305 op_add_esp(4);
306 }
307 else{
308 //その他整数型
309
310 //fild dword ptr[esp]
311 op_fld_ptr_esp(DEF_LONG);
312 }
313
314 //fcompp
315 OpBuffer[obp++]=(char)0xDE;
316 OpBuffer[obp++]=(char)0xD9;
317
318 //fnstsw ax
319 OpBuffer[obp++]=(char)0xDF;
320 OpBuffer[obp++]=(char)0xE0;
321
322 //mov ecx,0xFFFFFFFF
323 OpBuffer[obp++]=(char)0xB9;
324 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
325 obp+=sizeof(long);
326
327 //test ah,1
328 OpBuffer[obp++]=(char)0xF6;
329 OpBuffer[obp++]=(char)0xC4;
330 OpBuffer[obp++]=(char)0x01;
331
332 //je 5
333 OpBuffer[obp++]=(char)0x74;
334 OpBuffer[obp++]=(char)0x05;
335
336 //mov ecx,0
337 OpBuffer[obp++]=(char)0xB9;
338 *((long *)(OpBuffer+obp))=0;
339 obp+=sizeof(long);
340
341 //mov dword ptr[esp],ecx
342 OpBuffer[obp++]=(char)0x89;
343 OpBuffer[obp++]=(char)0x0C;
344 OpBuffer[obp++]=(char)0x24;
345 }
346 else if(Is64Type(AnswerType)){
347 ////////////////////
348 // 64ビット整数演算
349 ////////////////////
350 int TrueSchedule,
351 FalseSchedule1,
352 FalseSchedule2;
353
354 // 第1項 >= 第2項
355
356 //第1項 edx:eax
357 //第2項 ecx:ebx
358 GetStackData_ToRegister(type_stack,sp);
359
360 //cmp edx,ecx
361 OpBuffer[obp++]=(char)0x3B;
362 OpBuffer[obp++]=(char)0xD1;
363
364 if(IsSignedType(AnswerType)){
365 //符号あり演算
366
367 //jl FalseSchedule1(偽へジャンプ)
368 OpBuffer[obp++]=(char)0x7C;
369 }
370 else{
371 //符号なし演算
372
373 //jb FalseSchedule1(偽へジャンプ)
374 OpBuffer[obp++]=(char)0x72;
375 }
376 FalseSchedule1=obp;
377 obp++;
378
379 if(IsSignedType(AnswerType)){
380 //符号あり演算
381
382 //jg TrueSchedule(真へジャンプ)
383 OpBuffer[obp++]=(char)0x7F;
384 }
385 else{
386 //符号なし演算
387
388 //ja TrueSchedule(真へジャンプ)
389 OpBuffer[obp++]=(char)0x77;
390 }
391 TrueSchedule=obp;
392 obp++;
393
394 //cmp eax,ebx
395 OpBuffer[obp++]=(char)0x3B;
396 OpBuffer[obp++]=(char)0xC3;
397
398 //jb FalseSchedule2(偽へジャンプ)
399 OpBuffer[obp++]=(char)0x72;
400 FalseSchedule2=obp;
401 obp++;
402
403 //TrueScheduleのジャンプ先の設定
404 OpBuffer[TrueSchedule]=obp-(TrueSchedule+1);
405
406 //mov eax,0FFFFFFFFh
407 OpBuffer[obp++]=(char)0xB8;
408 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
409 obp+=sizeof(long);
410
411 //jmp 2(演算終了位置へジャンプ)
412 OpBuffer[obp++]=(char)0xEB;
413 OpBuffer[obp++]=(char)0x02;
414
415 //FalseScheduleのジャンプ先の設定
416 OpBuffer[FalseSchedule1]=obp-(FalseSchedule1+1);
417 OpBuffer[FalseSchedule2]=obp-(FalseSchedule2+1);
418
419 //xor eax,eax(eaxを0にする)
420 op_zero_reg(REG_EAX);
421
422 //push eax
423 op_push(REG_EAX);
424 }
425 else{
426 ////////////////////
427 // 32ビット整数演算
428 ////////////////////
429
430 //pop ebx
431 op_pop(REG_EBX);
432
433 //pop eax
434 op_pop(REG_EAX);
435
436 //sub esp,4
437 op_sub_esp(4);
438
439 //mov ecx,0FFFFFFFFh
440 OpBuffer[obp++]=(char)0xB9;
441 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
442 obp+=sizeof(long);
443
444 //cmp eax,ebx
445 OpBuffer[obp++]=(char)0x3B;
446 OpBuffer[obp++]=(char)0xC3;
447
448 if(IsSignedType(AnswerType)){
449 //符号あり演算
450
451 //jge 5(次のmovを飛び越す)符号有り
452 OpBuffer[obp++]=(char)0x7D;
453 OpBuffer[obp++]=(char)0x05;
454 }
455 else{
456 //符号なし演算
457
458 //jae 5(次のmovを飛び越す)
459 OpBuffer[obp++]=(char)0x73;
460 OpBuffer[obp++]=(char)0x05;
461 }
462
463 //mov ecx,0
464 OpBuffer[obp++]=(char)0xB9;
465 *((long *)(OpBuffer+obp))=0;
466 obp+=sizeof(long);
467
468 //mov dword ptr[esp],ecx
469 OpBuffer[obp++]=(char)0x89;
470 OpBuffer[obp++]=(char)0x0C;
471 OpBuffer[obp++]=(char)0x24;
472 }
473
474 sp--;
475 type_stack[sp-1]=DEF_LONG;
476
477 *pStackPointer=sp;
478 return 1;
479}
480
481BOOL Calc_Relation_P(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
482 //value[sp-2]<value[sp-1]
483
484 int sp;
485 sp=*pStackPointer;
486
487 int AnswerType;
488 AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
489
490 if(IsRealNumberType(AnswerType)){
491 //////////////
492 // 実数演算
493 //////////////
494
495 if(type_stack[sp-1]==DEF_DOUBLE){
496 //fld qword ptr[esp]
497 op_fld_ptr_esp(DEF_DOUBLE);
498
499 //add esp,8
500 op_add_esp(8);
501 }
502 else if(type_stack[sp-1]==DEF_SINGLE){
503 //fld dword ptr[esp]
504 op_fld_ptr_esp(DEF_SINGLE);
505
506 //add esp,4
507 op_add_esp(4);
508 }
509 else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
510 //64ビット整数値
511
512 //fild qword ptr[esp]
513 op_fld_ptr_esp(DEF_INT64);
514
515 //add esp,8
516 op_add_esp(8);
517 }
518 else{
519 //その他整数型
520
521 //fild dword ptr[esp]
522 op_fld_ptr_esp(DEF_LONG);
523
524 //add esp,4
525 op_add_esp(4);
526 }
527
528 if(type_stack[sp-2]==DEF_DOUBLE){
529 //fld qword ptr[esp]
530 op_fld_ptr_esp(DEF_DOUBLE);
531
532 //add esp,4
533 op_add_esp(4);
534 }
535 else if(type_stack[sp-2]==DEF_SINGLE){
536 //fld dword ptr[esp]
537 op_fld_ptr_esp(DEF_SINGLE);
538 }
539 else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
540 //64ビット整数値
541
542 //fild qword ptr[esp]
543 op_fld_ptr_esp(DEF_INT64);
544
545 //add esp,4
546 op_add_esp(4);
547 }
548 else{
549 //その他整数型
550
551 //fild dword ptr[esp]
552 op_fld_ptr_esp(DEF_LONG);
553 }
554
555 //fcompp
556 OpBuffer[obp++]=(char)0xDE;
557 OpBuffer[obp++]=(char)0xD9;
558
559 //fnstsw ax
560 OpBuffer[obp++]=(char)0xDF;
561 OpBuffer[obp++]=(char)0xE0;
562
563 //mov ecx,0xFFFFFFFF
564 OpBuffer[obp++]=(char)0xB9;
565 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
566 obp+=sizeof(long);
567
568 //test ah,01h
569 OpBuffer[obp++]=(char)0xF6;
570 OpBuffer[obp++]=(char)0xC4;
571 OpBuffer[obp++]=(char)0x01;
572
573 //jne 5
574 OpBuffer[obp++]=(char)0x75;
575 OpBuffer[obp++]=(char)0x05;
576
577 //mov ecx,0
578 OpBuffer[obp++]=(char)0xB9;
579 *((long *)(OpBuffer+obp))=0;
580 obp+=sizeof(long);
581
582 //mov dword ptr[esp],ecx
583 OpBuffer[obp++]=(char)0x89;
584 OpBuffer[obp++]=(char)0x0C;
585 OpBuffer[obp++]=(char)0x24;
586 }
587 else if(Is64Type(AnswerType)){
588 ////////////////////
589 // 64ビット整数演算
590 ////////////////////
591 int TrueSchedule1,
592 TrueSchedule2,
593 FalseSchedule;
594
595 // 第1項 < 第2項
596
597 //第1項 edx:eax
598 //第2項 ecx:ebx
599 GetStackData_ToRegister(type_stack,sp);
600
601 //cmp edx,ecx
602 OpBuffer[obp++]=(char)0x3B;
603 OpBuffer[obp++]=(char)0xD1;
604
605 if(IsSignedType(AnswerType)){
606 //符号あり演算
607
608 //jl TrueSchedule1(真へジャンプ)
609 OpBuffer[obp++]=(char)0x7C;
610 }
611 else{
612 //符号なし演算
613
614 //jb TrueSchedule1(真へジャンプ)
615 OpBuffer[obp++]=(char)0x72;
616 }
617 TrueSchedule1=obp;
618 obp++;
619
620 if(IsSignedType(AnswerType)){
621 //符号あり演算
622
623 //jg FalseSchedule(偽へジャンプ)
624 OpBuffer[obp++]=(char)0x7F;
625 }
626 else{
627 //符号なし演算
628
629 //ja FalseSchedule(偽へジャンプ)
630 OpBuffer[obp++]=(char)0x77;
631 }
632 FalseSchedule=obp;
633 obp++;
634
635 //cmp eax,ebx
636 OpBuffer[obp++]=(char)0x3B;
637 OpBuffer[obp++]=(char)0xC3;
638
639 //jb TrueSchedule2(真へジャンプ)
640 OpBuffer[obp++]=(char)0x72;
641 TrueSchedule2=obp;
642 obp++;
643
644 //FalseScheduleのジャンプ先の設定
645 OpBuffer[FalseSchedule]=obp-(FalseSchedule+1);
646
647 //xor eax,eax(eaxを0にする)
648 op_zero_reg(REG_EAX);
649
650 //jmp 5(演算終了位置へジャンプ)
651 OpBuffer[obp++]=(char)0xEB;
652 OpBuffer[obp++]=(char)0x05;
653
654 //TrueScheduleのジャンプ先の設定
655 OpBuffer[TrueSchedule1]=obp-(TrueSchedule1+1);
656 OpBuffer[TrueSchedule2]=obp-(TrueSchedule2+1);
657
658 //mov eax,0FFFFFFFFh
659 OpBuffer[obp++]=(char)0xB8;
660 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
661 obp+=sizeof(long);
662
663 //push eax
664 op_push(REG_EAX);
665 }
666 else{
667 ///////////////////
668 //32ビット整数演算
669 ///////////////////
670
671 //pop ebx
672 op_pop(REG_EBX);
673
674 //pop eax
675 op_pop(REG_EAX);
676
677 //sub esp,4
678 op_sub_esp(4);
679
680 //mov ecx,0FFFFFFFFh
681 OpBuffer[obp++]=(char)0xB9;
682 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
683 obp+=sizeof(long);
684
685 //cmp eax,ebx
686 OpBuffer[obp++]=(char)0x3B;
687 OpBuffer[obp++]=(char)0xC3;
688
689 if(IsSignedType(AnswerType)){
690 //符号あり演算
691
692 //jl 5(次のmovを飛び越す)
693 OpBuffer[obp++]=(char)0x7C;
694 OpBuffer[obp++]=(char)0x05;
695 }
696 else{
697 //符号なし演算
698
699 //jb 5(次のmovを飛び越す)
700 OpBuffer[obp++]=(char)0x72;
701 OpBuffer[obp++]=(char)0x05;
702 }
703
704 //mov ecx,0
705 OpBuffer[obp++]=(char)0xB9;
706 *((long *)(OpBuffer+obp))=0;
707 obp+=sizeof(long);
708
709 //mov dword ptr[esp],ecx
710 OpBuffer[obp++]=(char)0x89;
711 OpBuffer[obp++]=(char)0x0C;
712 OpBuffer[obp++]=(char)0x24;
713 }
714
715 sp--;
716 type_stack[sp-1]=DEF_LONG;
717
718 *pStackPointer=sp;
719 return 1;
720}
721
722BOOL Calc_Relation_Q(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
723 //value[sp-2]>value[sp-1]
724
725 int sp;
726 sp=*pStackPointer;
727
728 int AnswerType;
729 AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
730
731 if(IsRealNumberType(AnswerType)){
732 //////////////
733 // 実数演算
734 //////////////
735
736 if(type_stack[sp-1]==DEF_DOUBLE){
737 //fld qword ptr[esp]
738 op_fld_ptr_esp(DEF_DOUBLE);
739
740 //add esp,8
741 op_add_esp(8);
742 }
743 else if(type_stack[sp-1]==DEF_SINGLE){
744 //fld dword ptr[esp]
745 op_fld_ptr_esp(DEF_SINGLE);
746
747 //add esp,4
748 op_add_esp(4);
749 }
750 else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
751 //64ビット整数値
752
753 //fild qword ptr[esp]
754 op_fld_ptr_esp(DEF_INT64);
755
756 //add esp,8
757 op_add_esp(8);
758 }
759 else{ //Long、DWord
760 //fild dword ptr[esp]
761 op_fld_ptr_esp(DEF_LONG);
762
763 //add esp,4
764 op_add_esp(4);
765 }
766
767 if(type_stack[sp-2]==DEF_DOUBLE){
768 //fld qword ptr[esp]
769 op_fld_ptr_esp(DEF_DOUBLE);
770
771 //add esp,4
772 op_add_esp(4);
773 }
774 else if(type_stack[sp-2]==DEF_SINGLE){
775 //fld dword ptr[esp]
776 op_fld_ptr_esp(DEF_SINGLE);
777 }
778 else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
779 //64ビット整数値
780
781 //fild qword ptr[esp]
782 op_fld_ptr_esp(DEF_INT64);
783
784 //add esp,4
785 op_add_esp(4);
786 }
787 else{ //Long、DWord
788 //fild dword ptr[esp]
789 op_fld_ptr_esp(DEF_LONG);
790 }
791
792 //fcompp
793 OpBuffer[obp++]=(char)0xDE;
794 OpBuffer[obp++]=(char)0xD9;
795
796 //fnstsw ax
797 OpBuffer[obp++]=(char)0xDF;
798 OpBuffer[obp++]=(char)0xE0;
799
800 //mov ecx,0xFFFFFFFF
801 OpBuffer[obp++]=(char)0xB9;
802 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
803 obp+=sizeof(long);
804
805 //test ah,41
806 OpBuffer[obp++]=(char)0xF6;
807 OpBuffer[obp++]=(char)0xC4;
808 OpBuffer[obp++]=(char)0x41;
809
810 //je 5
811 OpBuffer[obp++]=(char)0x74;
812 OpBuffer[obp++]=(char)0x05;
813
814 //mov ecx,0
815 OpBuffer[obp++]=(char)0xB9;
816 *((long *)(OpBuffer+obp))=0;
817 obp+=sizeof(long);
818
819 //mov dword ptr[esp],ecx
820 OpBuffer[obp++]=(char)0x89;
821 OpBuffer[obp++]=(char)0x0C;
822 OpBuffer[obp++]=(char)0x24;
823 }
824 else if(Is64Type(AnswerType)){
825 ////////////////////
826 // 64ビット整数演算
827 ////////////////////
828 int FalseSchedule,
829 TrueSchedule1,
830 TrueSchedule2;
831
832 // 第1項 > 第2項
833
834 //第1項 edx:eax
835 //第2項 ecx:ebx
836 GetStackData_ToRegister(type_stack,sp);
837
838 //cmp edx,ecx
839 OpBuffer[obp++]=(char)0x3B;
840 OpBuffer[obp++]=(char)0xD1;
841
842 if(IsSignedType(AnswerType)){
843 //符号有り
844
845 //jg TrueSchedule1(真へジャンプ)
846 OpBuffer[obp++]=(char)0x7F;
847 }
848 else{
849 //符号無し
850
851 //ja TrueSchedule1(真へジャンプ)
852 OpBuffer[obp++]=(char)0x77;
853 }
854 TrueSchedule1=obp;
855 obp++;
856
857 if(IsSignedType(AnswerType)){
858 //符号有り
859
860 //jl FalseSchedule(偽へジャンプ)
861 OpBuffer[obp++]=(char)0x7C;
862 }
863 else{
864 //符号無し
865
866 //jb FalseSchedule(偽へジャンプ)
867 OpBuffer[obp++]=(char)0x72;
868 }
869 FalseSchedule=obp;
870 obp++;
871
872 //cmp eax,ebx
873 OpBuffer[obp++]=(char)0x3B;
874 OpBuffer[obp++]=(char)0xC3;
875
876 //ja TrueSchedule2(真へジャンプ)
877 OpBuffer[obp++]=(char)0x77;
878 TrueSchedule2=obp;
879 obp++;
880
881 //FalseScheduleのジャンプ先の設定
882 OpBuffer[FalseSchedule]=obp-(FalseSchedule+1);
883
884 //xor eax,eax(eaxを0にする)
885 op_zero_reg(REG_EAX);
886
887 //jmp 5(演算終了位置へジャンプ)
888 OpBuffer[obp++]=(char)0xEB;
889 OpBuffer[obp++]=(char)0x05;
890
891 //TrueScheduleのジャンプ先の設定
892 OpBuffer[TrueSchedule1]=obp-(TrueSchedule1+1);
893 OpBuffer[TrueSchedule2]=obp-(TrueSchedule2+1);
894
895 //mov eax,0FFFFFFFFh
896 OpBuffer[obp++]=(char)0xB8;
897 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
898 obp+=sizeof(long);
899
900 //push eax
901 op_push(REG_EAX);
902 }
903 else{
904 ////////////////////
905 // 32ビット整数演算
906 ////////////////////
907
908 //pop ebx
909 op_pop(REG_EBX);
910
911 //pop eax
912 op_pop(REG_EAX);
913
914 //sub esp,4
915 op_sub_esp(4);
916
917 //mov ecx,0FFFFFFFFh
918 OpBuffer[obp++]=(char)0xB9;
919 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
920 obp+=sizeof(long);
921
922 //cmp eax,ebx
923 OpBuffer[obp++]=(char)0x3B;
924 OpBuffer[obp++]=(char)0xC3;
925
926 if(IsSignedType(AnswerType)){
927 //jg 5(次のmovを飛び越す)
928 OpBuffer[obp++]=(char)0x7F;
929 OpBuffer[obp++]=(char)0x05;
930 }
931 else{
932 //ja 5(次のmovを飛び越す)
933 OpBuffer[obp++]=(char)0x77;
934 OpBuffer[obp++]=(char)0x05;
935 }
936
937 //mov ecx,0
938 OpBuffer[obp++]=(char)0xB9;
939 *((long *)(OpBuffer+obp))=0;
940 obp+=sizeof(long);
941
942 //mov dword ptr[esp],ecx
943 OpBuffer[obp++]=(char)0x89;
944 OpBuffer[obp++]=(char)0x0C;
945 OpBuffer[obp++]=(char)0x24;
946 }
947
948 sp--;
949 type_stack[sp-1]=DEF_LONG;
950
951 *pStackPointer=sp;
952 return 1;
953}
954
955BOOL Calc_Relation_NotEqual(int *type,int *pStackPointer){
956 //value[sp-2]<>value[sp-1]
957
958 int sp;
959 sp=*pStackPointer;
960
961 if(type[sp-2]==DEF_DOUBLE||type[sp-2]==DEF_SINGLE||
962 type[sp-1]==DEF_DOUBLE||type[sp-1]==DEF_SINGLE){
963 //////////////
964 // 実数演算
965 //////////////
966
967 if(type[sp-1]==DEF_DOUBLE){
968 //fld qword ptr[esp]
969 op_fld_ptr_esp(DEF_DOUBLE);
970
971 //add esp,8
972 op_add_esp(8);
973 }
974 else if(type[sp-1]==DEF_SINGLE){
975 //fld dword ptr[esp]
976 op_fld_ptr_esp(DEF_SINGLE);
977
978 //add esp,4
979 op_add_esp(4);
980 }
981 else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
982 //64ビット整数値
983
984 //fild qword ptr[esp]
985 op_fld_ptr_esp(DEF_INT64);
986
987 //add esp,8
988 op_add_esp(8);
989 }
990 else{ //Long、DWord
991 //fild dword ptr[esp]
992 op_fld_ptr_esp(DEF_LONG);
993
994 //add esp,4
995 op_add_esp(4);
996 }
997
998 if(type[sp-2]==DEF_DOUBLE){
999 //fld qword ptr[esp]
1000 op_fld_ptr_esp(DEF_DOUBLE);
1001
1002 //add esp,4
1003 op_add_esp(4);
1004 }
1005 else if(type[sp-2]==DEF_SINGLE){
1006 //fld dword ptr[esp]
1007 op_fld_ptr_esp(DEF_SINGLE);
1008 }
1009 else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
1010 //64ビット整数値
1011
1012 //fild qword ptr[esp]
1013 op_fld_ptr_esp(DEF_INT64);
1014
1015 //add esp,4
1016 op_add_esp(4);
1017 }
1018 else{ //Long、DWord
1019 //fild dword ptr[esp]
1020 op_fld_ptr_esp(DEF_LONG);
1021 }
1022
1023 //fcompp
1024 OpBuffer[obp++]=(char)0xDE;
1025 OpBuffer[obp++]=(char)0xD9;
1026
1027 //fnstsw ax
1028 OpBuffer[obp++]=(char)0xDF;
1029 OpBuffer[obp++]=(char)0xE0;
1030
1031 //mov ecx,0xFFFFFFFF
1032 OpBuffer[obp++]=(char)0xB9;
1033 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
1034 obp+=sizeof(long);
1035
1036 //test ah,40
1037 OpBuffer[obp++]=(char)0xF6;
1038 OpBuffer[obp++]=(char)0xC4;
1039 OpBuffer[obp++]=(char)0x40;
1040
1041 //je 5
1042 OpBuffer[obp++]=(char)0x74;
1043 OpBuffer[obp++]=(char)0x05;
1044
1045 //mov ecx,0
1046 OpBuffer[obp++]=(char)0xB9;
1047 *((long *)(OpBuffer+obp))=0;
1048 obp+=sizeof(long);
1049
1050 //mov dword ptr[esp],ecx
1051 OpBuffer[obp++]=(char)0x89;
1052 OpBuffer[obp++]=(char)0x0C;
1053 OpBuffer[obp++]=(char)0x24;
1054 }
1055 else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD||
1056 type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
1057 ////////////////////
1058 // 64ビット整数演算
1059 ////////////////////
1060 int TrueSchedule1,
1061 TrueSchedule2;
1062
1063 // 第1項 <> 第2項
1064
1065 //第1項 edx:eax
1066 //第2項 ecx:ebx
1067 GetStackData_ToRegister(type,sp);
1068
1069 //cmp eax,ebx
1070 OpBuffer[obp++]=(char)0x3B;
1071 OpBuffer[obp++]=(char)0xC3;
1072
1073 //jnz TrueSchedule1(真へジャンプ)
1074 OpBuffer[obp++]=(char)0x75;
1075 TrueSchedule1=obp;
1076 obp++;
1077
1078 //cmp edx,ecx
1079 OpBuffer[obp++]=(char)0x3B;
1080 OpBuffer[obp++]=(char)0xD1;
1081
1082 //jnz TrueSchedule2(真へジャンプ)
1083 OpBuffer[obp++]=(char)0x75;
1084 TrueSchedule2=obp;
1085 obp++;
1086
1087 //xor eax,eax(eaxを0にする)
1088 op_zero_reg(REG_EAX);
1089
1090 //jmp 5(演算終了位置へジャンプ)
1091 OpBuffer[obp++]=(char)0xEB;
1092 OpBuffer[obp++]=(char)0x05;
1093
1094 //TrueScheduleのジャンプ先の設定
1095 OpBuffer[TrueSchedule1]=obp-(TrueSchedule1+1);
1096 OpBuffer[TrueSchedule2]=obp-(TrueSchedule2+1);
1097
1098 //mov eax,0FFFFFFFFh
1099 OpBuffer[obp++]=(char)0xB8;
1100 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
1101 obp+=sizeof(long);
1102
1103 //push eax
1104 op_push(REG_EAX);
1105 }
1106 else{
1107 ////////////////////
1108 // 32ビット整数演算
1109 ////////////////////
1110
1111 //pop eax
1112 op_pop(REG_EAX);
1113
1114 //pop ebx
1115 op_pop(REG_EBX);
1116
1117 //sub esp,4
1118 op_sub_esp(4);
1119
1120 //xor eax,ebx
1121 OpBuffer[obp++]=(char)0x33;
1122 OpBuffer[obp++]=(char)0xC3;
1123
1124 //jz 5(次のmovを飛び越す)
1125 OpBuffer[obp++]=(char)0x74;
1126 OpBuffer[obp++]=(char)0x05;
1127
1128 //mov eax,0FFFFFFFFh
1129 OpBuffer[obp++]=(char)0xB8;
1130 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
1131 obp+=sizeof(long);
1132
1133 //mov dword ptr[esp],eax
1134 OpBuffer[obp++]=(char)0x89;
1135 OpBuffer[obp++]=(char)0x04;
1136 OpBuffer[obp++]=(char)0x24;
1137 }
1138
1139 sp--;
1140 type[sp-1]=DEF_LONG;
1141
1142 *pStackPointer=sp;
1143 return 1;
1144}
1145
1146BOOL Calc_Relation_Equal(int *type,int *pStackPointer){
1147 //value[sp-2]=value[sp-1]
1148
1149 int sp;
1150 sp=*pStackPointer;
1151
1152 if(type[sp-2]==DEF_DOUBLE||type[sp-2]==DEF_SINGLE||
1153 type[sp-1]==DEF_DOUBLE||type[sp-1]==DEF_SINGLE){
1154 //////////////
1155 // 実数演算
1156 //////////////
1157
1158 if(type[sp-1]==DEF_DOUBLE){
1159 //fld qword ptr[esp]
1160 op_fld_ptr_esp(DEF_DOUBLE);
1161
1162 //add esp,8
1163 op_add_esp(8);
1164 }
1165 else if(type[sp-1]==DEF_SINGLE){
1166 //fld dword ptr[esp]
1167 op_fld_ptr_esp(DEF_SINGLE);
1168
1169 //add esp,4
1170 op_add_esp(4);
1171 }
1172 else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
1173 //64ビット整数値
1174
1175 //fild qword ptr[esp]
1176 op_fld_ptr_esp(DEF_INT64);
1177
1178 //add esp,8
1179 op_add_esp(8);
1180 }
1181 else{ //Long、DWord
1182 //fild dword ptr[esp]
1183 op_fld_ptr_esp(DEF_LONG);
1184
1185 //add esp,4
1186 op_add_esp(4);
1187 }
1188
1189 if(type[sp-2]==DEF_DOUBLE){
1190 //fld qword ptr[esp]
1191 op_fld_ptr_esp(DEF_DOUBLE);
1192
1193 //add esp,4
1194 op_add_esp(4);
1195 }
1196 else if(type[sp-2]==DEF_SINGLE){
1197 //fld dword ptr[esp]
1198 op_fld_ptr_esp(DEF_SINGLE);
1199 }
1200 else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
1201 //64ビット整数値
1202
1203 //fild qword ptr[esp]
1204 op_fld_ptr_esp(DEF_INT64);
1205
1206 //add esp,4
1207 op_add_esp(4);
1208 }
1209 else{ //Long、DWord
1210 //fild dword ptr[esp]
1211 op_fld_ptr_esp(DEF_LONG);
1212 }
1213
1214 //fcompp
1215 OpBuffer[obp++]=(char)0xDE;
1216 OpBuffer[obp++]=(char)0xD9;
1217
1218 //fnstsw ax
1219 OpBuffer[obp++]=(char)0xDF;
1220 OpBuffer[obp++]=(char)0xE0;
1221
1222 //mov ecx,0xFFFFFFFF
1223 OpBuffer[obp++]=(char)0xB9;
1224 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
1225 obp+=sizeof(long);
1226
1227 //test ah,40
1228 OpBuffer[obp++]=(char)0xF6;
1229 OpBuffer[obp++]=(char)0xC4;
1230 OpBuffer[obp++]=(char)0x40;
1231
1232 //jne 5
1233 OpBuffer[obp++]=(char)0x75;
1234 OpBuffer[obp++]=(char)0x05;
1235
1236 //mov ecx,0
1237 OpBuffer[obp++]=(char)0xB9;
1238 *((long *)(OpBuffer+obp))=0;
1239 obp+=sizeof(long);
1240
1241 //mov dword ptr[esp],ecx
1242 OpBuffer[obp++]=(char)0x89;
1243 OpBuffer[obp++]=(char)0x0C;
1244 OpBuffer[obp++]=(char)0x24;
1245 }
1246 else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD||
1247 type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
1248 ////////////////////
1249 // 64ビット整数演算
1250 ////////////////////
1251 int FalseSchedule1,
1252 FalseSchedule2;
1253
1254 // 第1項 == 第2項
1255
1256 //第1項 edx:eax
1257 //第2項 ecx:ebx
1258 GetStackData_ToRegister(type,sp);
1259
1260 //cmp eax,ebx
1261 OpBuffer[obp++]=(char)0x3B;
1262 OpBuffer[obp++]=(char)0xC3;
1263
1264 //jnz FalseSchedule1(偽へジャンプ)
1265 OpBuffer[obp++]=(char)0x75;
1266 FalseSchedule1=obp;
1267 obp++;
1268
1269 //cmp edx,ecx
1270 OpBuffer[obp++]=(char)0x3B;
1271 OpBuffer[obp++]=(char)0xD1;
1272
1273 //jnz FalseSchedule2(偽へジャンプ)
1274 OpBuffer[obp++]=(char)0x75;
1275 FalseSchedule2=obp;
1276 obp++;
1277
1278 //mov eax,0FFFFFFFFh
1279 OpBuffer[obp++]=(char)0xB8;
1280 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
1281 obp+=sizeof(long);
1282
1283 //jmp 2(演算終了位置へジャンプ)
1284 OpBuffer[obp++]=(char)0xEB;
1285 OpBuffer[obp++]=(char)0x02;
1286
1287 //FalseScheduleのジャンプ先の設定
1288 OpBuffer[FalseSchedule1]=obp-(FalseSchedule1+1);
1289 OpBuffer[FalseSchedule2]=obp-(FalseSchedule2+1);
1290
1291 //xor eax,eax(eaxを0にする)
1292 op_zero_reg(REG_EAX);
1293
1294 //push eax
1295 op_push(REG_EAX);
1296 }
1297 else{
1298 ////////////////////
1299 // 32ビット整数演算
1300 ////////////////////
1301
1302 //pop eax
1303 op_pop(REG_EAX);
1304
1305 //pop ebx
1306 op_pop(REG_EBX);
1307
1308 //sub esp,4
1309 op_sub_esp(4);
1310
1311 //xor eax,ebx
1312 OpBuffer[obp++]=(char)0x33;
1313 OpBuffer[obp++]=(char)0xC3;
1314
1315 //jz 5(次のmovを飛び越す)
1316 OpBuffer[obp++]=(char)0x74;
1317 OpBuffer[obp++]=(char)0x05;
1318
1319 //mov eax,0FFFFFFFFh
1320 OpBuffer[obp++]=(char)0xB8;
1321 *((long *)(OpBuffer+obp))=0xFFFFFFFF;
1322 obp+=sizeof(long);
1323
1324 //not eax
1325 OpBuffer[obp++]=(char)0xF7;
1326 OpBuffer[obp++]=(char)0xD0;
1327
1328 //mov dword ptr[esp],eax
1329 OpBuffer[obp++]=(char)0x89;
1330 OpBuffer[obp++]=(char)0x04;
1331 OpBuffer[obp++]=(char)0x24;
1332 }
1333
1334 sp--;
1335 type[sp-1]=DEF_LONG;
1336
1337 *pStackPointer=sp;
1338 return 1;
1339}
Note: See TracBrowser for help on using the repository browser.