Search code examples
divisionz80zx81

Quick divisibility check in ZX81 BASIC


Since many of the Project Euler problems require you to do a divisibility check for quite a number of times, I've been trying to figure out the fastest way to perform this task in ZX81 BASIC.

So far I've compared (N/D) to INT(N/D) to check, whether N is dividable by D or not.
I have been thinking about doing the test in Z80 machine code, I haven't yet figured out how to use the variables in the BASIC in the machine code.

How can it be achieved?


Solution

  • Don't know if RANDOMIZE USR is available in ZX81 but I think it can be used to call routines in assembly. To pass arguments you might need to use POKE to set some fixed memory locations before executing RANDOMIZE USR.

    I remember to find a list of routines implemented in the ROM to support the ZX Basic. I'm sure there are a few to perform floating operation.

    An alternative to floating point is to use fixed point math. It's a lot faster in these kind of situations where there is no math coprocessor.

    You also might find more information in Sinclair User issues. They published some articles related to programming in the ZX Spectrum