AndreC 0 Newbie Poster

Hi

I need to do a correlation of 40 samples using a dsPIC30F6014A (@80Mhz) in less than 15us, but found that when I write the correlation in C, it takes way too long (about 40us). I came accross the MAC function in assembly, which (if I can get it going) would be perfect. I am writing the assembly code inline in MikroC.

Unfortunatley I just can't get it to work. I have two main problems:

1) Using the following code, the ACCAL register only becomes 0000 0100, instead of 0001 0100. What's wrong?

asm {
   CLR ACCA

   MOV #0x0004, W4;
   MOV #0x0005, W5;
    
   MAC W4*W5, A
   MOV W4,PORTD
   MOV W5,PORTF
   MOV ACCA, W0
   MOV W0, PORTG
 }

2) The previous code was used mainly because I can't get the following code to work

int Temp1 = 4 absolute 0x0802;    //Declare variable and assign specific location
int Temp2 = 5 absolute 0x0804;    

asm {
  CLR ACCA;  //Clears Accumulator A - not sure if this is necessary ?

  MOV #0x0802,W8;   //Move the variable address values into W8 and W10   
  MOV #0x0804,W10;   
  
  MAC W4*W5, A, [W8], W4, [W10], W5;
  MOV W4,PORTD;
  MOV W5,PORTF;
  MOV ACCA, W0;    //I can't move ACCA directly to PORTG - don't know why ?
  MOV W0, PORTG;
}

The problem seems to be with the MAC insctruction, because the program runs to the end if I comment it out.

Where can I find working examples of prefetch and the MAC instructions. I have looked at everything I can find, but not a single website has a complete example that I can learn from. It is seriously frustrating spending hours on end on what should only be 5 lines of code. Any help will be appreciated!

Oh, and beware of googling MAC...;)