Re: Example assembler code (primes.pasm)

2001-09-20 Thread Michael G Schwern

On Wed, Sep 19, 2001 at 02:49:58PM +0100, Leon Brocard wrote:
 Attached is a cute prime number printer.
 
 It strikes me that we need a central place to put these things - it'd
 really help people get stuck into the lowlevel stuff.

It wouldn't hurt to throw it in as a test.  Probably the most
complicated test case we've got at the moment.



-- 

Michael G. Schwern   [EMAIL PROTECTED]http://www.pobox.com/~schwern/
Perl6 Quality Assurance [EMAIL PROTECTED]   Kwalitee Is Job One
If you see an animal with (-) 100 points and (+) 70 points, would you eat it? 
Hell no, and you should run for your life!
 --Alex Chiu, Immortality Guy



Example assembler code (primes.pasm)

2001-09-19 Thread Leon Brocard

Attached is a cute prime number printer.

It strikes me that we need a central place to put these things - it'd
really help people get stuck into the lowlevel stuff.

How about an examples/ directory in the CVS tree? Alternatively, I
could set up a learning parrot assembler website of some sort,
although Simon's recent article on perl.com was damn good.

Leon

ps the assembler doesn't grok if I5, NEXT4, NEXT3 or comments
on lines which just have labels
-- 
Leon Brocard.http://www.astray.com/
Nanoware...http://www.nanoware.org/

... My name is Inigo Montoya. You killed my father. Prepare to die


# Some simple code to print out the primes up to 100
# Leon Brocard [EMAIL PROTECTED]

# I1 holds the number we're currently checking for primality
set I1, 1
# I2 holds the highest number we want to check for primality
set I2, 100
print   The primes up to 
print   I2
printare:\n
# I1 counts up to I2
REDO:   gt  I1, I2, OVER, NEXT1
NEXT1:
# I3 counts from 2 up to I4 (I1/2)
set I3, 2
set I4, 2
div I4, I1, I4
LOOP:   gt  I3, I4, PRIME, NEXT2
NEXT2:  
# Check if I3 is a factor of I1
mod I5, I1, I3
if_i_ic I5, NEXT4, NEXT3
NEXT3:
# We've found a factor, so it can't be a prime and
# we can skip right out of this loop and to the next
# number
branch  NEXT
NEXT4:  inc I3
branch  LOOP
PRIME:
# We haven't found a factor so it must be a prime
print   I1
print   \n
NEXT:   
# Move on to the next number
inc I1
branch  REDO
OVER:   end



Re: Example assembler code (primes.pasm)

2001-09-19 Thread Simon Cozens

On Wed, Sep 19, 2001 at 02:49:58PM +0100, Leon Brocard wrote:
 How about an examples/ directory in the CVS tree?

I'd rather we didn't do this; I don't want to clutter up Parrot
with auxilliary stuff.

 Alternatively, I
 could set up a learning parrot assembler website of some sort,

This would be better. I'd been thinking about registering parrotcode.org
or something.

 although Simon's recent article on perl.com was damn good.

Thank you. I wasted a lot of time trying to implement a prime factoring
algorithm before realising it couldn't be done with our current range of ops;
I forget exactly why.

-- 
I washed a sock.  Then I put it in the dryer.  When I took it out, it was gone.
-- Steven Wright