At 10:02 AM -0500 11/11/02, Michael Collins wrote:
Hi,

This may be an ignorant statement since I just joined this list, but I noticed
that the parrot "branch" assembly instruction doesn't work and sometimes causes
a core dump on Linux 2.4.
Oh, it works, you just need to understand it properly. :) This is one of the reasons to use labels in a hand-rolled assembly program. So, let's look at your code, shall we?

------------------
example 1:
set    I0, 16
branch 3
print  "a"
print  "b"
print  "c"
print  "d"
print  "\n"
end
Simple, straightforward, easy. With one mistake, that of counting. Branch offsets are relative to the PC (IC?) at the start of the op. Words used to encode parameters to ops also count. So, lets show this with offsets:

set    I0, 16
branch 3
  0	1

print  "a"
  2	3

print  "b"
  4	5

print  "c"
  6	7

print  "d"
print  "\n"
end

So the branch 3 sets the PC to be the constant "a". Now, we don't inline string constants, so that's really an offset in the current segment's string table. In this case, its the first constant in the constant table, so it has an offset of 0. Which just happens to be the end opcode number. :)

All you need to do is change the offset a bit to point to an opcode and you'll be fine.

Two tools you may find handy are disassemble.pl (which disassembles a bytecode file) and the -t switch to parrot, which traces execution. Both are really useful for diagnosing Odd Problems. (And if this is actual assembly code you're writing, use labels for branch destinations, though real offsets are fine if you're planning on emitting the bytecode directly)
--
Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
[EMAIL PROTECTED] have teddy bears and even
teddy bears get drunk

Reply via email to