I want to write a macro which pushes IE onto stack and pops it out soon. How can I do it? How to embed the code 0xc0, 0xa8 PUSH IE and 0xd0, 0xa8 POP IE into c program?
Pushing EA onto the stack is the natural way for an assembly language programmer to work. I'm not sure that the macros that you suggest will work. I'm not clear why LOADIE includes a "CLR EA" instruction. In any event, including a #ASM in a module will require that the optimisation level is turned down to zero - for the whole module. That is not very desirable. You could try implementing a save_ie()and load_ie() functions in a different (separately compiled) module. They would look something like this:
save_ie() { #pragma AMS POP Acc POP B PUSH IE PUSH B PUSH Acc #pragma ENDASM } load_ie() { #pragma AMS POP Acc POP B POP IE PUSH B PUSH Acc #pragma ENDASM } main { save_ie(); AE = 0; ..do stuff... load_ie(); }
Sigh... Use #pragma disable. For example:
#pragma disable void interrupt_protected_function (void) { }