@srnet,
Well... I think that a solution, or a darn good workaround is needed. But, I respect those members that feel differently. A programmer of your calibre obviously can take a complex example and incorporate that inline to your (existing) code. But complex examples IMO would have much more value to the less experienced if they could incorporate a function-like library.
- Ray
@srnet,
I seem to have hit a nerve about putting links to external routines in the handbooks, so perhaps your suggestion of a maths function tutorial would be a workaround that opened up some opportunities for many programmers to do things to overcome picaxe limitations that they might otherwise think of as being impossible. Those other trig routines etc may also be useful.
I am not an experienced coder but I had no difficulty using allycat's well documented earlier 32/16 bit divide subroutine in my application as below with great results. I am sure the tutorial could enhance this further for general use. (note below that I have re-assigned absolute word and byte registers eg ww1-4 and wb1-4 for more system flexibility)
;*******************************
;DIVIDE - subroutine to divide a 32 bit number by a 16 bit divisor
;Acknowledgement Alan (Allycat) London on Picaxe forum,
;
http://www.picaxeforum.co.uk/showthread.php?21357-Dividing-a-32-bit-number-by-a-16-bit-one/page2
;subroutine takes 52 bytes it typically executes about 180 lines taking around 150ms (at 4 MHz)
; (Testing with code below takes approx 10 msecs on a 18m2 running at 32 mHz)
; Divide ww1.ww2 by ww3 using "Long Division", result will be in ww4
; be careful as this also uses wb2,wb3
symbol numlo = ww1
symbol numhi = ww2
symbol numtop = ww2h ; highest byte of numerator ( = ww2h)
symbol denom = ww3
symbol result = ww4
symbol pass = wb2
symbol carry = wb3 ; Could use bit flag instead (used as zero / non-zero)
divide: ; 52 bytes in subroutine
result = 0 ; Clear result register
carry = 0 ; Clear carry "flag"
for pass = 0 to 16 ; Repeat for each bit position
result = result + result ; Shift left (do BEFORE the final bit is added)
if numhi < denom AND carry = 0 then shift ; Jump if can't subtract
result = result + 1 ; Store the databit
numhi = numhi - denom ; Subtract the denominator
shift:
carry = numtop AND $80 ; Carry flag from numerator top bit
numhi = numhi + numhi ; Shift numerator high left
if numlo > $7FFF then ; Carry bit from low word
numhi = numhi + 1 ; Add carry to high word
endif
numlo = numlo + numlo ; Shift numerator low left
next pass
return