source: dev/BasicCompiler32/Compile_Calc_PushVar.cpp@ 139

Last change on this file since 139 was 97, checked in by dai_9181, 18 years ago

関数の戻り値オブジェクトのメンバ・メソッドを一時オブジェクトを介さずに参照できるようにした。

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