Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

[perl script] print the assembly instruction and count the occurence

$
0
0
Hi,

I have a input file(text file) with the following lines.

Code:

0x000000 0x5a80 0x0060 BRA.l 0x60 ;file:UserCall.s ;function:_user_call_table ;C_sourceLine:24
0x000002 0x1bc5 RETI ;file:UserCall.s ;function:_user_call_table ;C_sourceLine:30
0x000003 0x6840 MOV R0L,R0L ;file:UserCall.s ;function:_user_call_table ;C_sourceLine:31
0x000004 0x1bc5 RETI ;file:UserCall.s ;function:_user_call_table ;C_sourceLine:35
0x000005 0x6840 MOV R0L,R0L ;file:UserCall.s ;function:_user_call_table ;C_sourceLine:36

Expected output is some thing like this :

Code:

BRA.l 0x60
RETI
MOV R0L,R0L
RETI
MOV R0L,R0L


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

Code:

#!/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.

Thank you.

any help is appreciated.

Viewing all articles
Browse latest Browse all 16232

Trending Articles