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
34 push(@out, "EXTRN\t_$_:DWORD\n");
40 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
46 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
79 &main'sub("esp",$num*4);
86 &main'add("esp",$num*4);
91 local($size,$addr,$reg1,$reg2,$idx)=@_;
93 local($ret)="$size PTR ";
96 if ($addr =~ /^(.+)\+(.+)$/)
101 elsif ($addr =~ /^[_a-z][_a-z0-9]*$/i)
106 if ($addr =~ /^.+\-.+$/) { $addr="($addr)"; }
108 $reg1="$regs{$reg1}" if defined($regs{$reg1});
109 $reg2="$regs{$reg2}" if defined($regs{$reg2});
110 if (($addr ne "") && ($addr ne 0))
114 else { $post=$addr; }
119 $t="*$idx" if ($idx != 0);
120 $reg1="+".$reg1 if ("$reg1$post" ne "");
121 $ret.="[$reg2$t$reg1$post]";
127 $ret =~ s/\[\]//; # in case $addr was the only argument
131 sub main'mov { &out2("mov",@_); }
132 sub main'movb { &out2("mov",@_); }
133 sub main'and { &out2("and",@_); }
134 sub main'or { &out2("or",@_); }
135 sub main'shl { &out2("shl",@_); }
136 sub main'shr { &out2("shr",@_); }
137 sub main'xor { &out2("xor",@_); }
138 sub main'xorb { &out2("xor",@_); }
139 sub main'add { &out2("add",@_); }
140 sub main'adc { &out2("adc",@_); }
141 sub main'sub { &out2("sub",@_); }
142 sub main'sbb { &out2("sbb",@_); }
143 sub main'rotl { &out2("rol",@_); }
144 sub main'rotr { &out2("ror",@_); }
145 sub main'exch { &out2("xchg",@_); }
146 sub main'cmp { &out2("cmp",@_); }
147 sub main'lea { &out2("lea",@_); }
148 sub main'mul { &out1("mul",@_); }
149 sub main'div { &out1("div",@_); }
150 sub main'dec { &out1("dec",@_); }
151 sub main'inc { &out1("inc",@_); }
152 sub main'jmp { &out1("jmp",@_); }
153 sub main'jmp_ptr { &out1p("jmp",@_); }
154 sub main'je { &out1("je",@_); }
155 sub main'jle { &out1("jle",@_); }
156 sub main'jz { &out1("jz",@_); }
157 sub main'jge { &out1("jge",@_); }
158 sub main'jl { &out1("jl",@_); }
159 sub main'ja { &out1("ja",@_); }
160 sub main'jae { &out1("jae",@_); }
161 sub main'jb { &out1("jb",@_); }
162 sub main'jbe { &out1("jbe",@_); }
163 sub main'jc { &out1("jc",@_); }
164 sub main'jnc { &out1("jnc",@_); }
165 sub main'jnz { &out1("jnz",@_); }
166 sub main'jne { &out1("jne",@_); }
167 sub main'jno { &out1("jno",@_); }
168 sub main'push { &out1("push",@_); $stack+=4; }
169 sub main'pop { &out1("pop",@_); $stack-=4; }
170 sub main'pushf { &out0("pushfd"); $stack+=4; }
171 sub main'popf { &out0("popfd"); $stack-=4; }
172 sub main'bswap { &out1("bswap",@_); &using486(); }
173 sub main'not { &out1("not",@_); }
174 sub main'call { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); }
175 sub main'call_ptr { &out1p("call",@_); }
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)=@_;
216 if ($line=~/\bxmm[0-7]\b/i) { $line=~s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i; }
217 push(@out,$line."\n");
224 push(@out,"\t$name\n");
232 push(@out,"\t$name\t".&conv($p1)."\n");
239 $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
247 grep(s/\.386/\.486/,@out);
258 _TEXT\$ SEGMENT PAGE 'CODE'
264 sub main'function_begin
266 local($func,$extra)=@_;
283 sub main'function_begin_B
285 local($func,$extra)=@_;
296 sub main'function_end
313 sub main'function_end_B
325 sub main'function_end_A
341 # try to detect if SSE2 or MMX extensions were used...
342 if (grep {/\b[x]?mm[0-7]\b,/i} @out) {
343 grep {s/\.[3-7]86/\.686\n\t\.XMM/} @out;
345 push(@out,"_TEXT\$ ENDS\n");
353 return(&main'DWP($stack+$num*4,"esp","",0));
358 return(&main'DWP($_[0]*4,"esp","",0));
361 # Should use swtmp, which is above esp. Linix can trash the stack above esp
366 # return(&main'DWP(-(($num+1)*4),"esp","",0));
373 push(@out,"\t; $_\n");
377 sub main'public_label
379 $label{$_[0]}="_$_[0]" if (!defined($label{$_[0]}));
380 push(@out,"PUBLIC\t$label{$_[0]}\n");
385 if (!defined($label{$_[0]}))
387 $label{$_[0]}="\$${label}${_[0]}";
390 return($label{$_[0]});
395 if (!defined($label{$_[0]}))
397 $label{$_[0]}="\$${label}${_[0]}";
400 if ($_[1]!=0 && $_[1]>1)
404 if((defined $_[2]) && ($_[2] == 1))
406 push(@out,"$label{$_[0]}::\n");
408 elsif ($label{$_[0]} !~ /^\$/)
410 push(@out,"$label{$_[0]}\tLABEL PTR\n");
414 push(@out,"$label{$_[0]}:\n");
420 push(@out,"\tDB\t".join(',',@_)."\n");
425 push(@out,"\tDD\t".join(',',@_)."\n");
430 push(@out,"\tALIGN\t$_[0]\n");
438 push(@out,"\t$name\t".&conv($p1)."\n");
444 &main'lea($dst,&main'DWP($sym));
447 sub main'blindpop { &out1("pop",@_); }
454 .CRT\$XCU SEGMENT DWORD PUBLIC 'DATA'