After downloading and building Parrot to experiment with this weekend, I decided to set about writing something with the Parrot assembler. The result, a new signature for myself, written to run in Parrot - This signature is based upon my existing signature, which converts a 32 bit binary number, representing the post number, into a decimal number.

However, given the lower level of operations within the Parrot engine, a different algorithm to solve this problem was employed, than that used in my signature previously. The equivalent perl code for the algorithm employed follows the Parrot code.

set S0, "00000000000000000000001001000010" length I0, S0 set I1, 1 set I2, 0 LOOP: dec I0 substr S1, S0, I0, 1 if S1, INC RETURN: mul I1, I1, 2 ge I0, 0, LOOP print I2 print "\n" end INC: add I2, I1 branch RETURN

And then compiling the Parrot assembler to bytecode and executing this:

rob@kathmandu:~/parrot-0.0.10$ perl assemble.pl count.pasm >count.pbc rob@kathmandu:~/parrot-0.0.10$ ./parrot count.pbc 578 rob@kathmandu:~/parrot-0.0.10$

For those unfamiliar with Parrot assembly, the Parrot code above is roughly equivalent to the following Perl code:

$s0 = "00000000000000000000001001000010"; $i0 = length $s0; $i1 = 1; $i2 = 0; while ( $i0 >= 0 ) { --$i0; $s1 = substr( $s0, $i0, 1 ); if ( $s1 eq '1' ) { $i2 += $i1; } $i1 *= 2; }; print $i2, "\n";

From my foray into Parrot assembler this weekend, I must say that I am quite impressed with its development and documentation to date. For those interesting in following my lead and investigating Parrot, I would recommend the following pages and resources:

 

rob@kathmandu:~/parrot-0.0.10$ perl assemble.pl count.pasm >count.pbc ; ./parrot count.pbc


In reply to My new signature - Some assembly required by rob_au

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.