AnsweredAssumed Answered

218x DSP C code doesn't produce the same assembly code

Question asked by sketkar on Jun 22, 2009
Latest reply on Jun 23, 2009 by StuartS

Hello all,

 

I have been given the task of "cleaning up" some 218x assembly code and porting it over to C code.  But I notice that the ported over C code doesn't produce the same assembly code and at times it doesn't execute at all.

 

I'm using the EZ-ICE debugger to evaluate my executions

 

I've attached three code segments

 

original assembly function, new C function and produced s-file assembly

 

***  original assembly function ***

 

.SECTION/CODE program;

.global    _setup_processor;

_setup_processor:

    ifc = b#00000011111111;         /* clear pending interrupt */
    nop;

    imask = b#0000000000; 

    icntl = b#10111;

     /* all outputs at 0, except active high reset for nco's, a/d and txer reset, active low irql1 and to pic intrpt */
    ax0 = b#0000000001111000;    dm(Prog_Flag_Data) = ax0;
  

    /* setup the pflags and bmwait and cmssel 1-output, 0-input */
    ax0 = b#0111000001111111;    dm(Prog_Flag_Comp_Sel_Ctrl) = ax0;

    /* sport0 to be configured for high speed */
    ax0 = b#0011111001001111;    dm(Sport0_Ctrl_Reg) = ax0;
      /* sport0 autobuffer control register */
    ax0 = b#0000010010000100;     dm(Sport0_Autobuf_Ctrl) = ax0;
  

    ax0 = 0x03;    dm(Sport0_Sclkdiv) = ax0;    /* 4.xxxmhz sclk */
    ax0 = 0x00; dm(Sport0_Rfsdiv) = ax0;

    ax0 = b#0001000000001000;   dm(Sys_Ctrl_Reg) = ax0;

    ax0 = b#0111111111010010;    dm(Dm_Wait_Reg) = ax0;

    ax0 = dm(0x3fd0);            /* get the flag from the application */
    dm(_app_flag) = ax0;        /* this will be 0xA5A5 if the app sent us here */

    reset fl0;
    set fl1;        /* txer select enable low, deselect high */
    reset fl2;        /* nco update  */
    reset flag_out;    /* power control pin, 1-power, 0-no power */

    reset fl1;            /* select the transmitters through fl1 low */
    ax0 = 0;        /* turn off the txers */
    IO(TX_ENABLE_ADDR) = ax0;
    set fl1;            /* deselect the transmitters through fl1 high */

    rts;

_setup_processor.END:

 

 

*** ported C function ***

 

void setup_processor(void)
{
    int *app_ptr = 0x3FD0; 
    sysreg_write(sysreg_IFC, 0x00FF);
    asm("nop;");
    sysreg_write(sysreg_IMASK, 0x000);
    sysreg_write(sysreg_ICNTL, 0x17);  
    Prog_Flag_Data = Prog_Flag_Data & 0x0078;
    Prog_Flag_Comp_Sel_Ctrl = Prog_Flag_Comp_Sel_Ctrl & 0x707F;
    Sport0_Ctrl_Reg = Sport0_Ctrl_Reg & 0x3E4F;
    Sport0_Autobuf_Ctrl = Sport0_Autobuf_Ctrl & 0x0484;
    Sport0_Sclkdiv = Sport0_Sclkdiv & 0x03;
    Sport0_Rfsdiv = Sport0_Rfsdiv & 0x00;
    Dm_Wait_Reg = 0x7FD2;  
    app_flag = *app_ptr;

    asm("reset fl0;");
    asm("set fl1;");        /* txer select enable low, deselect high */
    asm("reset fl2;");        /* nco update  */
    asm("reset flag_out;");    /* power control pin, 1-power, 0-no power */

    asm("reset fl1;");            /* select the transmitters through fl1 low */
    asm("ax0 = 0;");        /* turn off the txers */
    asm("IO(0x0300) = ax0;");
    asm("set fl1;");            /* deselect the transmitters through fl1 high */

}

 

*** The s-file produced by the 218x compiler/linker ***

 

.section/pm program;

 

.epctext:

 

_setup_processor:
//  line ".\setup.c":6
        AR = M4 ;
        M4 = I4 ;
        DM(I4 += M7) = AR;
        AR = TOPPCSTACK ;
        M5 =  -2;
        DM(I4 += M5) = AR;
        AR = I2 ;
        DM(I4 += M7) = AR;
        AR = I3 ;
        DM(I4 += M7) = AR;
_LN$1:
//  line 7
        AR =  16336;
        I6 =  -2; MODIFY(I6 += M4); DM(I6 += M6) = AR;
_LN$2:
//  line 10
        IFC= 255;
_LN$3:
//  line 12
        nop;
_LN$4:
//  line 14
        IMASK= 0;
_LN$5:
//  line 15
        ICNTL= 23;
_LN$6:
//  line 18
        AR =  16357;
        I1 = AR ;
        AX1 = DM(I1 += M2);
        AY1 =  120;
        AR = AX1 AND AY1;
        SI =  16357;
        I0 = SI ;
        DM(I0 += M2) = AR;
_LN$7:
//  line 20
        AR =  16358;
        I2 = AR ;
        AX1 = DM(I2 += M2);
        AY0 =  28799;
        AR = AX1 AND AY0;
        AX1 =  16358;
        I3 = AX1 ;
        DM(I3 += M2) = AR;
_LN$8:
//  line 22
        AR =  16374;
        I1 = AR ;
        AX0 = DM(I1 += M2);
        AY1 =  15951;
        AR = AX0 AND AY1;
        AX0 =  16374;
        I1 = AX0 ;
        DM(I1 += M2) = AR;
_LN$9:
//  line 24
        AR =  16371;
        I1 = AR ;
        SR1 = DM(I1 += M2);
        AY1 =  1156;
        AR = SR1 AND AY1;
        MX0 =  16371;
        I1 = MX0 ;
        DM(I1 += M2) = AR;
_LN$10:
//  line 26
        AR =  16373;
        I1 = AR ;
        SR1 = DM(I1 += M2);
        AY1 =  3;
        AR = SR1 AND AY1;
        MY0 =  16373;
        I1 = MY0 ;
        DM(I1 += M2) = AR;
_LN$11:
//  line 27
        AR =  16372;
        I1 = AR ;
        MX1 = DM(I1 += M2);
        MX1 =  0;
        I1 = AR ;
        DM(I1 += M2) = MX1;
_LN$12:
//  line 29
        AR =  16382;
        MY1 =  32722;
        I1 = AR ;
        DM(I1 += M2) = MY1;
_LN$13:
//  line 31
        I6 =  -2; MODIFY(I6 += M4); MR0 = DM(I6 += M6);
        I6 = MR0 ;
        MR1 = DM(I6 += M6);
        DM(ADDRESS(_app_flag)) = MR1;
_LN$14:
//  line 34
        reset fl0;
_LN$15:
//  line 35
        set fl1;
_LN$16:
//  line 36
        reset fl2;
_LN$17:
//  line 37
        reset flag_out;
_LN$18:
//  line 39
        reset fl1;
_LN$19:
//  line 40
        ax0 = 0;
_LN$20:
//  line 41
        IO(0x0300) = ax0;
_LN$21:
//  line 42
        set fl1;
        JUMP .P1L2147483647;
_LN$22:

 

.P1L2147483647:
        I6 = M4 ;
        AY0 = DM(I6 += M7);
        M5 =  -2;
        AR = DM(I6 += M5);
        TOPPCSTACK = AR ;
        AR = DM(I6 += M7);
        I2 = AR ;
        AR = DM(I6 += M7);
        I3 = AR ;
        I4 = M4 ;
        M4 = AY0 ;
        RTS;

 

._setup_processor.end:
    .global _setup_processor;
    .type _setup_processor,STT_FUNC;

 

 

Build the application with setup.C code will not execute properly but it does when using setup.ASM code.  Is there something I'm not doing correctly to produce the same assembly as the original function?

 

Thank you,

 

Satyajit

Outcomes