Jump to content
IGNORED

help me bug fix 32bit multiplication


twh/f2

Recommended Posts

Hi !

 

I have here a 32bit multiplication routine which is simply adapted from this code from the Codebase64.

 

http://codebase64.org/doku.php?id=base:16bit_multiplication_32-bit_product

 

The following code was adapted by FJC.

Num1	.ds 4
Num2	.ds 4
Num3	.ds 8

​.proc MulLong ; 32 bit multiplication: Num1 by Num2, result in Num3
	lda #0
	sta Num3+4
	sta Num3+5
	sta Num3+6
	sta Num3+7
	ldx #32 ; loop for each bit
multloop
	lsr Num1+3 ; divide multiplier by 2
	lsr Num1+2
	lsr Num1+1
	ror Num1
	bcc rotate
	lda Num3+4 ; get upper half of product and add multiplicand
	clc
	adc Num2
	sta Num3+4
	lda Num3+5
	adc Num2+1
	sta Num3+5
	lda Num3+6
	adc Num2+2
	sta Num3+6
	lda Num3+7
	adc Num2+3
rotate
	ror ; rotate partial product 
	sta Num3+7
	ror Num3+6
	ror Num3+5
	ror Num3+4
	ror Num3+3
	ror Num3+2
	ror Num3+1
	ror Num3
	dex
	bne multloop
	lda Num3
	ldx Num3+1
	rts
.endp

But I'm afraid it has a bug which I can't really fix. The following shows the dilemma: $4 * $16b62 = $5ad88
	mda #$16b62 Num1
	mda #$4 Num2
	jsr MulLong
	mda Num3 Temp	; save result

	jmp *

It's producing: "$1AD88" rather than "$5AD88".

 

However this one works: $16b62 * $4 = $5ad88

	mda #$4 Num1
	mda #$16b62 Num2
	jsr MulLong
	mda Num3 Temp	; save result

FJC: It seems that some upper bits of multiplier/multiplicand aren't handled properly (so result is different depending on which has set or cleared upper bits).

 

Any ideas?! Any help is appreciated!!

 

greetings,

\thomas

Edited by twh/f2
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...