Hi,
There's some basic problem in code attached [It just looks
long, its a lot of cut & paste work!]. What its supposed to do is multiply a
24bit no. with an 8bit number [say CONST00 with multiplier 0007h] and store the
result in a new 32-bit var (SUM3:SUM2:SUM1:SUM0). Then I have to add the next
product, i.e. the product of CONST01 and 0007h to the above 32-bit sum, and so
on. Also, my summing segment wouldn't work (how can I take the carries
into account?)
Errors generated during building: None
Logical Error: Has to be somewhere - as the different
registers don't change at all??? (Please help)
Thanks in advacne for your help/advice.
Regards,
Saurabh
PROD3 equ 10 ;
products
PROD2 equ 11
PROD1 equ 12
PROD0 equ 13
TWOFOUR3 equ 14 ;
multiplicand
TWOFOUR2 equ 15
TWOFOUR1 equ 16
TWOFOUR0
equ 17
mulitiplier equ 18 ;
multiplier
SUM3 equ 19 ;
Sum
SUM2 equ 20
SUM1 equ 21
SUM0 equ 22
;TABLE_COEFF
#define CONST00 0x082613
#define CONST01 0x0
#define CONST02 0xfFF26
#define CONST03 0x0
#define CONST04 0x28BE61
#define CONST05 0x400000
#define CONST06 0x28BE61
#define CONST07 0x0
#define CONST08 0xFF26
#define CONST09 0x0
#define CONST10 0x082613
#define multiplier 0x007
;*************************************RESET
VECTOR****************************************
ORG 0000h
GOTO BEGIN
;**********************************INTERUPT
VECTOR****************************************
;******************************************* MAIN PROGRAM
********************************
BEGIN:
movlw (const00 >>
16)
movf twofour2
movlw ((const00 >> 8)
& 0xFF)
movf twofour1
movlw (const00 &
0xFF)
movf twofour0
goto
mult24x8
goto multloop
goto
suminit
goto sum
movlw (const01 >> 16)
movf
twofour2
movlw ((const01 >> 8) &
0xFF)
movf twofour1
movlw (const01 &
0xFF)
movf twofour0
goto
mult24x8
goto multloop
goto sum
movlw (const02 >> 16)
movf
twofour2
movlw ((const02 >> 8) &
0xFF)
movf twofour1
movlw (const02 &
0xFF)
movf twofour0
goto
mult24x8
goto multloop
goto sum
;........
goto $
;**************************MULTIPLICATION
ROUTINE***************************************
mult24x8:
clrf
prod0 ; Clear the
product
clrf
prod1
clrf
prod2
clrf
prod3
clrf
twofour3 ; Clear the top byte of the
multiplicand
multloop:
movf mulitiplier,W ; Check to see if eight bit is
empty
btfsc
STATUS,Z ; Done if
zero
return
bcf
STATUS,C ; clear
carry
rrf
mulitiplier,F ; Get the next
bit
btfss
STATUS,C ; Add if carry is
set
goto
multshift ; shift only if
0
movf
twofour0,W ; Add the 32 bits of multiplicand to
product
addwf
prod0,F ; each addwf sets the
carry
btfsc
STATUS,C ; Don't increment if no
carry
incf
prod1,F ; Add one to next byte
if carry occured
movf twofour1,W
;
addwf
prod1,F
;
btfsc
STATUS,C ; Don't increment if no
carry
incf
prod2,F ; Add one to next byte
if carry occured
movf twofour2,W
;
addwf
prod2,F
;
btfsc
STATUS,C ; Don't increment if no
carry
incf
prod3,F ; Add one to next byte
if carry occured
movf twofour3,W
;
addwf
prod3,F ;
multshift:
bcf STATUS,C ;
clear carry
rlf twofour0,F ; Shift the
24 bits one bit to the left
rlf
twofour1,F
rlf
twofour2,F
rlf
twofour3,F
goto
multloop
;**************************ADDITION
ROUTINE***************************************
Suminit:
clrf sum3;
clrf sum2;
clrf sum1;
clrf sum0;
Sum:
movf prod3,w
movf
sum3
movf prod2,w
movf sum2
movf
prod1,w
movf
sum1
movf prod0,w
movf sum0