31 static void standardreg(CPU_INT
*RegTableCount
, CPU_INT reg
, CPU_INT setup_ebp
, FILE *outfp
)
34 if (reg
== RegTableCount
[3])
39 else if (reg
== RegTableCount
[31])
44 else if (reg
== RegTableCount
[4])
49 else if (reg
== RegTableCount
[1])
54 else if (reg
== RegTableCount
[8])
59 else if (reg
== RegTableCount
[9])
64 else if (reg
== RegTableCount
[10])
69 else if (reg
== RegTableCount
[11])
76 fprintf(outfp
,"dword [ebx - %d]");
78 fprintf(outfp
,"; unsuported should not happen it happen :(\n");
82 CPU_INT
ConvertToIA32Process( FILE *outfp
,
83 PMYBrainAnalys pMystart
,
84 PMYBrainAnalys pMyend
, CPU_INT regbits
,
85 CPU_INT HowManyRegInUse
,
86 CPU_INT
*RegTableCount
)
91 CPU_INT setup_ebp
= 0 ; /* 0 = no, 1 = yes */
94 /* Fixme optimze the RegTableCount table */
96 //if (HowManyRegInUse > 9)
97 if (HowManyRegInUse
> 8)
99 setup_ebp
=1; /* we will use ebx as ebp */
100 stack
= HowManyRegInUse
* regbits
;
103 if (RegTableCount
[1]!=0)
105 if (RegTableCount
[3]!=0)
107 if (RegTableCount
[4]!=0)
109 if (RegTableCount
[8]!=0)
111 if (RegTableCount
[9]!=0)
113 if (RegTableCount
[10]!=0)
115 if (RegTableCount
[11]!=0)
117 if (RegTableCount
[31]!=0)
120 if (HowManyRegInUse
!= t
)
122 /* fixme optimze the table or active the frame pointer */
123 setup_ebp
=1; /* we will use ebx as ebp */
124 stack
= HowManyRegInUse
* regbits
;
127 fprintf(outfp
,"BITS 32\n");
128 fprintf(outfp
,"GLOBAL _main\n");
129 fprintf(outfp
,"SECTION .text\n\n");
130 fprintf(outfp
,"; compile with nasm filename.asm -f win32, ld filename.obj -o filename.exe\n\n");
131 fprintf(outfp
,"_main:\n");
133 /* setup a frame pointer */
137 fprintf(outfp
,"\n; Setup frame pointer \n");
138 fprintf(outfp
,"push ebx\n");
139 fprintf(outfp
,"mov ebx,esp\n");
140 fprintf(outfp
,"sub esp, %d ; Alloc %d bytes for reg\n\n",stack
,stack
);
144 fprintf(outfp
,"; Start the program \n");
145 while (pMystart
!=NULL
)
147 /* fixme the line lookup from anaylysing process */
149 /* mov not full implement */
150 if (pMystart
->op
== OP_ANY_mov
)
152 printf("waring OP_ANY_mov are not full implement\n");
154 if ((pMystart
->type
& 8)== 8)
156 /* dst are register */
157 tmp
= stack
- (pMystart
->dst
*regbits
);
159 if ((pMystart
->type
& 2)== 2)
161 fprintf(outfp
,"mov ");
162 standardreg( RegTableCount
,
165 fprintf(outfp
," , ");
166 standardreg( RegTableCount
,
172 if ((pMystart
->type
& 16)== 16)
175 if ((pMystart
->src
== 0) &&
179 fprintf(outfp
,"xor ");
180 standardreg( RegTableCount
,
184 standardreg( RegTableCount
,
191 fprintf(outfp
,"mov ");
192 standardreg( RegTableCount
,
195 fprintf(outfp
,",%llu\n",pMystart
->src
);
197 } /* end "source are imm" */
198 } /* end pMyBrainAnalys->type & 8 */
200 if ((pMystart
->type
& 64)== 64)
202 if ((pMystart
->type
& 2)== 2)
204 /* dest [eax - 0x20], source reg */
206 fprintf(outfp
,"mov dword [");
207 standardreg( RegTableCount
,
210 if (pMystart
->dst_extra
>=0)
211 fprintf(outfp
," +%d], ",pMystart
->dst_extra
);
213 fprintf(outfp
," %d], ",pMystart
->dst_extra
);
215 standardreg( RegTableCount
,
220 if ((pMystart
->type
& 128)== 128)
222 fprintf(outfp
,"mov ");
223 standardreg( RegTableCount
,
226 fprintf(outfp
," , ");
227 standardreg( RegTableCount
,
230 fprintf(outfp
," %d\n",pMystart
->dst_extra
);
241 if (pMystart
->op
== OP_ANY_ret
)
243 if (pMyBrainAnalys
->ptr_next
== NULL
)
247 fprintf(outfp
,"\n; clean up after the frame \n");
248 fprintf(outfp
,"mov esp, ebx\n");
249 fprintf(outfp
,"pop ebx\n");
252 fprintf(outfp
,"ret\n");
254 if (pMystart
== pMyend
)
257 pMystart
= (PMYBrainAnalys
) pMystart
->ptr_next
;