source: dev/BasicCompiler32/Compile_Calc_PushVar.cpp@ 87

Last change on this file since 87 was 66, checked in by dai_9181, 18 years ago

参照型の整数型パラメータに実数を代入すると「内部エラー」になってしまうバグを修正。
参照型の整数型にリテラル値を直接指定すると「内部エラー」になってしまうバグを修正。
バージョンをβ15にした。

File size: 19.2 KB
Line 
1#include "../BasicCompiler_Common/common.h"
2#include "Opcode.h"
3
4void SetReg_RealVariable(int type,RELATIVE_VAR *pRelativeVar){
5 if(pRelativeVar->dwKind==VAR_GLOBAL){
6 if(pRelativeVar->bOffsetOffset){
7 //fld ptr[ecx+offset]
8 op_fld_base_offset(type,REG_ECX,(int)pRelativeVar->offset);
9 obp-=sizeof(long);
10 pobj_GlobalVarSchedule->add();
11 obp+=sizeof(long);
12 }
13 else{
14 //mov ecx,offset
15 op_mov_RV(REG_ECX,(int)pRelativeVar->offset);
16 obp-=sizeof(long);
17 pobj_GlobalVarSchedule->add();
18 obp+=sizeof(long);
19
20 //fld ptr[ecx]
21 op_fld_basereg(type,REG_ECX);
22 }
23 }
24 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
25 SetError(300,NULL,cp);
26 }
27 else if(pRelativeVar->dwKind==VAR_LOCAL){
28 if(pRelativeVar->bOffsetOffset){
29 //fld ptr[ebp+ecx+offset]
30 op_fld_base_offset_ex(type,REG_EBP,REG_ECX,(int)pRelativeVar->offset,USE_OFFSET);
31 obp-=sizeof(long);
32 AddLocalVarAddrSchedule();
33 obp+=sizeof(long);
34 }
35 else{
36 //fld ptr[ebp+offset]
37 op_fld_base_offset(type,REG_EBP,(int)pRelativeVar->offset);
38 obp-=sizeof(long);
39 AddLocalVarAddrSchedule();
40 obp+=sizeof(long);
41 }
42 }
43 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
44 if(pRelativeVar->bOffsetOffset){
45 //add ecx,qword ptr[ebp+offset]
46 op_add_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
47 obp-=sizeof(long);
48 AddLocalVarAddrSchedule();
49 obp+=sizeof(long);
50 }
51 else{
52 //mov ecx,qword ptr[ebp+offset]
53 op_mov_RM(sizeof(long),REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
54 obp-=sizeof(long);
55 AddLocalVarAddrSchedule();
56 obp+=sizeof(long);
57 }
58
59 goto directmem;
60 }
61 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
62directmem:
63 //fld ptr[ecx]
64 op_fld_basereg(type,REG_ECX);
65 }
66}
67void SetReg_WholeVariable(int type,RELATIVE_VAR *pRelativeVar,int reg){
68 int varSize;
69
70 varSize=GetTypeSize(type,-1);
71
72 if(varSize==sizeof(_int64)){
73 //64ビットの場合はedx:eaxにロード
74 if(reg!=REG_EAX){
75 SetError(300,NULL,cp);
76 return;
77 }
78
79 //下位32ビットをeaxにロード
80 SetReg_WholeVariable(DEF_LONG,pRelativeVar,REG_EAX);
81
82 //上位32ビットをedxにロード
83 pRelativeVar->offset+=sizeof(long);
84 SetReg_WholeVariable(DEF_LONG,pRelativeVar,REG_EDX);
85 pRelativeVar->offset-=sizeof(long);
86
87 return;
88 }
89
90 if(pRelativeVar->dwKind==VAR_GLOBAL){
91 if(pRelativeVar->bOffsetOffset){
92 //mov reg, ptr[ecx+offset]
93 op_mov_RM(varSize,reg,REG_ECX,(int)pRelativeVar->offset,MOD_BASE_DISP32);
94 }
95 else{
96 //mov reg, ptr[offset]
97 op_mov_RM(varSize,reg,0,(int)pRelativeVar->offset,MOD_DISP32);
98 }
99 obp-=sizeof(long);
100 pobj_GlobalVarSchedule->add();
101 obp+=sizeof(long);
102 }
103 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
104 if(pRelativeVar->bOffsetOffset){
105 //add ecx,qword ptr[offset]
106 op_add_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);
107 }
108 else{
109 //mov ecx,qword ptr[offset]
110 op_mov_RM(varSize,REG_ECX,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);
111 }
112 obp-=sizeof(long);
113 pobj_GlobalVarSchedule->add();
114 obp+=sizeof(long);
115
116 goto directmem;
117 }
118 else if(pRelativeVar->dwKind==VAR_LOCAL){
119 if(pRelativeVar->bOffsetOffset){
120 //mov reg, ptr[ebp+ecx+offset]
121 op_mov_RM_ex(varSize,reg,REG_EBP,REG_ECX,(int)pRelativeVar->offset,USE_OFFSET);
122 }
123 else{
124 //mov reg, ptr[ebp+offset]
125 op_mov_RM(varSize,reg,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
126 }
127 obp-=sizeof(long);
128 AddLocalVarAddrSchedule();
129 obp+=sizeof(long);
130 }
131 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
132 if(pRelativeVar->bOffsetOffset){
133 //add ecx,qword ptr[ebp+offset]
134 op_add_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
135 }
136 else{
137 //mov ecx,qword ptr[ebp+offset]
138 op_mov_RM(varSize,REG_ECX,REG_EBP,(int)pRelativeVar->offset,MOD_BASE_DISP32);
139 }
140 obp-=sizeof(long);
141 AddLocalVarAddrSchedule();
142 obp+=sizeof(long);
143
144 goto directmem;
145 }
146 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
147directmem:
148 //mov reg, ptr[ecx]
149 op_mov_RM(varSize,reg,REG_ECX,0,MOD_BASE);
150 }
151}
152
153
154
155
156
157void PushDoubleVariable(RELATIVE_VAR *pRelativeVar){
158 if(pRelativeVar->dwKind==VAR_GLOBAL){
159 if(pRelativeVar->bOffsetOffset){
160 //push dword ptr[ecx+offset+sizeof(long)]
161 OpBuffer[obp++]=(char)0xFF;
162 OpBuffer[obp++]=(char)0xB1;
163 *((long *)(OpBuffer+obp))=pRelativeVar->offset+sizeof(long);
164 pobj_GlobalVarSchedule->add();
165 obp+=sizeof(long);
166
167 //push dword ptr[ecx+offset]
168 OpBuffer[obp++]=(char)0xFF;
169 OpBuffer[obp++]=(char)0xB1;
170 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
171 pobj_GlobalVarSchedule->add();
172 obp+=sizeof(long);
173 }
174 else{
175 //push dword ptr[offset+sizeof(long)]
176 OpBuffer[obp++]=(char)0xFF;
177 OpBuffer[obp++]=(char)0x35;
178 *((long *)(OpBuffer+obp))=pRelativeVar->offset+sizeof(long);
179 pobj_GlobalVarSchedule->add();
180 obp+=sizeof(long);
181
182 //push dword ptr[offset]
183 OpBuffer[obp++]=(char)0xFF;
184 OpBuffer[obp++]=(char)0x35;
185 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
186 pobj_GlobalVarSchedule->add();
187 obp+=sizeof(long);
188 }
189 }
190 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
191 SetError(300,NULL,cp);
192 }
193 else if(pRelativeVar->dwKind==VAR_LOCAL){
194 if(pRelativeVar->bOffsetOffset){
195 //add ecx,offset+sizeof(long)
196 OpBuffer[obp++]=(char)0x81;
197 OpBuffer[obp++]=(char)0xC1;
198 *((long *)(OpBuffer+obp))=pRelativeVar->offset+sizeof(long);
199 AddLocalVarAddrSchedule();
200 obp+=sizeof(long);
201
202 //push dword ptr[ebp+ecx]
203 OpBuffer[obp++]=(char)0xFF;
204 OpBuffer[obp++]=(char)0x74;
205 OpBuffer[obp++]=(char)0x0D;
206 OpBuffer[obp++]=(char)0x00;
207
208 //sub ecx,sizeof(long)
209 OpBuffer[obp++]=(char)0x83;
210 OpBuffer[obp++]=(char)0xE9;
211 OpBuffer[obp++]=(char)0x04;
212
213 //push dword ptr[ebp+ecx]
214 OpBuffer[obp++]=(char)0xFF;
215 OpBuffer[obp++]=(char)0x74;
216 OpBuffer[obp++]=(char)0x0D;
217 OpBuffer[obp++]=(char)0x00;
218 }
219 else{
220 //push dword ptr[ebp+offset+sizeof(long)]
221 OpBuffer[obp++]=(char)0xFF;
222 OpBuffer[obp++]=(char)0xB5;
223 *((long *)(OpBuffer+obp))=pRelativeVar->offset+sizeof(long);
224 AddLocalVarAddrSchedule();
225 obp+=sizeof(long);
226
227 //push dword ptr[ebp+offset]
228 OpBuffer[obp++]=(char)0xFF;
229 OpBuffer[obp++]=(char)0xB5;
230 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
231 AddLocalVarAddrSchedule();
232 obp+=sizeof(long);
233 }
234 }
235 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
236 //mov eax,dword ptr[ebp+offset]
237 OpBuffer[obp++]=(char)0x8B;
238 OpBuffer[obp++]=(char)0x85;
239 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
240 AddLocalVarAddrSchedule();
241 obp+=sizeof(long);
242
243 if(pRelativeVar->bOffsetOffset){
244 //add eax,ecx
245 OpBuffer[obp++]=(char)0x03;
246 OpBuffer[obp++]=(char)0xC1;
247 }
248
249 //push dword ptr[eax+sizeof(long)]
250 OpBuffer[obp++]=(char)0xFF;
251 OpBuffer[obp++]=(char)0x70;
252 OpBuffer[obp++]=(char)0x04;
253
254 //push dword ptr[eax]
255 OpBuffer[obp++]=(char)0xFF;
256 OpBuffer[obp++]=(char)0x30;
257 }
258 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
259 //push dword ptr[ecx+sizeof(long)]
260 OpBuffer[obp++]=(char)0xFF;
261 OpBuffer[obp++]=(char)0xB1;
262 *((long *)(OpBuffer+obp))=sizeof(long);
263 obp+=sizeof(long);
264
265 //push dword ptr[ecx]
266 OpBuffer[obp++]=(char)0xFF;
267 OpBuffer[obp++]=(char)0x31;
268 }
269}
270void PushLongVariable(RELATIVE_VAR *pRelativeVar){
271 if(pRelativeVar->dwKind==VAR_GLOBAL){
272 if(pRelativeVar->bOffsetOffset){
273 //push dword ptr[ecx+offset]
274 OpBuffer[obp++]=(char)0xFF;
275 OpBuffer[obp++]=(char)0xB1;
276 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
277 pobj_GlobalVarSchedule->add();
278 obp+=sizeof(long);
279 }
280 else{
281 //push dword ptr[offset]
282 OpBuffer[obp++]=(char)0xFF;
283 OpBuffer[obp++]=(char)0x35;
284 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
285 pobj_GlobalVarSchedule->add();
286 obp+=sizeof(long);
287 }
288 }
289 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
290 //mov eax,dword ptr[offset]
291 op_mov_RM( sizeof(long), REG_EAX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32 );
292 obp-=sizeof(long);
293 pobj_GlobalVarSchedule->add();
294 obp+=sizeof(long);
295
296 if(pRelativeVar->bOffsetOffset){
297 //add eax,ecx
298 OpBuffer[obp++]=(char)0x03;
299 OpBuffer[obp++]=(char)0xC1;
300 }
301
302 //push dword ptr[eax]
303 OpBuffer[obp++]=(char)0xFF;
304 OpBuffer[obp++]=(char)0x30;
305 }
306 else if(pRelativeVar->dwKind==VAR_LOCAL){
307 if(pRelativeVar->bOffsetOffset){
308 //add ecx,offset
309 OpBuffer[obp++]=(char)0x81;
310 OpBuffer[obp++]=(char)0xC1;
311 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
312 AddLocalVarAddrSchedule();
313 obp+=sizeof(long);
314
315 //push dword ptr[ebp+ecx]
316 OpBuffer[obp++]=(char)0xFF;
317 OpBuffer[obp++]=(char)0x74;
318 OpBuffer[obp++]=(char)0x0D;
319 OpBuffer[obp++]=(char)0x00;
320 }
321 else{
322 //push dword ptr[ebp+offset]
323 OpBuffer[obp++]=(char)0xFF;
324 OpBuffer[obp++]=(char)0xB5;
325 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
326 AddLocalVarAddrSchedule();
327 obp+=sizeof(long);
328 }
329 }
330 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
331 //mov eax,dword ptr[ebp+offset]
332 OpBuffer[obp++]=(char)0x8B;
333 OpBuffer[obp++]=(char)0x85;
334 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
335 AddLocalVarAddrSchedule();
336 obp+=sizeof(long);
337
338 if(pRelativeVar->bOffsetOffset){
339 //add eax,ecx
340 OpBuffer[obp++]=(char)0x03;
341 OpBuffer[obp++]=(char)0xC1;
342 }
343
344 //push dword ptr[eax]
345 OpBuffer[obp++]=(char)0xFF;
346 OpBuffer[obp++]=(char)0x30;
347 }
348 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
349 //push dword ptr[ecx]
350 OpBuffer[obp++]=(char)0xFF;
351 OpBuffer[obp++]=(char)0x31;
352 }
353}
354void PushIntegerVariable(RELATIVE_VAR *pRelativeVar){
355 if(pRelativeVar->dwKind==VAR_GLOBAL){
356 if(pRelativeVar->bOffsetOffset){
357 //movsx eax,word ptr[ecx+offset]
358 OpBuffer[obp++]=(char)0x0F;
359 OpBuffer[obp++]=(char)0xBF;
360 OpBuffer[obp++]=(char)0x81;
361 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
362 pobj_GlobalVarSchedule->add();
363 obp+=sizeof(long);
364 }
365 else{
366 //movsx eax,word ptr[offset]
367 OpBuffer[obp++]=(char)0x0F;
368 OpBuffer[obp++]=(char)0xBF;
369 OpBuffer[obp++]=(char)0x05;
370 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
371 pobj_GlobalVarSchedule->add();
372 obp+=sizeof(long);
373 }
374 }
375 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
376 //mov ebx,dword ptr[offset]
377 op_mov_RM( sizeof(long), REG_EBX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32 );
378 obp-=sizeof(long);
379 pobj_GlobalVarSchedule->add();
380 obp+=sizeof(long);
381
382 if(pRelativeVar->bOffsetOffset){
383 //add ebx,ecx
384 OpBuffer[obp++]=(char)0x03;
385 OpBuffer[obp++]=(char)0xD9;
386 }
387
388 //movsx eax,word ptr[ebx]
389 OpBuffer[obp++]=(char)0x0F;
390 OpBuffer[obp++]=(char)0xBF;
391 OpBuffer[obp++]=(char)0x03;
392 }
393 else if(pRelativeVar->dwKind==VAR_LOCAL){
394 if(pRelativeVar->bOffsetOffset){
395 //add ecx,offset
396 OpBuffer[obp++]=(char)0x81;
397 OpBuffer[obp++]=(char)0xC1;
398 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
399 AddLocalVarAddrSchedule();
400 obp+=sizeof(long);
401
402 //movsx eax,word ptr[ebp+ecx]
403 OpBuffer[obp++]=(char)0x0F;
404 OpBuffer[obp++]=(char)0xBF;
405 OpBuffer[obp++]=(char)0x44;
406 OpBuffer[obp++]=(char)0x0D;
407 OpBuffer[obp++]=(char)0x00;
408 }
409 else{
410 //movsx eax,word ptr[ebp+offset]
411 OpBuffer[obp++]=(char)0x0F;
412 OpBuffer[obp++]=(char)0xBF;
413 OpBuffer[obp++]=(char)0x85;
414 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
415 AddLocalVarAddrSchedule();
416 obp+=sizeof(long);
417 }
418 }
419 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
420 //mov ebx,dword ptr[ebp+offset]
421 OpBuffer[obp++]=(char)0x8B;
422 OpBuffer[obp++]=(char)0x9D;
423 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
424 AddLocalVarAddrSchedule();
425 obp+=sizeof(long);
426
427 if(pRelativeVar->bOffsetOffset){
428 //add ebx,ecx
429 OpBuffer[obp++]=(char)0x03;
430 OpBuffer[obp++]=(char)0xD9;
431 }
432
433 //movsx eax,word ptr[ebx]
434 OpBuffer[obp++]=(char)0x0F;
435 OpBuffer[obp++]=(char)0xBF;
436 OpBuffer[obp++]=(char)0x03;
437 }
438 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
439 //movsx eax,word ptr[ecx]
440 OpBuffer[obp++]=(char)0x0F;
441 OpBuffer[obp++]=(char)0xBF;
442 OpBuffer[obp++]=(char)0x01;
443 }
444
445 //push eax
446 op_push(REG_EAX);
447}
448void PushWordVariable(RELATIVE_VAR *pRelativeVar){
449 //xor eax,eax(eaxを0に初期化する)
450 op_zero_reg(REG_EAX);
451
452 if(pRelativeVar->dwKind==VAR_GLOBAL){
453 if(pRelativeVar->bOffsetOffset){
454 //mov ax,word ptr[ecx+offset]
455 OpBuffer[obp++]=(char)0x66;
456 OpBuffer[obp++]=(char)0x8B;
457 OpBuffer[obp++]=(char)0x81;
458 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
459 pobj_GlobalVarSchedule->add();
460 obp+=sizeof(long);
461 }
462 else{
463 //mov ax,word ptr[offset]
464 OpBuffer[obp++]=(char)0x66;
465 OpBuffer[obp++]=(char)0xA1;
466 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
467 pobj_GlobalVarSchedule->add();
468 obp+=sizeof(long);
469 }
470 }
471 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
472 //mov ebx,dword ptr[offset]
473 op_mov_RM( sizeof(long), REG_EBX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32 );
474 obp-=sizeof(long);
475 pobj_GlobalVarSchedule->add();
476 obp+=sizeof(long);
477
478 if(pRelativeVar->bOffsetOffset){
479 //add ebx,ecx
480 OpBuffer[obp++]=(char)0x03;
481 OpBuffer[obp++]=(char)0xD9;
482 }
483
484 //mov ax,word ptr[ebx]
485 OpBuffer[obp++]=(char)0x66;
486 OpBuffer[obp++]=(char)0x8B;
487 OpBuffer[obp++]=(char)0x03;
488 }
489 else if(pRelativeVar->dwKind==VAR_LOCAL){
490 if(pRelativeVar->bOffsetOffset){
491 //add ecx,offset
492 OpBuffer[obp++]=(char)0x81;
493 OpBuffer[obp++]=(char)0xC1;
494 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
495 AddLocalVarAddrSchedule();
496 obp+=sizeof(long);
497
498 //mov ax,word ptr[ebp+ecx]
499 OpBuffer[obp++]=(char)0x66;
500 OpBuffer[obp++]=(char)0x8B;
501 OpBuffer[obp++]=(char)0x44;
502 OpBuffer[obp++]=(char)0x0D;
503 OpBuffer[obp++]=(char)0x00;
504 }
505 else{
506 //mov ax,word ptr[ebp+offset]
507 OpBuffer[obp++]=(char)0x66;
508 OpBuffer[obp++]=(char)0x8B;
509 OpBuffer[obp++]=(char)0x85;
510 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
511 AddLocalVarAddrSchedule();
512 obp+=sizeof(long);
513 }
514 }
515 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
516 //mov ebx,dword ptr[ebp+offset]
517 OpBuffer[obp++]=(char)0x8B;
518 OpBuffer[obp++]=(char)0x9D;
519 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
520 AddLocalVarAddrSchedule();
521 obp+=sizeof(long);
522
523 if(pRelativeVar->bOffsetOffset){
524 //add ebx,ecx
525 OpBuffer[obp++]=(char)0x03;
526 OpBuffer[obp++]=(char)0xD9;
527 }
528
529 //mov ax,word ptr[ebx]
530 OpBuffer[obp++]=(char)0x66;
531 OpBuffer[obp++]=(char)0x8B;
532 OpBuffer[obp++]=(char)0x03;
533 }
534 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
535 //mov ax,word ptr[ecx]
536 OpBuffer[obp++]=(char)0x66;
537 OpBuffer[obp++]=(char)0x8B;
538 OpBuffer[obp++]=(char)0x01;
539 }
540
541 //push eax
542 op_push(REG_EAX);
543}
544void PushCharVariable(RELATIVE_VAR *pRelativeVar){
545 if(pRelativeVar->dwKind==VAR_GLOBAL){
546 if(pRelativeVar->bOffsetOffset){
547 //movsx eax,byte ptr[ecx+offset]
548 OpBuffer[obp++]=(char)0x0F;
549 OpBuffer[obp++]=(char)0xBE;
550 OpBuffer[obp++]=(char)0x81;
551 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
552 pobj_GlobalVarSchedule->add();
553 obp+=sizeof(long);
554 }
555 else{
556 //movsx eax,byte ptr[offset]
557 OpBuffer[obp++]=(char)0x0F;
558 OpBuffer[obp++]=(char)0xBE;
559 OpBuffer[obp++]=(char)0x05;
560 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
561 pobj_GlobalVarSchedule->add();
562 obp+=sizeof(long);
563 }
564 }
565 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
566 //mov ebx,dword ptr[offset]
567 op_mov_RM( sizeof(long), REG_EBX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32 );
568 obp-=sizeof(long);
569 pobj_GlobalVarSchedule->add();
570 obp+=sizeof(long);
571
572 if(pRelativeVar->bOffsetOffset){
573 //add ebx,ecx
574 OpBuffer[obp++]=(char)0x03;
575 OpBuffer[obp++]=(char)0xD9;
576 }
577
578 //movsx eax,byte ptr[ebx]
579 OpBuffer[obp++]=(char)0x0F;
580 OpBuffer[obp++]=(char)0xBE;
581 OpBuffer[obp++]=(char)0x03;
582 }
583 else if(pRelativeVar->dwKind==VAR_LOCAL){
584 if(pRelativeVar->bOffsetOffset){
585 //add ecx,offset
586 OpBuffer[obp++]=(char)0x81;
587 OpBuffer[obp++]=(char)0xC1;
588 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
589 AddLocalVarAddrSchedule();
590 obp+=sizeof(long);
591
592 //movsx eax,byte ptr[ebp+ecx]
593 OpBuffer[obp++]=(char)0x0F;
594 OpBuffer[obp++]=(char)0xBE;
595 OpBuffer[obp++]=(char)0x44;
596 OpBuffer[obp++]=(char)0x0D;
597 OpBuffer[obp++]=(char)0x00;
598 }
599 else{
600 //movsx eax,byte ptr[ebp+offset]
601 OpBuffer[obp++]=(char)0x0F;
602 OpBuffer[obp++]=(char)0xBE;
603 OpBuffer[obp++]=(char)0x85;
604 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
605 AddLocalVarAddrSchedule();
606 obp+=sizeof(long);
607 }
608 }
609 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
610 //mov ebx,dword ptr[ebp+offset]
611 OpBuffer[obp++]=(char)0x8B;
612 OpBuffer[obp++]=(char)0x9D;
613 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
614 AddLocalVarAddrSchedule();
615 obp+=sizeof(long);
616
617 if(pRelativeVar->bOffsetOffset){
618 //add ebx,ecx
619 OpBuffer[obp++]=(char)0x03;
620 OpBuffer[obp++]=(char)0xD9;
621 }
622
623 //movsx eax,byte ptr[ebx]
624 OpBuffer[obp++]=(char)0x0F;
625 OpBuffer[obp++]=(char)0xBE;
626 OpBuffer[obp++]=(char)0x03;
627 }
628 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
629 //movsx eax,byte ptr[ecx]
630 OpBuffer[obp++]=(char)0x0F;
631 OpBuffer[obp++]=(char)0xBE;
632 OpBuffer[obp++]=(char)0x01;
633 }
634
635 //push eax
636 op_push(REG_EAX);
637}
638void PushByteVariable(RELATIVE_VAR *pRelativeVar){
639 //xor eax,eax(eaxを0に初期化する)
640 op_zero_reg(REG_EAX);
641
642 if(pRelativeVar->dwKind==VAR_GLOBAL){
643 if(pRelativeVar->bOffsetOffset){
644 //mov al,byte ptr[ecx+offset]
645 OpBuffer[obp++]=(char)0x8A;
646 OpBuffer[obp++]=(char)0x81;
647 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
648 pobj_GlobalVarSchedule->add();
649 obp+=sizeof(long);
650 }
651 else{
652 //mov al,byte ptr[offset]
653 OpBuffer[obp++]=(char)0xA0;
654 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
655 pobj_GlobalVarSchedule->add();
656 obp+=sizeof(long);
657 }
658 }
659 else if(pRelativeVar->dwKind==VAR_REFGLOBAL){
660 //mov ebx,dword ptr[offset]
661 op_mov_RM( sizeof(long), REG_EBX, REG_NON, (int)pRelativeVar->offset, MOD_DISP32 );
662 obp-=sizeof(long);
663 pobj_GlobalVarSchedule->add();
664 obp+=sizeof(long);
665
666 if(pRelativeVar->bOffsetOffset){
667 //add ebx,ecx
668 OpBuffer[obp++]=(char)0x03;
669 OpBuffer[obp++]=(char)0xD9;
670 }
671
672 //mov al,byte ptr[ebx]
673 OpBuffer[obp++]=(char)0x8A;
674 OpBuffer[obp++]=(char)0x03;
675 }
676 else if(pRelativeVar->dwKind==VAR_LOCAL){
677 if(pRelativeVar->bOffsetOffset){
678 //add ecx,offset
679 OpBuffer[obp++]=(char)0x81;
680 OpBuffer[obp++]=(char)0xC1;
681 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
682 AddLocalVarAddrSchedule();
683 obp+=sizeof(long);
684
685 //mov al,byte ptr[ebp+ecx]
686 OpBuffer[obp++]=(char)0x8A;
687 OpBuffer[obp++]=(char)0x44;
688 OpBuffer[obp++]=(char)0x0D;
689 OpBuffer[obp++]=(char)0x00;
690 }
691 else{
692 //mov al,byte ptr[ebp+offset]
693 OpBuffer[obp++]=(char)0x8A;
694 OpBuffer[obp++]=(char)0x85;
695 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
696 AddLocalVarAddrSchedule();
697 obp+=sizeof(long);
698 }
699 }
700 else if(pRelativeVar->dwKind==VAR_REFLOCAL){
701 //mov ebx,dword ptr[ebp+offset]
702 OpBuffer[obp++]=(char)0x8B;
703 OpBuffer[obp++]=(char)0x9D;
704 *((long *)(OpBuffer+obp))=pRelativeVar->offset;
705 AddLocalVarAddrSchedule();
706 obp+=sizeof(long);
707
708 if(pRelativeVar->bOffsetOffset){
709 //add ebx,ecx
710 OpBuffer[obp++]=(char)0x03;
711 OpBuffer[obp++]=(char)0xD9;
712 }
713
714 //mov al,byte ptr[ebx]
715 OpBuffer[obp++]=(char)0x8A;
716 OpBuffer[obp++]=(char)0x03;
717 }
718 else if(pRelativeVar->dwKind==VAR_DIRECTMEM){
719 //mov al,byte ptr[ecx]
720 OpBuffer[obp++]=(char)0x8A;
721 OpBuffer[obp++]=(char)0x01;
722 }
723
724 //push eax
725 op_push(REG_EAX);
726}
Note: See TracBrowser for help on using the repository browser.