Email: bknpk@hotmail.com Phone: +972-54-7649119
V

 

ASIC/FPGA Design and Verification Out Source Services

A very simple perl script to put an incremental value in binary format.

  1. This site shows many simple perl scripts. The scripts are simple and targeted to help in text editing. They are called from within vim on specified text block (mark a and b). Firing the script is very simple:
    'a,'b !perl binary_counter.pl

    If you need to work on all the file, then there is no need to put any marks. Simply use the file operator:
    :% !perl ~/bin/vim_extract_c_cc_h.pl


  2. The main loop of the scripts waits for line, which are sent from within the vim editor. It uses the function sprintf to convert to binary:
    #!/bin/perl

    $cnt=0;
    while (<STDIN> {
       chomp($_);
       if($_ =~ /(.*)(4'd[0-9])(.*)/) {
          $t1=$1; $t3=$3;
          $bin_cnt=sprintf("%04b", $cnt);
          print("$t1");
          print("\"$bin_cnt\"");
          print("$t3\n");
          $cnt++;
       }
    }#while


  3. The output in my case looks like:
    if (status(12:9) = "0000") $display("State was Idle");
    if (status(12:9) = "0001") $display("State was Ready");
    if (status(12:9) = "0010") $display("State was Ident");
    if (status(12:9) = "0011") $display("State was Stby");
    if (status(12:9) = "0100") $display("State was Tran");
    if (status(12:9) = "0101") $display("State was Data");
    if (status(12:9) = "0110") $display("State was Rcv");
    if (status(12:9) = "0111") $display("State was Prog");
    if (status(12:9) = "1000") $display("State was Dis");


  4. One can use c++ (.cpp file) to work on text from within vim in a similar way. In the following example the string dbg is added to each line:

    1. #include <iostream>
    2. using namespace std;
    3. //g++ -o cin cin.cpp
    4. string input_line;
    5. int main() {
    6.    while(cin) {
    7.       getline(cin, input_line);
    8.       cout << "dbg " << input_line << endl;
    9.    };
    10.    return 0;
    11. }



Home

SD slave with Samsung flash.






Search This Site


Feedback This Site




new pages on this site