This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

inline assembly

Hi friends,

I am using inline assembly in my ISR routine. When i observe the generated sorce file. AT the start of ISR the compiler generates a code to save the ACC, DPL, DPH etc and the general purpose regi used by routine. Now i want to avoid the generation of code to save device context. I am using a saperate function to save and restore context. I want this becuse i am doing task switching in ISR so the restored context will be different then the saved one. I know that other compiler provides this facility by using control directives like "NAKED". Is there any such directive in KEIL compiler so that i can avoid generation of context save and restore by the compiler?

Thank you,
Dhaval Shah

Parents Reply Children
  • "I have no idea about writting ISR in assembly and using it in C program."

    You don't!

    The whole point of an 8051 ISR is that you do not call it from your code - ever!

    An ISR is called directly by the hardware interrupt system - never by your software!

    "An application note or example will be of great help."

    Hmmm... that suggests that you would be far better off using a ready-made RTOS rather than trying to roll your own!! :-0

  • I know my friend that isr will be called by hardware when interrupt will be generated. But there is no example program given in the manual to implement assembler ISR and integrating it in C main program. I dont intend to use the ready made material. Also i dont have that much specific tasks to be done, i dont want to use ready made RTOS.

  • you have evidently cooked up some so called RTOS without starting the design with "how do I handle interrupts". If I am right, I can see no other way to fix it than starting from scratch.

    Erik

  • "But there is no example program given in the manual to implement assembler ISR and integrating it in C main program."

    That's because the compiler isn't involved. You need to create an assembler source file, assemble it and link it into your program.

    This is easily achieved by including it in your project.

    I'm no assembler expert so this could be hopelessly wrong, but I think it is about as simple as this:

    CSEG AT 3 ;Address of interrupt vector
    JMP ISR

    CSEG AT 100 ;Some fairly arbitrary address within your code space
    ISR:
    ;Your code here
    RETI

    END

  • I'm no assembler expert so this could be hopelessly wrong, but I think it is about as simple as this:

    CSEG AT 3 ;Address of interrupt vector
    JMP ISR

    CSEG AT 100 ;Some fairly arbitrary address within your code space
    ISR:
    ;Your code here
    RETI

    it is, with the caveat: you must save (by push/pop and/or register page change) all registers and flags that are used in the ISR. This is done automatically by the compiler, with the assembler, you are on your own. More "lurking" errors have been caused by assembler ISRs not totally saving what they use ( a classic I remember: using CJNE and not saving the CY) than anything else. Then, of course, we have the calling of subroutines that are also used in the main, I think to recall that the linker catch these when in C, but not when the ISR is in assembler.

    Erik

  • "with the caveat: you must save (by push/pop and/or register page change) all registers and flags that are used in the ISR. This is done automatically by the compiler, with the assembler, you are on your own."

    The whole point of this thread is that the OP wants to prevent the context being saved and restored by the compiler.

  • The whole point of this thread is that the OP wants to prevent the context being saved and restored by the compiler.

    I know that, but for normal people the caveat apply.

    Erik

  • "The whole point of this thread is that the OP wants to prevent the context being saved and restored by the compiler."

    Yes, but Erik is right that he still needs to take care of it himself - when the "task" next runs, it needs to have its own context back...!

  • "Yes, but Erik is right that he still needs to take care of it himself - when the "task" next runs, it needs to have its own context back...!"

    Er, the OP is writing a context switcher - don't you think this might have occurred to him?

  • I am writing a task switcher so naturally context switcher will be involved. After replies from all of you i have decided to write the saperate ISR in assembly with its own context save and restore sections and task switching.I am doing it for the first time and i will face some problem but now lets do it. This is the best solution i have.
    Thank you all. Your more suggessions are welcome.

    Dhaval Shah

  • "Your more suggessions are welcome."

    If you are not doing this as an academic exercise my advice would be to think carefully whether a task switcher is really required for your project. If you can avoid using one you will have one less thing to debug.

  • Ya i am now thinking of using a differrent scheme and i think it will work which will not require task switcher.

  • "If you can avoid using one you will have one less thing to debug."

    The thing is that bugs in your task switcher can manifest themselves as very peculiar & bizarre behaviour in your tasks which can be very hard indeed to track down.

    So avoiding a task switcher not only relieves you of denugging the task switcher itself, but also elimitates another source of problems in the rest of your code!