16/32 Bit Maths Routines

In the process of developing code for my Plotter project, I have had to write a number of routines for handling 32 bit numbers.

The routines include
Mult16 - multiple two 16bit word values together (giving a 32 bit value)

Divide32 - divides a 32 bit value by a 16bit word, and returns a Word result

Add32 - Add two 32 bit values together

Sub32 - Subtracts a 32 bit value from another 32 bit value

Sqroot - returns the Square Root of a Word Value

SqRoot32 - returns a word value, containing the Square Root of a 32 bit value.


The 32 bit values are help in a 4 byte data table, e.g.

Declare DataPointer Temp32P
Declare DataTable Temp32 ; Temporary store for
; intermediate 32 bit results
Reserve 4 ; reserve 4 bytes = 32 bits
End DataTable
Declare Word Result

to use, you need to pass pointers to the value, rather than the value itself.
For example

Temp32P = SetPointer(Temp32)
Result = SqRoot32(Temp32P)

. 16 and 32 Bit RoutinesRoutines for 16 and 32 bit maths.
Use an Include File "16BitMult.txt" statement in your program, so that you can keep the routines in a common library directory.

Tags: