3 # Because the bswapl instruction is not supported for old assembers
4 # (it was a new instruction for the 486), I've added .byte xxxx code
13 $align=($main'aout)?"4":"16";
14 $under=($main'aout)?"_":"";
15 $com_start=($main'sol)?"/":"#";
17 sub main'asm_init_output { @out=(); }
18 sub main'asm_get_output { return(@out); }
19 sub main'get_labels { return(@labels); }
20 sub main'external_label { push(@labels,@_); }
50 %regs=( 'eax', '%eax',
73 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
79 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
85 local($addr,$reg1,$reg2,$idx)=@_;
88 $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
89 $reg1="$regs{$reg1}" if defined($regs{$reg1});
90 $reg2="$regs{$reg2}" if defined($regs{$reg2});
91 $ret.=$addr if ($addr ne "") && ($addr ne 0);
93 { $ret.="($reg1,$reg2,$idx)"; }
101 return(&main'DWP(@_));
106 # local($addr,$reg1,$reg2,$idx)=@_;
110 # $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
111 # $reg1="$regs{$reg1}" if defined($regs{$reg1});
112 # $reg2="$regs{$reg2}" if defined($regs{$reg2});
113 # $ret.=$addr if ($addr ne "") && ($addr ne 0);
115 # { $ret.="($reg1,$reg2,$idx)"; }
117 # { $ret.="($reg1)" }
121 sub main'mov { &out2("movl",@_); }
122 sub main'movb { &out2("movb",@_); }
123 sub main'and { &out2("andl",@_); }
124 sub main'or { &out2("orl",@_); }
125 sub main'shl { &out2("sall",@_); }
126 sub main'shr { &out2("shrl",@_); }
127 sub main'xor { &out2("xorl",@_); }
128 sub main'xorb { &out2("xorb",@_); }
129 sub main'add { &out2("addl",@_); }
130 sub main'adc { &out2("adcl",@_); }
131 sub main'sub { &out2("subl",@_); }
132 sub main'rotl { &out2("roll",@_); }
133 sub main'rotr { &out2("rorl",@_); }
134 sub main'exch { &out2("xchg",@_); }
135 sub main'cmp { &out2("cmpl",@_); }
136 sub main'lea { &out2("leal",@_); }
137 sub main'mul { &out1("mull",@_); }
138 sub main'div { &out1("divl",@_); }
139 sub main'jmp { &out1("jmp",@_); }
140 sub main'jmp_ptr { &out1p("jmp",@_); }
141 sub main'je { &out1("je",@_); }
142 sub main'jle { &out1("jle",@_); }
143 sub main'jne { &out1("jne",@_); }
144 sub main'jnz { &out1("jnz",@_); }
145 sub main'jz { &out1("jz",@_); }
146 sub main'jge { &out1("jge",@_); }
147 sub main'jl { &out1("jl",@_); }
148 sub main'jb { &out1("jb",@_); }
149 sub main'jc { &out1("jc",@_); }
150 sub main'jnc { &out1("jnc",@_); }
151 sub main'jno { &out1("jno",@_); }
152 sub main'dec { &out1("decl",@_); }
153 sub main'inc { &out1("incl",@_); }
154 sub main'push { &out1("pushl",@_); $stack+=4; }
155 sub main'pop { &out1("popl",@_); $stack-=4; }
156 sub main'bswap { &out1("bswapl",@_); }
157 sub main'not { &out1("notl",@_); }
158 sub main'call { &out1("call",$under.$_[0]); }
159 sub main'ret { &out0("ret"); }
160 sub main'nop { &out0("nop"); }
164 local($name,$p1,$p2)=@_;
166 local(%special)=( "roll",0xD1C0,"rorl",0xD1C8,
167 "rcll",0xD1D0,"rcrl",0xD1D8,
168 "shll",0xD1E0,"shrl",0xD1E8,
171 if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1))
173 $op=$special{$name}|$reg_val{$p1};
174 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
175 $tmp2=sprintf(".byte %d\t",$op &0xff);
181 &main'comment("$name $p2 $p1");
185 push(@out,"\t$name\t");
190 $tmp1=sprintf("\t" x $ll);
192 push(@out,&conv($p1)."\n");
199 local(%special)=("bswapl",0x0FC8);
201 if ((defined($special{$name})) && defined($regs{$p1}))
203 $op=$special{$name}|$reg_val{$p1};
204 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
205 $tmp2=sprintf(".byte %d\t",$op &0xff);
211 &main'comment("$name $p2 $p1");
215 push(@out,"\t$name\t".&conv($p1)."\n");
223 push(@out,"\t$name\t*".&conv($p1)."\n");
228 push(@out,"\t$_[0]\n");
235 # $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
237 $p=$regs{$p} if (defined($regs{$p}));
239 $p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/;
240 $p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/;
256 sub main'function_begin
260 &main'external_label($func);
270 { $tmp=push(@out,"\tTYPE($func,\@function)\n"); }
271 else { $tmp=push(@out,"\t.type\t$func,\@function\n"); }
272 push(@out,"$func:\n");
284 sub main'function_begin_B
286 local($func,$extra)=@_;
288 &main'external_label($func);
298 { push(@out,"\tTYPE($func,\@function)\n"); }
299 else { push(@out,"\t.type $func,\@function\n"); }
300 push(@out,"$func:\n");
304 sub main'function_end
320 { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); }
321 else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); }
322 push(@out,".ident \"$func\"\n");
327 sub main'function_end_A
341 sub main'function_end_B
347 push(@out,".${func}_end:\n");
349 { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); }
350 else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); }
351 push(@out,".ident \"desasm.pl\"\n");
360 return(&main'DWP($stack+$num*4,"esp","",0));
367 &main'sub("esp",$num*4);
374 &main'add("esp",$num*4);
379 return(&main'DWP($_[0]*4,"esp","",0));
382 # Should use swtmp, which is above esp. Linix can trash the stack above esp
387 # return(&main'DWP(-($num+1)*4,"esp","",0));
397 { push(@out,"\t$com_start $_ $com_end\n"); }
403 if (!defined($label{$_[0]}))
405 $label{$_[0]}=".${label}${_[0]}";
408 return($label{$_[0]});
413 if (!defined($label{$_[0]}))
415 $label{$_[0]}=".${label}${_[0]}";
418 push(@out,".align $align\n") if ($_[1] != 0);
419 push(@out,"$label{$_[0]}:\n");
428 push(@out,"\t.long $_[0]\n");