I need fast routines in this case so i built a 32bit timeout checking routine in assembly that is very fast.
It returns a bool in accumulator A and an accordingly set Z flag (condition code).
On use of this routine the compiler thinks it is necessary to test A again:
  936:   if(CheckTimeoutByRef(&Timeout)) { //If timeout:  0000 a600     [2]             LDA   @Timeout  0002 5f       [1]             CLRX    0003 cd0000   [5]             JSR   CheckTimeoutByRef  0006 4d       [1]             TSTA    0007 270b     [3]             BEQ   L14 ;abs = 0014  937: 
How do i tell the compiler that Z is already correctly set ie. that the TSTA instruction is not necessary ? (I know it saves just one instruction.)
The CheckTimeoutByRef function is pure assembly.
Add something to the function definition ? A pragma ? Or .... ?
Hello
This is not possible. When you are calling a function the compiler expects it to follow the calling convention defined by the compiler.
This calling convention is described in the "Compiler_HC08.pdf" manual chapter "Using the Compiler" section "HC(S)08 Back End" -> "Calling Protocol and Conventions"
THere is no way to change the calling convention (i.e. The way parameter are passed and values are returned).
When you are mixing C and assembly file it is your responsibility that your assembly files follows the compiler calling convention.
CrasyCat
What made you think i did not understand the calling convention ?
Thanx anyway, pity that the calling convention & the compiler dont seem to want to know about a condition code...
I had the hope that there would be a pragma for it or that RTS ! {},{} could be used.
Hello
You can submit a service request to ask for an extension in the compiler.
Here is the URL for submitting a service request:
https://www.freescale.com/webapp/servicerequest.create_SR.framework?regFlag=fromOpenSR
CrasyCat
I could, yes.
But that would be just one user asking for a seldom used compiler extention, imho...
I'll do with what i have.
I've been looking at these library functions from rtshc08.c:
#pragma NO_EXITvoid _PUSH_CC(void) {/* DESC:    push condition code without affecting any other register   IN:      CC   OUT:   WRITTEN:  */   asm {                PSHA                ; // save A                TPA                 ; // save CC on stack                PSHA                LDA    4,SP         ; // push return address                PSHA                LDA    4,SP                PSHA                LDA    4,SP         ; // reload A                RTS ! {H+X+A}, {SR}   }}#pragma NO_EXITvoid _POP_CC(void) {/* DESC:    pop condition code without affecting any other register   IN:   OUT:     CC   WRITTEN:  */   asm {                STA    4,SP        ; // save A                PULA               ; // move return address to the place of '_PUSH_CC'                STA    4,SP                PULA                STA    4,SP                PULA               ; // restore CC                TAP                PULA               ; // restore A                RTS ! {H+X+A+SR}, {}   }}
Here the compiler clearly knows about CC aka SR.
Looking at generated code: the compiler uses the above functions quite often.
Could you (or someone else) explain what these do, please ? :
RTS ! {H+X+A}, {SR}
RTS ! {H+X+A+SR}, {}
I have been reading the help about "In & Gen Sets" but i still dont understand it quite...