Welcome to the Parallax Discussion Forums, sign-up to participate.

pilot0315
Posts: **335**

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

14,842My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBladeProp OS(also see Sphinx, PropDos, PropCmd, Spinix)Website: www.clusos.comProp Tools (Index) , Emulators (Index) , ZiCog (Z80)50It 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:...and

mightneed to be instead:Hope you take this as a friendly observation. Always have valued your code, comments, and commitment to the Prop!

-joe

335thanks to both

2,211Here is a modified version that works for me on a Quickstartboard:

Andy

14,842My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBladeProp OS(also see Sphinx, PropDos, PropCmd, Spinix)Website: www.clusos.comProp Tools (Index) , Emulators (Index) , ZiCog (Z80)50Any 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...

14,842My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBladeProp OS(also see Sphinx, PropDos, PropCmd, Spinix)Website: www.clusos.comProp Tools (Index) , Emulators (Index) , ZiCog (Z80)10,759Believe me, I would love to have that capability because I

broken links.HATE335I will post a version of it soon.

335335