Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Modulus in Applesoft

881 views
Skip to first unread message

Jayson Smith

unread,
Oct 5, 2004, 6:09:57 PM10/5/04
to
Hi,
I'm having problems using the Modulus operator under Applesoft, or don't
know how to do it. In Integer, if I remember correctly, you could do, E.G.
10 poke 493,x mod 256:poke 494,x/256
and have a memory address poked in. That's just an example. However, doing
print 900 mod 256
in Applesoft produces the result 9000, and I think I just figured out why.
I think it's printing the number 900, then the contents of variable 'mod'
which is 0. So how do you do that in Applesoft?
Thanks.

Michael J. Mahon

unread,
Oct 6, 2004, 3:26:24 AM10/6/04
to
Jayson Smith wrote:

There is no modulus function in Applesoft, though it would be handy.

It is usually done like this:

555 H = INT(V / 256): L = V - H * 256

This sets H to the high byte of V and L to the low byte.

The generalization to other divisors is straightforward.

-michael

Check out parallel computing for 8-bit Apples on my
Home page: http://members.aol.com/MJMahon/

Ben Yates

unread,
Oct 6, 2004, 8:27:23 AM10/6/04
to
"Jayson Smith" <nospamratgu...@nospamplease.bellsouth.ihatespam.net> wrote in message news:<eYE8d.259383$%n4.2...@bignews6.bellsouth.net>...

My Applesoft is rusty, but a MOD such as x = a mod b can be done as:

x = a - int( a / b )* b

Ben

Roger Johnstone

unread,
Oct 8, 2004, 5:54:17 AM10/8/04
to

As mentioned already Applesoft BASIC didn't have a modulus operator, but
the older Integer BASIC did have MOD. It also used # for 'not equal to'
instead of <>, which while it made no real difference to programming I
always though just looked nicer :o)

--
Roger Johnstone, Invercargill, New Zealand
http://vintageware.orcon.net.nz/
________________________________________________________________________
No Silicon Heaven? Preposterous! Where would all the calculators go?

Kryten, from the Red Dwarf episode "The Last Day"

Scott Alfter

unread,
Oct 8, 2004, 1:46:30 PM10/8/04
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In <eYE8d.259383$%n4.2...@bignews6.bellsouth.net> Jayson Smith wrote:

I always used something like this to find x mod y:

abs(x)-int(abs(x)/y)*y

If you know x will always be non-negative, you can leave out the two
occurrences of abs() and speed things up a bit.

_/_
/ v \ Scott Alfter (remove the obvious to send mail)
(IIGS( http://alfter.us/ Top-posting!
\_^_/ rm -rf /bin/laden >What's the most annoying thing on Usenet?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Linux)

iD8DBQFBZtJ2VgTKos01OwkRAtQhAJ91lukSMekfBDUTUfotYQ6ihtld4gCgsyTh
s5LyglT8AdUv0lclgfID/MI=
=0xj2
-----END PGP SIGNATURE-----

0 new messages