32 bit Maths routines

General Chit Chat about Sinclair Computers and their Clones
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

32 bit Maths routines

Post by Moggy »

Does anybody have any idea why commonly used examples of m/l 32 bit maths routines never seem to work on a Zeddy? The four byte result is always totally different to answers given in published examples, does the Zeddy store it's results in memory differently from other Z80 systems? Also how do you extract a USABLE result from the four bytes? Every routine I have seen shows how to do the maths but not how to extract a readable result. I just want to see how far it can manipulate large integers without resorting to the floating point rom which is just as slow when addressed in m/l as when using Basic, (I also want to cut out E-notation) I would be greatful if anyone has a solution to something which has Me totally stumped!!

Thanks in advance moggy
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: 32 bit Maths routines

Post by siggi »

Moggy wrote:commonly used examples of m/l 32 bit maths routines never seem to work on a Zeddy?
First you should list the assembler source of those routines for further analysis ..

I compiled with Z88DK a FAT32 program, which does a lot of 32 bit calculations, and it works with a Zeddy. But you must know the behaviour of a Zeddy to get correct results:

1) in SLOW mode the Zeddy uses the AF' register as NMI-counter. So never use this registers in calculations during SLOW mode
2) The IX and IY register are used by the display routine in SLOW mode. So don't change (or use) them during calculations.

For a simple test you could try to calculate in FAST mode and display the result then is SLOW mode.

HTH Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: 32 bit Maths routines

Post by sirmorris »

Or wait to see zeddy crash when IX/IY is altered..!
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: 32 bit Maths routines

Post by Moggy »

Thanks for prompt answers siggi/sir mo this has given me food for thought.
Once more unto the 32 bit breach dear friends !!!!!!
Cheers moggy
User avatar
Forthretro.new.fr
Posts: 32
Joined: Thu Nov 19, 2009 9:34 pm

Re: 32 bit Maths routines

Post by Forthretro.new.fr »

Hello Moggy

This will not answer your very question, but since you are talking about 32 bit math :roll: , Forth works fine with both :
Double precision math (integer !) and Zeddy.

Of course Forth seems, at first, a very strange language, but believe me, you can do what you want with the
Zeddy using this, helas, forgotten language.

The Fig Forth standard use double precision with the standard double sum, and to store the result you can access later or by Machine Language is very easy.

You have, included, a Forth file zip, that you can use with your emulator (or your Zeddy).

http://forthretro.new.fr/download/math.zip

BTW : In Forth, use the command - CLS - for to clear the screen.

1 - (Forth use the LSB for minus mark)

At the prompt try :

HEX <nl> \ you want hexadecimal

7FFFFF. <NL> \Don't forget the DOT - Forth will understand it is a 32 bit

FFFF. <NL> \ Forth = Polish Notation

D+ <NL> \ 32 bit sum

D. <NL> \ Display the result.

80FFFE

If you want to play with decimal :

DECIMAL <NL> \ you want decimal

8388607. <NL> \Don't forget the DOT
65535. <NL>
D+ <NL>

D. <NL>

8454142

2 - If you want to store the result somewhere ( let suppose adress $7000 and $7002)
I wrote the word DSTORE (Double Store)- So you can do the following :

DECIMAL <NL> \ you want decimal

8388607. <NL> \Don't forget the DOT
65535. <NL>
D+ <NL>

DSTORE <NL> \ $0080 -> ($7002/3)
\ $FFFE -> ($7000/1)

3 - You can use the following words :
a) D/ - It takes the ratio of two double to yield a single

DECIMAL <NL>
80544200. <NL>
805442. <NL>
D/ <NL>

. <NL> \ A DOT only since it is a single

100 \ or use SSTORE $0064 -> ($7002/3)

b) D*S - Multiplies a double times a single to yield a double

DECIMAL <NL>
575236. <NL>
215 <NL> \Without the DOT, for Forth to understand it is a single
D*S <NL>

D. <NL> \ D. (D-Dot) print a double on the SCR
\ or use the command DSTORE as in ex 2

123675740

c) D/S - Divides a double by single to yield a double quotient
d) D*/ - Takes a double and multiplies and divide by single, yielding a double ( very useful for scaling)
e) T* - (For UNSIGNED) Multiplies a double times a single to yield a triple precision.
(For to print on the screen, use . (DOT) then D. (D-DOT) or save it on $7000 $7002 $7004 with TSTORE)
f) T/ - (For UNSIGNED) Divides a triple by a single to yield a double
g) U*/ - (For UNSIGNED) Takes a double and multiplie and divide by a single yielding a double.


All the above comes from an old FORTH DIMENSION magazine V05 Number 1 Page 16 - " Double-Precision Math Words" by L H Bieman

There is also in other issue, Math with quadruple precision.... :lol: It is funny to see our Zeddy doing it.

I hope it help.

Amicalement Dominique
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: 32 bit Maths routines

Post by Moggy »

Hi Dominique

Many many thanks for this, not only an answer to My question but a new language to learn too!!! If this can run on a real Zeddy it will be great.


Regards moggy
User avatar
Forthretro.new.fr
Posts: 32
Joined: Thu Nov 19, 2009 9:34 pm

Re: 32 bit Maths routines

Post by Forthretro.new.fr »

Bonsoir Moggy,
Yes, I am sure It works on the ZEDDY.

Use the ARTIC Forth compiler (It IS a true FIG Forth compiler
With the 32 bit D+)

http://forthretro.new.fr/download/ZXforthArtic.zip
(Thanks Xavier from Xav Snap)

So the ZX will do the job.

Input the following program :

\\\\\\

HEX <NL>
: 2SWAP ROT >R ROT R> ; <NL> (OK)
: 2OVER >R OVER R> SWAP ; <NL> (OK)
: D- DMINUS D+ ; <NL> (OK)
: D/SIGN 2OVER OVER XOR ; <NL> (OK)
: CONTINU >R >R U/ SWAP DROP 0 R> U/ SWAP DROP R> +- ; <NL> (OK)
: D/ D/SIGN >R DABS DUP 1+ DUP >R U/ SWAP DROP >R DABS R> R> R> CONTINU ; <NL> (OK)
: T* DUP ROT U* >R >R U* 0 R> R> D+ ; <NL> (OK)
: T/ >R R U/ SWAP ROT 0 R U/ SWAP ROT R> U/ SWAP DROP 0 2SWAP SWAP D+ ; <NL> (OK)
: U*/ >R T* R> T/ ; <NL> (OK)
: SA 2DUP XOR >R ABS >R DABS R> R> ; <NL> (OK)
: D*S SA >R T* DROP R> D+- ; <NL> (OK)
: D/S SA >R 0 SWAP T/ R> D+- ; <NL> (OK)
: D*/ >R SA R> DUP ROT XOR >R ABS U*/ R> D+- ; <NL> (OK)
: BIN 2 BASE C! ; <NL> (OK)
: SSTORE 7002 ! ; <NL> (OK)
: DSTORE 7002 ! 7000 ! ; <NL> (OK)
: TSTORE 7004 ! 7002 ! 7000 ! ; <NL> (OK)

\\\\\\

NB : A) Have a look at the keyboard picture for ! or @ command .
B) I choose $7000 / $7004 as adress to store the 32 bit result.

But you can choose another adress.
The top of the compiler must be around $6500 ...
Take care, no adress under $6500/6600...

E) You have BIN include. BIN do the job as DECIMAL and HEX. (Example :
HEX <NL>
1FFFFF. <NL>
5EFA2. <NL>
D+ <NL>
BIN <NL>
D. <NL>
----------
1001011110111110100001 (OK)
Have fun
Dominique

Ooops.

For D- we use DMINUS.

DECIMAL
550000.
150000.
DMINUS \ now 150000 -> -150000
D+
D.
...400000
See how FORTH is easy ! The definition of D- will be :
: D- DMINUS D+ ;
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: 32 bit Maths routines

Post by Moggy »

Hi Dominique

Many thanks for this I will now spend the next 12 hours getting My head round it!!!!


many thanks Regards moggy
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: 32 bit Maths routines

Post by siggi »

Meanwhile I think, that BRAINFUCK is an easier programming language:

http://www.youtube.com/watch?v=OnQobTyqEd0

And Matthias wrote a brainfuck interpreter for the ZX81:

http://www.swatosch.de/zx81/brainfuck.p

For details: see
http://forum.tlienhard.com/phpBB3/viewt ... 75&start=0

:mrgreen:

Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
User avatar
Forthretro.new.fr
Posts: 32
Joined: Thu Nov 19, 2009 9:34 pm

Re: 32 bit Maths routines

Post by Forthretro.new.fr »

Siggi,

To promote the survival of Forth as the more successful HOAX of the past century, is my duty.

http://www.xs4all.nl/~lennartb/forthhoax.txt
Post Reply