Newsgroups: comp.sys.apple2.programmer Path: blue.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!newsrelay.iastate.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!cs.utexas.edu!utnut!utcsri!newsflash.concordia.ca!CC.UMontreal.CA!IRO.UMontreal.CA!guertinp From: guertinp@IRO.UMontreal.CA (Paul Guertin) Subject: Re: ASM multiply/divide Message-ID: Sender: news@IRO.UMontreal.CA Organization: Universite de Montreal, Canada References: <2veuv9$1u6@atlas.cs.upei.ca> <2vgkqu$g64@atlas.cs.upei.ca> Date: Thu, 7 Jul 1994 21:30:12 GMT Lines: 28 Here's a 16-by-8 bit unsigned divide that I used in a program to calculate many decimals of pi. Input in dvend, dvend+1 (lsbyte first) and dvsor. Output in dvend (quotient) and dvend+1 (remainder). Of course, since the quotient is 8 bits wide, you must ensure that floor(dividend/divisor) < 256. I didn't count cycles, but it should take around 200 cycles average. ldx #9 lda dvend+1 loop rol dvend dex beq end rol bcs foo cmp dvsor bcc loop foo sbc dvsor sec bcs loop end sta dvend+1 rts Paul Guertin guertinp@iro.umontreal.ca