Propeller manual pasm division

in Propeller 1
I am having issues with this code example. I cannot get the remainder and' ing and shifting as Dave at parallax advised. If I divide an even number all is good. An odd number does not work and I get gobbelygook.
Here is their code: page 380 of the propeller manual
' Divide x[31..0] by y[15..0] (y[16] must be 0)
' on exit, quotient is in x[15..0] and remainder is in x[31..16]
'
divide shl y,#15 'get divisor into y[30..15]
mov t,#16 'ready for 16 quotient bits
:loop cmpsub x,y wc 'y =< x? Subtract it, quotient bit in c
rcl x,#1 'rotate c into quotient, shift dividend
djnz t,#:loop 'loop until done
divide_ret ret 'quotient in x[15..0],
'remainder in x[31..16]
Here is their code: page 380 of the propeller manual
' Divide x[31..0] by y[15..0] (y[16] must be 0)
' on exit, quotient is in x[15..0] and remainder is in x[31..16]
'
divide shl y,#15 'get divisor into y[30..15]
mov t,#16 'ready for 16 quotient bits
:loop cmpsub x,y wc 'y =< x? Subtract it, quotient bit in c
rcl x,#1 'rotate c into quotient, shift dividend
djnz t,#:loop 'loop until done
divide_ret ret 'quotient in x[15..0],
'remainder in x[31..16]
Comments
It looks like the links in your signature are broken (maybe because of the n-th forum upgrade?).
Anyway, as an example the Prop Tools (Index) link is currently:
http://forums.parallax.com/showthread.php?t=106790
...and might need to be instead:
https://forums.parallax.com/discussion/106790
Hope you take this as a friendly observation. Always have valued your code, comments, and commitment to the Prop!
-joe
thanks to both
Here is a modified version that works for me on a Quickstartboard:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 'QUICKSTART 80 MHZ NORMAL CRYSTAL var long dividend 'VARIABLE IN THE PAR ADDRESS TO BE PASSED long divisor long quotient long remainder obj pst : "parallax serial terminal" pub main dividend := 21 divisor := 2 pst.start(115200) waitcnt(clkfreq*5 + cnt) 'hold five sec to open the 'serial terminal and enable it cognew(@asm,@dividend) 'start cog at the first variable address waitcnt(clkfreq + cnt) 'give top object time to catch up to pasm pst.str(string("quotient:")) pst.dec(quotient) pst.newline pst.str(string("remainder:")) pst.dec(remainder) pst.newline dat asm org mov tempvar, par 'get the par address into the temporary variable rdlong x, tempvar 'read the value into the dividend add tempvar, #4 'move over to the next long to get the divisor variable rdlong y, tempvar 'read the value of the divisor into the variable add tempvar, #4 'move over to the next long to get the quotient address ' Divide x[31..0] by y[15..0] (y[16] must be 0) ' on exit, quotient is in x[15..0] and remainder is in x[31..16] ' divide shl y,#15 'get divisor into y[30..15] mov t,#16 'ready for 16 quotient bits :loop cmpsub x,y wc 'y =< x? Subtract it, quotient bit in c rcl x,#1 'rotate c into quotient, shift dividend djnz t,#:loop 'loop until done ' quotient in x[15..0], ;return if used as a subroutine ' remainder in x[31..16] mov quotientvar,x and quotientvar,andvar2 'isolate lower 16 bits wrlong quotientvar,tempvar 'write into Spinvar 'quotient' mov remaindervar,x shr remaindervar, #16 'isolate higher 16 bits add tempvar,#4 'incr pointer to remainder address wrlong remaindervar,tempvar 'write into Spinvar 'remainder' andvar2 long $ffff tempvar res 1 x res 1 y res 1 quotientvar res 1 remaindervar res 1 t res 1
Andy
Any hope the forum moderators could to a global search and replace for these "showthread.php?t=" things?
I'm not even sure who to reach out for matters like that...
Believe me, I would love to have that capability because I HATE broken links.
I will post a version of it soon.