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
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!
I am not asking for inline assembly ... I am asking for the assembly code from scratch that juz include Startup.s file IN KEIL IDE and no .C file at all.
If I am not wrong while making FIQ program in C I had to make changes in Startup.s file ... although this is not the case for Vectored and non-vectored IRQ ... but ya for FIQ i had to make the changes.
Can anybody gimme the code for 1 second timer interrupt!!!
Hi Arvind Shrivastava,
Try to get a book called "The Defi nitive Guide to the ARM Cortex-M3" written by Joseph Yiu.
It has a lot of assembly example code like the following.
LDR R0, =0xE000ED0C ; Application Interrupt and Reset ; Control Register LDR R1, =0x05FA0500 ; Priority Group 5 (2/6) STR R1, [R0] ; Set Priority Group ... MOV R4,#8 ; Vector Table in ROM LDR R5,=(NEW_VECT_TABLE+8) LDMIA R4!,{R0-R1} ; Read vectors address for NMI and ; Hard Fault STMIA R5!,{R0-R1} ; Copy vectors to new vector table ... LDR R0,=0xE000ED08 ; Vector Table Offset Register LDR R1,=NEW_VECT_TABLE STR R1,[R0] ; Set vector table to new location ... LDR R0,=IRQ7_Handler ; Get starting address of IRQ#7 handler LDR R1,=0xE000ED08 ; Vector Table Offset Register LDR R1,[R1] ADD R1, R1, #(4*(7+16)); Calculate IRQ#7 handler vector ; address STR R0,[R1] ; Setup vector for IRQ#7 ... LDR R0,=0xE000E400 ; External IRQ priority base MOV R1, #0xC0 STRB R1,[R0,#7] ; Set IRQ#7 priority to 0xC0 ... LDR R0,=0xE000E100 ; SETEN register MOV R1,#(1<<7) ; IRQ#7 enable bit (value 0x1 shifted ; by 7 bits) STR R1,[R0] ; Enable the interrupt
But it is not for your LPC2148.
Sir,
Thanx a lot for your kind reply and valuable guidance.
No problem if the code is not for LPC2148 ... i juz wanna 2 know the concept.
thanx once again
It is embarrassing that, for the people who were involved in this thread, I am afraid that, you and me, might be the only two persons, who don't know how to code in assembly.
I think the situation is, for those who know how to code in assembly, they don't need things like tutorial or example code, they just know how to do that; for those who don't know how to code in assembly, the resource is very limited.
And I believe that you already know this, just to remind you once again,
Assembly is very platform dependent, though the general concept should be very similar.
No Problem if I dont know how to code in assembly, atleast I can try my hand.
For the rest of the guys in this forum ... might I am not been able to give them the clear picture of what I wanted to do.
So again I am briefing ...
I wanted to write a simple code in assembly for TIMER Interrupt ... lets say for 1 second and toggle some GPIO thats it.
Now for the concept ... where I am confused or having no idea is ...
how to write the ISR? how to assign the address of the ISR?
Above task is done successfully in c by me ... coz many tutorials are available on net.
But for the assembly ... I am bit confused ... this juz may be the result of lack of my information and concrete knowledge.