From mboxrd@z Thu Jan 1 00:00:00 1970 From: ralph at inputplus.co.uk (Ralph Corderoy) Date: Mon, 25 May 2020 06:22:29 +0100 Subject: [COFF] Pointers for maths routines in "assembly" In-Reply-To: <20200525042726.GA685@minnie.tuhs.org> References: <20200525042726.GA685@minnie.tuhs.org> Message-ID: <20200525052229.037CC1FAA1@orac.inputplus.co.uk> Hi Warren, > Assume that you can multiply two 8-bit values in hardware and get a > 16-bit result (e.g. ROM lookup table). It's straightforward to use > this to multiply two 16-bit values: ... > But if the hardware can only provide the low eight bits of the 8-bit > by 8-bit multiply, is it still possible to do a 16-bit by 16-bit > multiply? Yes. Given hex 8-b numbers ab and cd, use your 8×8=8 hardware multiply to work out b × d = BD a × d = AD b × c = BC a × c = AC and then shift and add: BD + (AD << 4) + (BC << 4) + (AC << 8) > ** Back story. I'm designing an 8-bit TTL CPU which has 8-bit > multiply, divide and modulo in a ROM table. I'd like to write > subroutines to do 16-bit and 32-bit integer maths. That's quite an unusual mix. Eight-bit CPUs I can think of either have no hardware multiply of which to take advantage, e.g. http://6502org.wikidot.com/software-math-intmul, or have a 8×8=16. -- Cheers, Ralph.