Chapter 9. Parrot Assembly Language

Parrot assembly (PASM) is an assembly language written for Parrot’s virtual CPU. PASM has an interesting mix of features. Because it’s an assembly language, it has many low-level features, such as flow control based on branches and jumps, and direct manipulation of values in the software registers and on the stacks. Basic register operations or branches are generally a single CPU instruction.[28] On the other hand, because it’s designed to implement dynamic high-level languages, it has support for many advanced features, such as lexical and global variables, objects, garbage collection, continuations, coroutines, and much more.

Getting Started

The first step before you start playing with PASM code is to get a copy of the source code and compile it. There is some information on this in Section 2.2.2.1 in Chapter 2. For more information and updates, see http://www.parrotcode.org and the documentation in the distributed code.

The basic steps are:[29]

$ perl Configure.pl
$ make
$ make test

Once you’ve compiled Parrot, create a small test file in the main parrot directory. We’ll call it fjord.pasm.

print "He's pining for the fjords.\n"
end

.pasm is the standard extension for Parrot assembly language source files. Now you can run this file with:

$ ./parrot fjord.pasm

And watch the result of the program execution. Instead of executing the program immediately, you could also compile it to bytecode:

$ ./parrot --output fjord.pbc fjord.pasm

You specify the name ...

Get Perl 6 and Parrot Essentials, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.