and it should count the occurence too like
MOV R0L,R0L occured 2 times
RETI occured 1
BRA.l 0x60 occured 1
So far I have developed code and need help here
#!/usr/local/bin/perl -w
my $filename = 'C:\data1.txt';
my @opcode_var = 0;
my @s_words = 0;
my $fun_name = 0;
my $file_name = 0;
my $output_var = 0;
my $remove_hex = 0;
open(FILE,$filename) or die "Could not read from filename";
my @lines = <FILE>;
chop @lines;
my $word = 0;
foreach my $line(@lines)
{
if ($line =~ /0x*/)
{
chop ($line);
@opcode_var = split(/ /,$line);
if($opcode_var[2] =~ /0x*/)
{
print "$opcode_var[3] $opcode_var[4]\n";
}
else
{
if($opcode_var[2] =~ /0x*/)
{
print "$opcode_var[2] $opcode_var[3]\n";
}
}
}
}
you can copy this code and print the output. Just stuck here. Learning to extract the assembly code from .s file.
It looks like Corona688's script missed one detail; the number of fields at the start of a line beginning with 0x is not a constant 2. This slight modification to his script:
awk '
{ sub(/;.*/, "")
while($1 ~ /^0/) {
$1 = ""
$0 = $0
}
sub(/^[ \r\n\t]*/, "")
print
A[$0]++
}
END { print ""
for(X in A)
print "\"" X "\" appeared " A[X] " times."
}' file.s
(with the sample input your provided) produces the output:
BRA.l 0x60
RETI
MOV R0L,R0L
RETI
MOV R0L,R0L
"MOV R0L,R0L" appeared 2 times.
"BRA.l 0x60" appeared 1 times.
"RETI" appeared 2 times.
which seems to be what was requested.
If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk .