OK, that sounds reasonable enough.
So back to BigWumpus' code.
The rlncf's are a problem because it rotates the high bit around to the low bit. What needs to be done is rotate a 0 into the Low bit, and the High bit to the carry.
bcf STATUS, C
rlcf _AL,f
rlcf _AM,f
rlcf _AH,f
rlcf _AU,f
and the addwfc's need to go to F (file) instead of W. Here's the corrected code...
Code:
asm
;clear X
clrf _XU
clrf _XH
clrf _XM
clrf _XL
;shift A by 1 position left
bcf STATUS, C
rlcf _AL,f
rlcf _AM,f
rlcf _AH,f
rlcf _AU,f
;[repeat the shift-routine]
bcf STATUS, C
rlcf _AL,f
rlcf _AM,f
rlcf _AH,f
rlcf _AU,f
;move A to X
movff _AU,_XU
movff _AH,_XH
movff _AM,_XM
movff _AL,_XL
;[repeat the shift-routine]
bcf STATUS, C
rlcf _AL,f
rlcf _AM,f
rlcf _AH,f
rlcf _AU,f
;[repeat the shift-routine]
bcf STATUS, C
rlcf _AL,f
rlcf _AM,f
rlcf _AH,f
rlcf _AU,f
;[repeat the shift-routine]
bcf STATUS, C
rlcf _AL,f
rlcf _AM,f
rlcf _AH,f
rlcf _AU,f
;add A to X
bcf STATUS, C
movf _AL,w
addwfc _XL,f
movf _AM,w
addwfc _XM,F
movf _AH,w
addwfc _XH,F
movf _AU,w
addwfc _XU,F
;[repeat the shift-routine]
bcf STATUS, C
rlcf _AL,f
rlcf _AM,f
rlcf _AH,f
rlcf _AU,f
;[repeat the add-routine]
bcf STATUS, C
movf _AL,w
addwfc _XL,f
movf _AM,w
addwfc _XM,F
movf _AH,w
addwfc _XH,F
movf _AU,w
addwfc _XU,F
endasm
Or, Here's my little spin on it.
Code:
gosub Mult32
;______________________________
Mult32:
asm
call ShiftA
call ShiftA ; *4
movff _AU,_XU ; move A to X
movff _AH,_XH
movff _AM,_XM
movff _AL,_XL
call ShiftA
call ShiftA
call ShiftA ; *32
call AddAX ;add A to X
call ShiftA ; *64
call AddAX ;add A to X
return
;________________________________________________
ShiftA ; shift A by 1 position left
bcf STATUS, C
rlcf _AL,f
rlcf _AM,f
rlcf _AH,f
rlcf _AU,f
return
AddAX ; add A to X
movf _AL,w
addwf _XL,F ;ignore Carry
movf _AM,w
addwfc _XM,F
movf _AH,w
addwfc _XH,F
movf _AU,w
addwfc _XU,F
return
endasm
HTH,
DT
Bookmarks