6809 8-bit Division

Hardware Hacking, Programming and Game Solutions/Cheats

6809 8-bit Division

Postby Rink » Wed Aug 08, 2012 1:19 pm

Does anyone happen to have 6809 assembly language code for a simple 8-bit division routine?

It's been a very long time since I had to write one; and to be honest, it just doesn't sound like a fun way to spend the afternoon. Besides, there no sense re-inventing the wheel after all.

Cheers guys.
Rink
 
Posts: 226
Joined: Mon Sep 05, 2011 7:01 pm

Re: 6809 8-bit Division

Postby Sarah » Wed Aug 08, 2012 6:16 pm

Do you need a floating point solution?

If not, with integers you could simply do multiple SUB instructions, counting the iterations until the result is less than the divisor. Of course if the divisor is 2, 4, 8, 16 etc then it's dead easy as you just need to do one or more right shifts (ASR/LSR) instead.

Maybe something like this to divide A by B (leaving the result in B)?*

PSHS D
CLRB
LOOP SUBA 1,S
BCS END
INCB
BRA LOOP
END LDA ,S++

*Just a quick stab, not tested!
Sarah
 
Posts: 131
Joined: Wed Apr 13, 2011 3:36 pm

Re: 6809 8-bit Division

Postby Rink » Wed Aug 08, 2012 6:31 pm

Oops. Forgot to mention that yes, i only need integer division and that i need to extract the remainder.

Good thinking with SUBS though. A routine like that (with remainder calculation at the end) will be pretty quick to implement. i'm not overly concerned about performance; it won't be used much.

Cheers Sarah.
Rink
 
Posts: 226
Joined: Mon Sep 05, 2011 7:01 pm

Re: 6809 8-bit Division

Postby Sarah » Wed Aug 08, 2012 6:44 pm

I guess if you change the last line to ADDA 1,S then you've got the remainder in A and just need to adjust the stack appropriately (LEAS 2,S) afterwards.

Or more simply:

PSHS B
CLRB
LOOP SUBA ,S
BCS END
INCB
BRA LOOP
END ADDA ,S+
Sarah
 
Posts: 131
Joined: Wed Apr 13, 2011 3:36 pm

Re: 6809 8-bit Division

Postby Rink » Wed Aug 08, 2012 8:26 pm

That works an absolute treat.

Who are you!?! Everytime I (or anyone else for that matter) pose a fairly difficult question, you're there with an informed answer or elegant solutions!!!

Thank you very much. You've saved me a lot of hassle - and even when i'd got to the end of my own routine, it wouldn't have been so concise.
Rink
 
Posts: 226
Joined: Mon Sep 05, 2011 7:01 pm

Re: 6809 8-bit Division

Postby Sarah » Wed Aug 08, 2012 10:26 pm

LOL!

You're welcome! :D
Sarah
 
Posts: 131
Joined: Wed Apr 13, 2011 3:36 pm

Re: 6809 8-bit Division

Postby sixxie » Thu Aug 09, 2012 10:17 am

Not what you asked for, but I remembered adapting a specific unsigned divide-16-bit-by-10 here:

http://www.6809.org.uk/dragon/asm/printd.s

Could definitely do with more (any) comments, because I now have no clue how it works! But it was a fairly straightforward non-iterative algorithm found on the web somewhere, whittled down to make (best?) use of 6809 ops.
sixxie
 
Posts: 655
Joined: Fri Jul 18, 2008 8:36 am
Location: Llundain

Re: 6809 8-bit Division

Postby snarkhunter » Mon Aug 13, 2012 7:50 pm

I just checked my old "Zaks/Labiaks" and, as I remembered, it does include some routines for 8/8 and 16/16 bit divisions. The former is a bit longer than what has already been proposed here since it uses ASLB/ROLA instructions, but I'm not sure about the actual speed of the code vs looped SUBs.

If you're at all interested, I may re-type this here within the next couple of days.

I owe so much to that book, which is the one that actually got me started with m/c programming, circa 1984...

Lionel
snarkhunter
 
Posts: 162
Joined: Fri Apr 03, 2009 7:16 pm
Location: France


Return to Hints and Tips

Who is online

Users browsing this forum: No registered users and 0 guests