Hi
I am using a MC9S08QD4 and CodeWarrior.
I want to minimize the Interrupt routines that I have to absolute minimum.
In this case it means removing the "PSHH" and "PULH" instructions which is done at the beginning and end, respectivly.
I would like to keep all the code in C.
I saw in the compiler manual that you can use the #pragma TRAP_PROC" keyword for the interrupt routines and that will remove the pushing and popping of the H-reg.
Unfortunatley that does not remove the instructions
So, can anyone help me with this.. or should I write the routines in assembly instead?
Thanks in advance!
/P
Hello
I did check with V6.2..
With TRAP_PROC alone, H is pushed/restores in interrupt function even when it is not used.
In order to prevent that from happening you need to use TRAP_PROC SAVE_NO_REGS.
I do not have V6.0 installed so I cannot comment on what is happening there.
CrasyCat
Ok. I have written everything in assembly now, and it works fine.
I only have two 5 cycle instructions per routine PLUS the RTI of course.
Now to the problem:
I want the compiler to find the mc9s08qd4.inc by itself. Right now i have written this...
INCLUDE "mc9s08qd4.inc" ; include device file
... in the assembler file and had to add the file in the source directory together with all the other .c .h and .asm files.
I would like to have it similar to the derivative.h file in which the MC9S08QD4.h file is included without having the actual file in the project, rather fetching it somewhere from the compiler directory.
So can anyone help me with this?
P_B wrote:Ok. I have written everything in assembly now, and it works fine.
I only have two 5 cycle instructions per routine PLUS the RTI of course.
Now to the problem:
I want the compiler to find the mc9s08qd4.inc by itself. Right now i have written this...
INCLUDE "mc9s08qd4.inc" ; include device file... in the assembler file and had to add the file in the source directory together with all the other .c .h and .asm files.
I would like to have it similar to the derivative.h file in which the MC9S08QD4.h file is included without having the actual file in the project, rather fetching it somewhere from the compiler directory.
So can anyone help me with this?
Thought I would answer the above by myself
I think I know now how to do the above. Even though I am not gonna use it.
Just make a new project, and make sure you have assemby and C selected.
That should generate a derivative.inc and derivative.h... problem solved
I want to minimize the Interrupt routines that I have to absolute minimum.
In this case it means removing the "PSHH" and "PULH" instructions which is done at the beginning and end, respectivly.
I would like to keep all the code in C.
I see a contradiction here. You want to use only C yet you want the absolute minimum, and to also remove the PSHH and PULH instructions.
Using only C means you let the compiler do its best. You only concentrate on writing tight C code.
Removing PSHH and PULH means you're messing with assembly code, and the C compiler can't possibly know what you're doing. If the compiler had no need protecting H in the first place, it wouldn't (unless there is no optimization with your compiler). I don't think you can tell a compiler to avoid specific assembly language instructions, so that it won't ever mess with the H register (LDHX, AIX, etc.) Even if it were possible, the advantage of removing just two bytes (PSHH & PULH) is too small a gain compared to the loss of the remaining code still written in C, and handicapped by trying NOT to use H affecting instructions.
Finally, I don't care what anyone else might tell you, the absolute minimum cannot be had in C, period! Use assembly for interrupt handler.
I don't think you can tell a compiler to avoid specific assembly language instructions, so that it won't ever mess with the H register (LDHX, AIX, etc.)
Finally, I don't care what anyone else might tell you, the absolute minimum cannot be had in C, period! Use assembly for interrupt handler.
Well, line 4 to 5 on page 422 in "HC(S)08 Build Tools Reference Manual for Microcontrollers" says something else.
In my case the absolut minimum can be made in C, it won't be smaller than assembly, it will be equal.
Then why not use assembly? Well I would like to keep it in C for customer.
Well, I didn't urge you not to use C. I only emphasized that you can't expect the absolute minimum in C. And it seemed to me that was your primary goal.
You're right, it may be possible for C to produce code just as good as assembly (never better, of course, by common logic) but only if the statements involved are trivial, e.g. simple assignment or if statements, etc. But for any code that's a bit more involved the advantage is always on the assembly side. I did assume your interrupt handler does something not too trivial, or else you wouldn't care about optimizing it further.
By the way, what do those lines (4 & 5) say? I can't find the doc you're referring to, but I'm curious, can you quote?
Well, my interrupt routines are very simple and the 5 cycles that pushing and popping of the H-reg would only save me 5 cycles x 2MHz bus clock = 2,5 µs. Most likely it will not be a problem.
I am writing(trying to) the interrupt routines in assembly but it's not going well
So I think I am gonna leave it as it is.
Quote from "HC(S)08 Build Tools Reference Manual for Microcontrollers" :
"....If you are sure that H is not written in the
interrupt routine, you can use the TRAP_PROC pragma to disable the saving and restoring
of H..."
Quote from "HC(S)08 Build Tools Reference Manual for Microcontrollers" :
"....If you are sure that H is not written in the
interrupt routine, you can use the TRAP_PROC pragma to disable the saving and restoring
of H..."
OK, this is most certainly referring to code you have written in assembly. The compiler knows whether its own generated code uses H or not, so it should not change its behavior with this pragma for code the compiler generates, as it would be a sure disaster. The statement does not imply you can force the compiler not use the H register at all in its own generated code.
I understand what you mean and it seems logical.
But what does the statement imply then?
I am quoting the whole text now instead:
Quote from "HC(S)08 Build Tools Reference Manual for Microcontrollers" :
-------------------------------
Pragma TRAP_PROC
This pragma defines an interrupt routine (i.e., activating this pragma terminates the
function with an RTI instruction instead of an RTS). Normally, interrupt routines save and
restore the H register at the entry response exit. If you are sure that H is not written in the
interrupt routine, you can use the TRAP_PROC pragma to disable the saving and restoring
of H (see #pragma TRAP_PROC: Mark Function as Interrupt Function)
------------------------------
Well english is not my native language so I might miss-interpret.
But I thought it meant that if I was sure that the code I write (or more exactly the generated assembly) in the interrupt routine will not modify the H-reg in any way, I can use the TRAP_PROC to disable the pushing and popping.
Hello
If you want to tell the compiler your function is an interrupt function and you do not want to save/restore H register in the function entry/exit code, you need to specify the pragma
#pragma TRAP_PROC SAVE_NO_REGS
in front of the function.
Then it is your responsibility to make sure the register H is not modified within the function.
CrasyCat
Ok, everyone thanks for the support!
the "SAVE_NO_REGS" was the thing I needed!
Now everything is in C, just like I wanted
Just one thing... I can't find any info on the "SAVE_NO_REGS" in the manual. I found something in the CW help, it only says something about some page registers.
How are you supposed to get the "TRAP_PROC" pragma working when there is no explicit explanation about "SAVE_NO_REGS" ?????
Perhaps I have missed something?
Hello
Looks like some information are missing in the manual.
Please submit a service request and ask for an update of the compiler manual including description of pragma TRAP_PROC SAVE_NO_REGS.
Click here to submit a service request.
CrasyCat
Dear P_B,
I would encourage you to embed your assembly code in the C program rather than write separate assembly code which seems to be implied by your later question.
An Example
// Note - Untested, I don't have a QD4!
//
#pragma TRAP_PROC SAVE_NO_REGS
interrupt VectorNumber_Virq
void exampleInterruptCodeInAssembly(void) {
asm {
mov #0xFF,PTADD
nop
nop
lda #50
oloop:
psha
lda #100
loop:
deca
bne loop
lda PTAD
coma
sta PTAD
pula
deca
bne oloop
}
}
This has the advantage of not needing separate files plus you have access to the usual register definitions.
Note: The compiler may do some 'optimization' of the assembly language so it may be a good idea to disassemble to the code to check exactly what is produced.
bye