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

pilot0315
Posts: **152**

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

11 Commentssorted by Date Added Votes14,253-1Vote UpVote DownMy Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBladeProp OS(also see Sphinx, PropDos, PropCmd, Spinix)Website: www.clusos.comProp Tools (Index) , Emulators (Index) , ZiCog (Z80)450Vote UpVote DownIt 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

1520Vote UpVote Downthanks to both

2,1991Vote UpVote DownHere is a modified version that works for me on a Quickstartboard:

Andy

14,2530Vote UpVote DownMy Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBladeProp OS(also see Sphinx, PropDos, PropCmd, Spinix)Website: www.clusos.comProp Tools (Index) , Emulators (Index) , ZiCog (Z80)450Vote UpVote DownAny 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,2530Vote UpVote DownMy Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBladeProp OS(also see Sphinx, PropDos, PropCmd, Spinix)Website: www.clusos.comProp Tools (Index) , Emulators (Index) , ZiCog (Z80)10,4740Vote UpVote DownBelieve me, I would love to have that capability because I

broken links.HATE1520Vote UpVote DownI will post a version of it soon.

1520Vote UpVote Down1520Vote UpVote Down