27 sub main'asm_init_output { @out=(); }
28 sub main'asm_get_output { return(@out); }
29 sub main'get_labels { return(@labels); }
30 sub main'external_label { push(@labels,@_); }
31 sub main'external_label
35 push(@out, "EXTRN\t_$_:DWORD\n");
41 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
47 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
80 &main'sub("esp",$num*4);
87 &main'add("esp",$num*4);
92 local($size,$addr,$reg1,$reg2,$idx)=@_;
94 local($ret)="$size PTR ";
97 if ($addr =~ /^(.+)\+(.+)$/)
102 elsif ($addr =~ /^[_a-z][_a-z0-9]*$/i)
107 if ($addr =~ /^.+\-.+$/) { $addr="($addr)"; }
109 $reg1="$regs{$reg1}" if defined($regs{$reg1});
110 $reg2="$regs{$reg2}" if defined($regs{$reg2});
111 if (($addr ne "") && ($addr ne 0))
115 else { $post=$addr; }
120 $t="*$idx" if ($idx != 0);
121 $reg1="+".$reg1 if ("$reg1$post" ne "");
122 $ret.="[$reg2$t$reg1$post]";
128 $ret =~ s/\[\]//; # in case $addr was the only argument
132 sub main'mov { &out2("mov",@_); }
133 sub main'movb { &out2("mov",@_); }
134 sub main'and { &out2("and",@_); }
135 sub main'or { &out2("or",@_); }
136 sub main'shl { &out2("shl",@_); }
137 sub main'shr { &out2("shr",@_); }
138 sub main'xor { &out2("xor",@_); }
139 sub main'xorb { &out2("xor",@_); }
140 sub main'add { &out2("add",@_); }
141 sub main'adc { &out2("adc",@_); }
142 sub main'sub { &out2("sub",@_); }
143 sub main'sbb { &out2("sbb",@_); }
144 sub main'rotl { &out2("rol",@_); }
145 sub main'rotr { &out2("ror",@_); }
146 sub main'exch { &out2("xchg",@_); }
147 sub main'cmp { &out2("cmp",@_); }
148 sub main'lea { &out2("lea",@_); }
149 sub main'mul { &out1("mul",@_); }
150 sub main'div { &out1("div",@_); }
151 sub main'dec { &out1("dec",@_); }
152 sub main'inc { &out1("inc",@_); }
153 sub main'jmp { &out1("jmp",@_); }
154 sub main'jmp_ptr { &out1p("jmp",@_); }
155 sub main'je { &out1("je",@_); }
156 sub main'jle { &out1("jle",@_); }
157 sub main'jz { &out1("jz",@_); }
158 sub main'jge { &out1("jge",@_); }
159 sub main'jl { &out1("jl",@_); }
160 sub main'ja { &out1("ja",@_); }
161 sub main'jae { &out1("jae",@_); }
162 sub main'jb { &out1("jb",@_); }
163 sub main'jbe { &out1("jbe",@_); }
164 sub main'jc { &out1("jc",@_); }
165 sub main'jnc { &out1("jnc",@_); }
166 sub main'jnz { &out1("jnz",@_); }
167 sub main'jne { &out1("jne",@_); }
168 sub main'jno { &out1("jno",@_); }
169 sub main'push { &out1("push",@_); $stack+=4; }
170 sub main'pop { &out1("pop",@_); $stack-=4; }
171 sub main'pushf { &out0("pushfd"); $stack+=4; }
172 sub main'popf { &out0("popfd"); $stack-=4; }
173 sub main'bswap { &out1("bswap",@_); &using486(); }
174 sub main'not { &out1("not",@_); }
175 sub main'call { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); }
176 sub main'ret { &out0("ret"); }
177 sub main'nop { &out0("nop"); }
178 sub main'test { &out2("test",@_); }
179 sub main'bt { &out2("bt",@_); }
180 sub main'leave { &out0("leave"); }
181 sub main'cpuid { &out0("DW\t0A20Fh"); }
182 sub main'rdtsc { &out0("DW\t0310Fh"); }
183 sub main'halt { &out0("hlt"); }
184 sub main'movz { &out2("movzx",@_); }
185 sub main'neg { &out1("neg",@_); }
186 sub main'cld { &out0("cld"); }
189 sub main'emms { &out0("emms"); }
190 sub main'movd { &out2("movd",@_); }
191 sub main'movq { &out2("movq",@_); }
192 sub main'movdqu { &out2("movdqu",@_); }
193 sub main'movdqa { &out2("movdqa",@_); }
194 sub main'movdq2q{ &out2("movdq2q",@_); }
195 sub main'movq2dq{ &out2("movq2dq",@_); }
196 sub main'paddq { &out2("paddq",@_); }
197 sub main'pmuludq{ &out2("pmuludq",@_); }
198 sub main'psrlq { &out2("psrlq",@_); }
199 sub main'psllq { &out2("psllq",@_); }
200 sub main'pxor { &out2("pxor",@_); }
201 sub main'por { &out2("por",@_); }
202 sub main'pand { &out2("pand",@_); }
206 local($name,$p1,$p2)=@_;
209 push(@out,"\t$name\t");
214 push(@out,"\t" x $l);
215 push(@out,&conv($p2));
223 push(@out,"\t$name\n");
231 push(@out,"\t$name\t".&conv($p1)."\n");
238 $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
246 grep(s/\.386/\.486/,@out);
257 _TEXT\$ SEGMENT PAGE 'CODE'
263 sub main'function_begin
265 local($func,$extra)=@_;
282 sub main'function_begin_B
284 local($func,$extra)=@_;
295 sub main'function_end
312 sub main'function_end_B
324 sub main'function_end_A
340 # try to detect if SSE2 or MMX extensions were used...
341 if (grep {/xmm[0-7]\s*,/i} @out) {
342 grep {s/\.[3-7]86/\.686\n\t\.XMM/} @out;
344 elsif (grep {/mm[0-7]\s*,/i} @out) {
345 grep {s/\.[3-7]86/\.686\n\t\.MMX/} @out;
347 push(@out,"_TEXT\$ ENDS\n");
355 return(&main'DWP($stack+$num*4,"esp","",0));
360 return(&main'DWP($_[0]*4,"esp","",0));
363 # Should use swtmp, which is above esp. Linix can trash the stack above esp
368 # return(&main'DWP(-(($num+1)*4),"esp","",0));
375 push(@out,"\t; $_\n");
379 sub main'public_label
381 $label{$_[0]}="_$_[0]" if (!defined($label{$_[0]}));
382 push(@out,"PUBLIC\t$label{$_[0]}\n");
387 if (!defined($label{$_[0]}))
389 $label{$_[0]}="\$${label}${_[0]}";
392 return($label{$_[0]});
397 if (!defined($label{$_[0]}))
399 $label{$_[0]}="\$${label}${_[0]}";
402 if ($_[1]!=0 && $_[1]>1)
406 if((defined $_[2]) && ($_[2] == 1))
408 push(@out,"$label{$_[0]}::\n");
410 elsif ($label{$_[0]} !~ /^\$/)
412 push(@out,"$label{$_[0]}\tLABEL PTR\n");
416 push(@out,"$label{$_[0]}:\n");
422 push(@out,"\tDD\t".join(',',@_)."\n");
427 push(@out,"\tALIGN\t$_[0]\n");
435 push(@out,"\t$name\t ".&conv($p1)."\n");
441 &main'lea($dst,&main'DWP($sym));
444 sub main'blindpop { &out1("pop",@_); }
451 .CRT\$XIU SEGMENT DWORD PUBLIC 'DATA'