HC908GP __isflag_carry()

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

HC908GP __isflag_carry()

3,748 Views
CJH
Contributor I
I'm trying to check the carry bit using __isflag_carry() but keep getting the linker error
 
L1822: Symbol __isflag_carry in file ....c.o is undefined
 
According to the manual file,
 
"To avoid using HLI for this purpose, the Compiler offers a set of intrinsic functions. The code of these functions is inlined. The processor flags listed in Table 8.3 are read by the associated intrinsic function. "
 
Since it's supposed to be intrinsic, there does not appear to be a .h file to declare it.
 
What am I missing?  (CW V5.7.0 Build 2015, HC908GP)
 
Thanks.
Labels (1)
0 Kudos
10 Replies

767 Views
CompilerGuru
NXP Employee
NXP Employee
The following sample builds/runs fine for me (default options)

Daniel

#include <hidef.h>
#include "derivative.h"

void Err() { for (;;) { /* wait here */ } }

char __isflag_carry(void);

char fun(unsigned char a) {
  __asm ADD #1;
  return __isflag_carry();
}
void main() {
  if (fun(1) != 0) {
    Err();
  }
  if (fun(255) != 1) {
    Err();
  }

  for(;;) {
    __RESET_WATCHDOG(); /* feeds the dog */
  }
}



    9:    __asm ADD #1;
  0000 ab01     [2]             ADD   #1
   10:    return __isflag_carry();
  0002 2502     [3]             BCS   L6 ;abs = 0006
  0004 4f       [1]             CLRA 
  0005 81       [4]             RTS  
  0006          [5]     L6:    
  0006 a601     [2]             LDA   #1
   11:  }
  0008 81       [4]             RTS  
   12:  void main() {
0 Kudos

767 Views
CJH
Contributor I
Strange - I copied your code into CW and compiled and I get:
 
  12:     __asm ADD #1; 
 0000 ab01     [2]             ADD   #1
  13:     return __isflag_carry();
 0002 cd0000   [5]             JSR   __isflag_carry
  14:     }
 0005 81       [4]             RTS  
  15:    
  16:  void main() {
Which of course results in the __isflag_carry undefined message from the linker...
 
What version of CW are you running?
0 Kudos

767 Views
Geezer
Contributor I
Check your compiler option "Disable optimizations".
Al
0 Kudos

767 Views
CJH
Contributor I
I do have "disable optimizations" checked in the compiler options tab.
0 Kudos

767 Views
Geezer
Contributor I
CJH:

For younger generations checking something means clicking on a little square icon.

Sigh.Poor modern English on my part... when I said to "check" an item I meant it in the older sense of "go look at it".

Al
0 Kudos

767 Views
CJH
Contributor I
Yeah, I got the part about looking at it - I assumed that turning off optimizations was the desired setting, so I figured having it "checked" was right...
 
I'm not all _that_ young...
 
Thanks to all for the help.
 
Carlos
0 Kudos

767 Views
bigmac
Specialist III
Hello,
 
As a matter of curiosity, do both the two different compiled versions produce the intended result?  It appears to me that one version may make a macro substitution, and the other version makes a sub-routine call, with either version giving correct operation.  Does it have something to do with the compiler optimising for speed, or code compactness?
 
Just a thought.
 
Regards,
Mac
 
0 Kudos

767 Views
CJH
Contributor I
Mac,
 
The main problem I was having is that it's NOT defined anywhere else - there is no such subroutine, so the version compiled with a subroutine call produces an error in linking since the linker doesn't find that subroutine anywhere.  So no, they don't produce equivalent results, at least not in my opinion...
 
Carlos
0 Kudos

767 Views
CompilerGuru
NXP Employee
NXP Employee
I see, it's a silly behavior of the -ont option.
If you disable the complete tree optimizer, then the intrinsics are not recognized :smileysad:
2 solutions:
- only disable the treeopt suboptimization you really do not want. So instead of -ont, use -ont=ab.......
- define the __isflag_carry function in another module.
As the function is only called with disabled optimizations, it wont affect the release build. And the debug build will just call it.

Daniel
0 Kudos

767 Views
CJH
Contributor I
Man, I would never have figured that out - disabling optimizations disables intrinsics too!  Certainly not obvious to me, and I don't think a very desirable behavior...
 
Thank you!
0 Kudos