in reply to How can I read assemble code ?

xiaoyafeng:

You might want to try the B::Terse and similar modules. They will show you the bytecode generated by the perl compiler. It's not exactly assembler, but can be very useful in learning some of the fundamentals of the system, much like the native assembly language is very useful in understanding many concepts.

Trivial example:

$ perl -MO=Terse -e 'print "foo!\n"' LISTOP (0x10122248) leave [1] OP (0x10033b50) enter COP (0x100253d8) nextstate LISTOP (0x10122220) print OP (0x1002fcf0) pushmark SVOP (0x100252e0) const [2] PV (0x10010f90) "foo!\n" -e syntax OK

...roboticus

Replies are listed 'Best First'.
Re^2: How can I read assemble code ?
by ysth (Canon) on Oct 12, 2007 at 23:25 UTC
    Terse was replaced with Concise (and now Terse is just a wrapper that calls Concise). Concise, by default shows a bit more info:
    $ perl -MO=Concise -e 'print "foo!\n"' 6 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <@> print vK ->6 3 <0> pushmark s ->4 4 <$> const[PV "foo!\n"] s ->5 -e syntax OK
    Or in execution order, instead of the syntax tree:
    $ perl -MO=Concise,-exec -e 'print "foo!\n"' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v 3 <0> pushmark s 4 <$> const[PV "foo!\n"] s 5 <@> print vK 6 <@> leave[1 ref] vKP/REFC -e syntax OK
    See B::Concise for what all that densely packed info means.