Hey, I've been looking around for 2 days now how to do 24 by 24 bit division in z80 asm. I've found 16/8, 16/16, 24/8, 24/16 and even 32/8. I'm sure there must be a 24/24 out there, but I can't find it. Does anyone know how to do this? I'm getting quite desperate...
Have you considered writing one yourself? I'd imagine that one of the problems is that the 24-bit by 24-bit division takes six registers for the operands, not even worrying about the division state, while the z80 only has a, b, c, d, e, h, l (seven general-purpose 8-bit registers). You could easily do some mathematical tricks to phrase your division in terms of repeated operations, though.
I am considering writing one myself now, yes, because it seems I was wrong about there already being a routine that suits my needs. I only found one forum entry, but it was for a different processor... Sad

About the lack of enough registers, I was thinking about maybe using the shadow registers somehow (I'm using my own interrupt routine that saves those at the start so no worriyng there, it just wouldn't make it very universal though). Like you said, I am sure this can somehow be done in a 24 step loop.

I wish I would have paid more attention at elementary school to understand the idea behind long division. I want to understand all those routines by Milos Bazelides to extend them to 24/24, but it's really giving me a headache.
I assume you're looking at the z80 Bits page? Those are amazing routines, but as you say, understanding how they work is highly non-trivial. Are you dividing your 24-bit number by a constant or a variable?
It has to be a variable. I am making a Bejeweled type game.
The routine was going to be used for the representation of a 50 pixel high progress bar. On the one hand you have the total amount of points needed to finish the level and on the other hand the number of points you have now. Once reaching higher levels those numbers will exceed 16-bit values. So 24 bits are needed to represent them.

The division routine I thought I needed was only going to be used to scale the ratio betweem those two values to 50 pixels (so you can watch the bar to see how far you have progressed on the level). I just figured out that in this case I effectively need only one byte (up to 50 pixels, so actually only 7 bits) of precision in the end result.

I still have the 24 bit values in memory and will use those internally , but for the progress bar I will only use 16 of those bits. Once the total amount of points needed starts using the msb, I will omit the lsb in both values to keep the division in the 16 bit range. If you're still following...

Thanks for your reply anyway, it's great to get some feedback on this.

I was indeed looking at the Z80 bits page, those routines are awesome! I'm actually using a couple of those in my game as well.
I just implemented this new idea and it seems to be working! Smile
cerzus69 wrote:
I just implemented this new idea and it seems to be working! Smile
Great to hear! Just as a point of forum etiquette, when it is less than 18 to 24 hours since your last post, it is considered correct to edit your previous post rather than double-posting. Smile Now that you have a problem solved, may I recommend that you Introduce Yourself and perhaps start a topic for your project progress on your game in the Your Projects subforum?
  
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.

» Go to Registration page
Page 1 of 1
» 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

 

Advertisement