V

 

ASIC/FPGA Design and Verification Out Source Services

Run a perl script from vim on a specified text block and convert binary word to hex.

  1. This pages is another example, to many other ones discussed in this site, on how it is easy to start a perl script from vim to do some text manipulations.

  2. In this case there are a few binary words that first need to be concatenated to form a single binary word.
    Next the large word is chopped to 16 bits and converted to hex.

  3. The input format was taken from VHDL code:

    0111100
    0111100
    0111100
    0111100
    0111100
    0111100
    0111100
    0111100
    01111000


  4. The output format was taken from specman e code:

    0x7878F1E3 0xC78F1e3C


  5. The output format from script looks like:

    0111100001111000 -> 7878
    1111000111100011 -> F1E3
    1100011110001111 -> C78F
    0001111000111100 -> 1E3C



  6. The script is shown below:


    #!/bin/perl

    $buf="";
    while (<STDIN>) {
      chomp($_);
      $buf=$_ . $buf;
    }#while
    #convert to hex and print
    $l=length($buf);
    if($l > 16) {
      $j=0;
      for($i = 0; $i < $l; $i += 16) {
        $b=substr($buf, $i, 16);
        $hex = sprintf('%X', oct("0b$b"));
        print("$b -> $hex\n");
        $j++;
      }
    } else {
      $hex = sprintf('%X', oct("0b$buf"));
      print("$buf -> $hex\n");
    }


  7. You may find this page interesting if you have to enumerate a large number of VHDL constants: vhdl enumerate perl script

 


Also available on this project:


Home

Some tips for controlling the xterm title








Search This Site


Feedback This Site




new pages on this site