Hi,

I was half asleep when I reported my last code generation problem, but this time I think I am awake :-)

The attached test.c file compiles to the attached test.s file. There seems to be something rather wrong with this. The arithmetic performed on accum2 looks OK, but accum1 is screwed up. accum1 is never loaded or stored, and screwy registers are used in accumulating the result of the imul16 routine.

Regards,
Steve
#include <signal.h>
#include <io.h>

int32_t static __inline__ imul16(register int16_t x, register int16_t y)
{
        register int32_t z;

        __asm__ (
"__MPY=0x130 \n"
"__MPYS=0x132 \n"
"__MAC=0x134 \n"
"__MACS=0x136 \n"
"__OP2=0x138 \n"
"__RESLO=0x13a \n"
"__RESHI=0x13c \n"
"__SUMEXT=0x13e \n"
        " mov   %1,&__MPYS \n"
        " mov   %2,&__OP2 \n"
        " mov   &__RESHI,%B0 \n"
        " mov   &__RESLO,%A0 \n"
        : "=r"(z)
        : "r"(x), "r"(y));
        return z;
}

int32_t accum1;
int32_t accum2;

interrupt (TIMERB0_VECTOR) adc_interrupt(void)
{
    int16_t sampleA;
    int16_t sampleB;

    sampleA = ADC12MEM[0];
    sampleB = ADC12MEM[1]; 

    accum1 += imul16(sampleA, sampleB);
    accum2 += imul16(sampleA, sampleA);
}
        .file   "test.c"
        .arch msp430x149

/* Hardware multiplier registers: */
__MPY=0x130
__MPYS=0x132
__MAC=0x134
__MACS=0x136
__OP2=0x138
__RESLO=0x13a
__RESHI=0x13c
__SUMEXT=0x13e

        .text
        .p2align 1,0
.global adc_interrupt
.global vector_fffa
        .type   adc_interrupt,@function
/***********************
 * Interrupt Service Routine `adc_interrupt' at 0xfffa
 ***********************/
vector_fffa:
adc_interrupt:
/* prologue: frame size = 0 */
.L__FrameSize_adc_interrupt=0x0
.L__FrameOffset_adc_interrupt=0x6
        push    r15
        push    r14
        push    r13
/* prologue end (size=3) */
        mov     &320, r13 
        mov     &322, r15 
/* #APP */
        __MPY=0x130 
__MPYS=0x132 
__MAC=0x134 
__MACS=0x136 
__OP2=0x138 
__RESLO=0x13a 
__RESHI=0x13c 
__SUMEXT=0x13e 
 mov    r13,&__MPYS 
 mov   r15,&__OP2 
 mov   &__RESHI,r15 
 mov   &__RESLO,r14 

/* #NOAPP */
        add     r14, r14
        addc    r15, r15
/* #APP */
        __MPY=0x130 
__MPYS=0x132 
__MAC=0x134 
__MACS=0x136 
__OP2=0x138 
__RESLO=0x13a 
__RESHI=0x13c 
__SUMEXT=0x13e 
 mov    r13,&__MPYS 
 mov   r13,&__OP2 
 mov   &__RESHI,r15 
 mov   &__RESLO,r14 

/* #NOAPP */
        add     r14, &accum2
        addc    r15, &accum2+2
/* epilogue: frame size=0 */
        pop     r13
        pop     r14
        pop     r15
        reti
/* epilogue end (size=4) */
/* function adc_interrupt size 71 (64) */
.Lfe1:
        .size   adc_interrupt,.Lfe1-adc_interrupt
/********* End of function ******/

        .comm accum1,4,2
        .comm accum2,4,2

/*********************************************************************
 * File test.c: code size: 71 words (0x47)
 * incl. words in prologues: 3, epilogues: 4
 *********************************************************************/

Reply via email to