你的问题是 MUL 只有 16 位,这意味着如果你有一个 64 位的结果,你需要按 4 个 16 位的乘法和加法的顺序来做。然后将结果返回到两个寄存器中,因为每个寄存器都是 32 位的。
假设你想要 A x B,A 是 AH 和 AL,B 是 BH 和 BL
你会得到一系列的部分产品:
1: BL x AL
2: BL x AH x 2^16
3: BH x 2^16 x AL
4: BH x 2^16 x AH x 2^16
4 个部分积中的每一个都在 64 位字的自己的部分中累积,为了使事情更有趣,您需要考虑进位。
就寄存器而言,我将介绍的内容与您需要的内容有所不同,但是如果您能理解它,您可以根据自己的练习进行更改。假设 A6 是堆栈,我们将在 D0 中返回高 32 位字的结果,并在 D1 中返回低 32 位字。这是我库中的一段代码
umul32: link a6, #0
movem.l d2-d4, -(sp)
move.l (multiB,a6), d4 ;B into d4
move.l (multiA,a6), d3 ;A into d3
moveq #0,d2
moveq #0,d1
moveq #0,d0
mshift1: lsr.l #1,d4 ; look for 1 in multiplier
bcc.s mshift2 ; branch on 0
add.l d3,d1 ; add shifted A to product
addx.l d2,d0 ; add carry if found
mshift2: lsl.l #1,d3 ; shift for next iteration
roxl.l #1,d2
tst.l d4 ; check for 1s
bne.s mshift1
movem.l (sp)+,d2-d4
ulnk a6
move.l (sp),(8,sp) ;clean the 8 entries off the stack
addq.l 8, sp
rts