7 $::lbdecor="\$L"; # local label decoration
8 $nmdecor="_"; # external name decoration
13 { my ($opcode,@arg)=@_;
15 # fix hexadecimal constants
16 $arg[0] =~ s/0x([0-9a-f]+)/0$1h/oi if (defined($arg[0]));
17 $arg[1] =~ s/0x([0-9a-f]+)/0$1h/oi if (defined($arg[1]));
20 $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[1]=~/\bxmm[0-7]\b/i);
21 $arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i);
23 &::emit($opcode,@arg);
27 # opcodes not covered by ::generic above, mostly inconsistent namings...
29 sub ::call { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); }
30 sub ::call_ptr { &::emit("call",@_); }
31 sub ::jmp_ptr { &::emit("jmp",@_); }
34 { my($size,$addr,$reg1,$reg2,$idx)=@_;
37 $ret .= "$size PTR " if ($size ne "");
40 # prepend global references with optional underscore
41 $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige;
42 # put address arithmetic expression in parenthesis
43 $addr="($addr)" if ($addr =~ /^.+[\-\+].+$/);
45 if (($addr ne "") && ($addr ne 0))
46 { if ($addr !~ /^-/) { $ret .= "$addr"; }
54 $ret .= "+$reg1" if ($reg1 ne "");
60 $ret =~ s/\+\]/]/; # in case $addr was the only argument
65 sub ::BP { &get_mem("BYTE",@_); }
66 sub ::DWP { &get_mem("DWORD",@_); }
67 sub ::QWP { &get_mem("QWORD",@_); }
75 ECHO MASM version 8.00 or later is strongly recommended.
81 .text\$ SEGMENT PAGE 'CODE'
83 .text\$ SEGMENT ALIGN(64) 'CODE'
89 sub ::function_begin_B
91 my $global=($func !~ /^_/);
92 my $begin="${::lbdecor}_${func}_begin";
94 &::LABEL($func,$global?"$begin":"$nmdecor$func");
95 $func="ALIGN\t16\n".$nmdecor.$func."\tPROC";
97 if ($global) { $func.=" PUBLIC\n${begin}::\n"; }
98 else { $func.=" PRIVATE\n"; }
105 push(@out,"$nmdecor$func ENDP\n");
111 { my $xmmheader=<<___;
120 if (grep {/\b[x]?mm[0-7]\b/i} @out) {
121 grep {s/\.[3-7]86/$xmmheader/} @out;
124 push(@out,".text\$ ENDS\n");
126 if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out)
129 COMM ${nmdecor}OPENSSL_ia32cap_P:DWORD
132 # comment out OPENSSL_ia32cap_P declarations
133 grep {s/(^EXTERN\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out;
136 push (@out,$initseg) if ($initseg);
140 sub ::comment { foreach (@_) { push(@out,"\t; $_\n"); } }
143 { my $l=shift; push(@out,$l.($l=~/^\Q${::lbdecor}\E[0-9]{3}/?":\n":"::\n")); };
147 { push(@out, "EXTERN\t".&::LABEL($_,$nmdecor.$_).":NEAR\n"); }
151 { push(@out,"PUBLIC\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); }
154 { push(@out,("DB\t").join(',',@_)."\n"); }
157 { push(@out,("DD\t").join(',',@_)."\n"); }
160 { push(@out,"ALIGN\t$_[0]\n"); }
164 &::lea($dst,&::DWP($sym));
168 { my $f=$nmdecor.shift;
171 .CRT\$XCU SEGMENT DWORD PUBLIC 'DATA'