I wanted to see if my understanding is correct on this... I figured out multiplication, but I'm not quite sure how division would work. Please correct any mistakes.

Code:
```Rla Multiplication a * b 1. RRA B 2. Push the flags (af) 3. RLA A, DEC B 4. Repeat 3 until B=0 5. Pop the flags (af) 6. If c, then add the original a to a. If nc, you are done. ```

Code:
```Rra Division a / b 1. RRA B 2. Push the flags (af) 3. RRA A, DEC B 4. Repeat 3 until B=0 5. Pop the flags (af) 6. If nc, you are done. If c, [what would I do here?] ```
[/code]
What do you have against using the wonderful routines from z80Bits? I strongly, strongly recommend that you read these thoroughly, understand how they work, and then use them.

http://baze.au.com/misc/z80bits.html
Well, I don't have anything against them. I'm just interested in demonstrating mult/div via bit rotation in my tutorial.
ACagliano wrote:
Well, I don't have anything against them. I'm just interested in demonstrating mult/div via bit rotation in my tutorial.

Bit rotation is good for division, mostly for powers of two though. For multiplication adding something to itself is a faster way to multiply by two than shifting generally (only a very small speedup, but if you need a fast routine, sla a is slower than add a, a...)

I suggest you actually go through the ones Kerm told you to look at; pick those apart, and you'll see some neater and more optimized routines, and you can learn a lot more

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum