hi all,
I am on the learning stage of LPC2148 and I have done basic programs like interrupts ... ADC ... TIMER/COUNTER. But all the code I have written is in C Language.
Though I had written some basic progarams of LED in assembly but not the interrupt part.
Could any one here tell me what are the rules to write the assembly code for interrupts i.e. for FIQ, IRQ and NV IRQ.
If possible plz guide me with some source code.
I am using KEIL uvision 4.
Arvind Shrivastava
There is no difference. All you need to make sure is that you do the right thing - namely, acknowledge the interrupt, don't loop etc. - just like in C. Why bother with assembly? time critical stuff? code size? isn't the optimization of the compiler good enough? something?
"Why bother with assembly?"
Be serious.
It is still possible for a proficient writer of assembler to produce faster and smaller code than can be created by the best compilers.
And it's possible for a carpenter or sculptor to do a better job with just a knife than with all the power tools in this world.
A good assembler programmer beats a compiler for most processors. For some processors, the complexity of the processor pipeline is so high that it takes an exceptional assembler programmer - or one with all the time in the world - to keep up.
But an important issue is: Program in assembler to learn assembler? Or program in assembler because it's cool? Or program in assembler because it's needed? Quite a lot of projects manages quite well without any assembler involved, since it's very few times when you get a significant improvement (i.e. where the size or speed difference really matters) from using assembler.
"But an important issue is: Program in assembler to learn assembler? Or program in assembler because it's cool? Or program in assembler because it's needed?"
It is a very useful for an embedded engineer to be aware of what goes on under the hood so they can understand what the compiler is doing and how they might effectively carry out debugging tasks - You just need to look at the numerous posts on this forum regarding 'lost watch variables' and optimizations to see the need for such things.
Unfortunately the want or need to understand assembler seems to be dying and is considered to be terribly un-cool. It often get's the "no-one needs assembler anymore". That's not good for future developments.
But there is a bit of level difference between speaking assembler fluently, and just read it decently. Less people needs to be fully up-to-speed writing in assembler now than 10 years ago.
Guys! ... Please dont argue for which is better 'C'(HLL) or assembly ... I had just asked if some one can guide me for writing interrupt routines in assembly.
No doubt Assembly is the best but requires more exposure and experience then high level language for writing OPTTIMIZED & efficient code.
Hope some some guidance will come out form you all beautifull minds.
The simplest course of action for you to pursuit is:
1. Write it in C, compile with minimum optimization and observe the generated compiler code (see "listing" tab). 2. Have the assembly guide at hand as reference.
S Steve said:
It is a very useful for an embedded engineer to be aware of what goes on under the hood so they can understand what the compiler is doing and how they might effectively carry out debugging tasks.
---
Totally agree with that concept, and not just for programming. If only my wife could be persuaded to understand what was going on "under the hood". She might then have realised that the "funny sound coming from my engine when I go up the hill" was actually an expensive to fix slipping, soon to be burnt out, clutch!
There was no arguing which is best, for the single reason that there can't be any "best" unless you define the criteria for "best".
Is it "best" to have the smallest, fastest, code that gets shipped one week too late? Or that contains a very embarrasing bug because one of the developers didn't know assembler well enough, resulting in a missed register save that wasn't obvious until that interrupt did happen at a very specific position of the main code processing - resulting in the slightly smaller program just happen to remove someones arm?
The debate was about the reason for you to ask for help with assembler. If you asked because you thought you needed assembler or if you did know you needed assembler or just wanted to broaden your knowledge.
But for whatever debate you may enter - always remember that "best" needs to be very well defined way before you start to suggest what is best.
Frogramming forums normally get stuck around: - what is best - HLL or assembler? - which HLL is best? - which processor is best? - which compiler is best? - ...
Almost always without any definition of the grading criteria, so almost always resulting in an epic failure.
Per Westermark said:
-----------------------
Thanx for your reply
Now from my part for the word "BEST" -> Assembly is best in the case of code optimization which obviously results in memory saving and speed.
Hope "BEST" part is descriptive from the above statement.
Now for why I am asking for the assembler code -> Surely I wanted to broaden my knowledge which results in the better understanding of the system.
Now can any body here guide me with small code( like timer interrupt for LED blinking or something like that).
Nowadays say that coding in assembly code is best for speed and size is not true, as the compiler may handle many optimization that you would not be able to do (pipeline, cache, ...). In my opinion, you write assembly code to be deterministic with the code produced (size& speed), or when you no have no high-level language for your device (here the C compiler).
Why don't you specify your needs with speed/code size and try to see if your compiler satisfy these needs ?
If you really want to know how to code this in assembly you can still code it in C and read the listing produced (with the different level optimization).
ohk!
I got the idea what you guys wanted to say about the assembly and HLL and the meaning of BEST also.
As I am on the learning stage so there is no specific need of my application as there is no one presently.
I juz wanted to try my hand on assembly for the interrupt part. As I had already told that I have written the small code for LED blinking in assembly.
I HLL like 'C' I have written the code for interrupt. But I am not getting any concrete idea and hint for writing code in assembly for the interrupts.
I juz know that some changes are to be made in Startup.s file. But what are the changes I am not getting it in a proper manner.
You must READ the above statement clearly.
I juz know that some changes are to be made in Startup.s file. But what are the changes I am not getting it in a proper manner.M
No this is not the case. if you write you interrupt handler like this:
__irq void DAbt_Handler(void) { handle_failure() ; for (;;) ; }
and then
__asm void handle_failure(void) { // assembly code here }
you're done.
You can also write the handler itself directly in assembly, like this:
__asm __irq void DAbt_Handler(void)
Let me reiterate:
There is nothing special about assembly code in interrupts handlers. It is just assembly. Nothing magical or mysterious about it. If you need help with the syntax or instruction set - you must have a look in the assembly guide of the tool chain.
One more thing: Use assembly in interrupt handlers does not require any change to the startup file!