NAME MODULENAME .... .... EXTRN CODE (function1) .... .... mov dptr,#0x9000 mov a,@dptr cjne a,#0x02,label1 lcall my_isr_function label: NOP .... .... Is this the correct way to call a C function from assembly?Do I need to save the program status before calling the my_isr_function?
lcall my_isr_function If that ISR indicates that your 'C' function is an Interrupt Service Routine (ISR), why are you trying to call it from assembler? ISRs should only be called by the Interrupt hardware...
Exactly Neil I am trying to call an ISR. Before calling I am checking particular bit of the register related to that ISR ,if it is set then only I am calling that ISR. Cant we call an ISR from assembler routine? We can call an ISR from 'C' right?
http://www.keil.com/support/man/docs/c51/c51_le_interruptfuncs.htm In particular, look at the bullet points at the bottom of that page: "The compiler recognizes direct calls to interrupt functions and rejects them. It is pointless to call interrupt procedures directly, because exiting the procedure causes execution of the RETI instruction which affects the hardware interrupt system of the 8051 chip. Because no interrupt request on the part of the hardware existed, the effect of this instruction is indeterminate and usually fatal..." (my emphasis)
Cant we call an ISR from assembler routine? We can call an ISR from 'C' right? An ISR cannot be "called" regardless of the language used, because it returns with a RETI instead of a RET. Trying to call an ISR is like begging for the program to crash.
"An ISR cannot be 'called'..." Well, it can be called - but that doesn't make it a good idea! You can test whether a mains outlet is "live" by sticking your fingers in it - but nobody in their right mind would attempt to use that technique!
"Before calling I am checking particular bit of the register related to that ISR, if it is set then only I am calling that ISR." But Why? That is entirely pointless! This is exactly what the interrupt hardware does - there is no point in doing it software! If you just want to poll the bit, and call a non-interrupt function, that's fine; but don't call it an ISR - because it is not an ISR!
Hello Mr.Neil and Mr.Franck thanks a lot. My code is working now. The mistake I did was before calling a function I was not saving the accumulator and PSW register contents , after doing that my code got worked. Once again thanks for helping me. Regards Shalini.
after doing that my code got worked You mat think so, but if you are calling an ISR, it is not. It may take as month before it fails, but it will. Erik