16 bit signed division

41 views
Skip to first unread message

Robb Bates

unread,
Dec 17, 2025, 4:38:20 PM (2 days ago) Dec 17
to RC2014-Z80
I don't know why, but it's almost impossible to find a fast compact 16 bit signed division assembly routine.

Yes, I know just use an unsigned one after getting the ABS of both values and negating the result if needed.

But mine is a slow, big and bloated brute force method.  If anyone has a nice small routine already crafted, can you post it?

Ideally, HL=DE/HL with DE=remainder.  But I'll take anything.

Thanks,
Robb

Willy De la Court

unread,
Dec 17, 2025, 4:43:11 PM (2 days ago) Dec 17
to RC2014-Z80
https://wikiti.brandonw.net/index.php?title=Z80_Routines:Math:Division
Not tested these but this I think are valid.

Willy De la Court

unread,
Dec 17, 2025, 4:45:23 PM (2 days ago) Dec 17
to RC2014-Z80

Robb Bates

unread,
Dec 17, 2025, 5:54:02 PM (2 days ago) Dec 17
to RC2014-Z80
Yeah, I've seen those and I'll probably end up using one of them.  I was hoping someone had one already pre-rolled and ready to go.  All the register shuffling that I have to do adds bloat.

The ac/de one is nice and small, but I'll have to see if it leaves the remainder somewhere.  I need a MOD function as well.

Robb

Phillip Stevens

unread,
Dec 18, 2025, 12:08:19 AM (yesterday) Dec 18
to RC2014-Z80
Here is the z88dk small implementation, which follows the C standard of the remainder taking the sign of the dividend.
 

Phillip Stevens

unread,
Dec 18, 2025, 12:10:55 AM (yesterday) Dec 18
to RC2014-Z80
I don't know why, but it's almost impossible to find a fast compact 16 bit signed division assembly routine.
Ideally, HL=DE/HL with DE=remainder.  But I'll take anything.
Here is the z88dk small implementation, which follows the C standard of the remainder taking the sign of the dividend.

There are fast versions too, if you prefer that path.
Reply all
Reply to author
Forward
0 new messages