How to to remove the warning in CW compiler  "Warning : C1404: Return expected:

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to to remove the warning in CW compiler  "Warning : C1404: Return expected:

Jump to solution
1,367 Views
AnnaKoteswarara
Contributor I

Hi,

I am using the Codewarrior compiler in which i uses the both assembly and C code in a function. This is for HCS08 SG16 micro. I am facing an error like

Warning : C1404: Return expected in my function as below,

 

 

BYTE Get_IMask_Status(void)
{
   #asm
      tpa                  ; Read contents of CCR to A
      and #0x08            ; isolate I mask bit
      asla                 ; shift left by one bit
      nsa                  ; nibble swap, Acc has the content of I bit
   #endasm
}

 

I have the above  function which retruns a BYTE,  but i  am reading that BYTE value from the Accumalator from the assembly code . but CW is throwing a error that return expected. But i am have not written the return statement in the C function but evenm though i am getting return indirectly from the A which is in assembly. is ther any way that i can remove this warning? Or how can i get the Accumulator value into C retun true.

Please reply to me.

Labels (1)
Tags (1)
0 Kudos
1 Solution
823 Views
theo
NXP Employee
NXP Employee

In order to disable message C1404 for a specific function (you would not want to do that for the whole compilation unit), you need to use #pragma MESSAGE with that function:

- pragma before the function, to disable the message

- pragma after the function, to set the message back to Warning again (so as to make sure that, were there other functions which miss the return statement, the warning will actually be reported for those functions).

Given your function, this means:

#pragma MESSAGE DISABLE C1404
BYTE Get_IMask_Status(void)
{
   #asm
      tpa                  ; Read contents of CCR to A
      and #0x08            ; isolate I mask bit
      asla                 ; shift left by one bit
      nsa                  ; nibble swap, Acc has the content of I bit
   #endasm
}
#pragma MESSAGE WARNING C1404

 

View solution in original post

0 Kudos
5 Replies
823 Views
bigmac
Specialist III

Hello,

 

The compiler does not analyse the actions of the assembly code, so it does not take into account that you are already returning the required value in the accumulator.  To avoid the warning, you need to create a local variable, assign the accumulator value to the variable, and return the variable.  Of course this reduces the efficiency of the code.

 

byte Get_IMask_Status(void){   byte temp;   #asm      tpa                  ; Read contents of CCR to A      and #0x08            ; isolate I mask bit      asla                 ; shift left by one bit      nsa                  ; nibble swap, Acc has the content of I bit      sta temp;   #endasm   return temp;}

 

This results in the following assembly code for the sub-routine.  The additional code associated with the variable is indicated.  The routine occupies eleven bytes.

.

    pshh

    tpa

    and  #0x08

    lsla

    nsa

    tsx

    sta  ,x

    lda  ,x

    pulh

    rts

.

Here is an alternative version of the function, requiring nine bytes of code.

 

byte Get_IMask_Status(void){   byte temp = 0;      __asm bmc B1;   temp++;   __asm B1:   return temp;}

 

However, you do not need to use either of these functions to return the I-bit status.  An intrinsic function is already available to do this, and requires smaller code.  The function prototype can be found within the file <intrinsics_hc08.h>, present in the CW installation.

 

char __isflag_int_enabled( void);

 

Functions to return other status bits may also be of interest.

 

Regards,

Mac

 

0 Kudos
823 Views
AnnaKoteswarara
Contributor I

Thanks for your good idea. I have to try out this new code implmentation. But i have to minimize the code size as we have critical flash requirements. I can go for the Message disable option. Again thanks for this new idea. I will try it out and come back to you...

 

0 Kudos
823 Views
BlackNight
NXP Employee
NXP Employee

Instead of using

#pragma MESSAGE WARNING C1404

in order to reset the message back to a warning you could use as well

#pragma MESSAGE DEFAULT C1404

 

That way you do not need to 'know' that it was a warning message.

 

BK

 

0 Kudos
824 Views
theo
NXP Employee
NXP Employee

In order to disable message C1404 for a specific function (you would not want to do that for the whole compilation unit), you need to use #pragma MESSAGE with that function:

- pragma before the function, to disable the message

- pragma after the function, to set the message back to Warning again (so as to make sure that, were there other functions which miss the return statement, the warning will actually be reported for those functions).

Given your function, this means:

#pragma MESSAGE DISABLE C1404
BYTE Get_IMask_Status(void)
{
   #asm
      tpa                  ; Read contents of CCR to A
      and #0x08            ; isolate I mask bit
      asla                 ; shift left by one bit
      nsa                  ; nibble swap, Acc has the content of I bit
   #endasm
}
#pragma MESSAGE WARNING C1404

 

0 Kudos
823 Views
AnnaKoteswarara
Contributor I

Thanks and it is working fine for me.

 

 

0 Kudos