[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] In line assembly
From: |
Graham Davies |
Subject: |
Re: [avr-gcc-list] In line assembly |
Date: |
Wed, 7 Jul 2004 09:38:39 -0400 |
I'm not an expert, but below your message I have put a function with mixed C
and assembly that is working well for me. You have to go read up on how C
uses the registers, how arguments are passed and results returned and which
registers you can do what with. See FAQ 13 in the avr-libc documentation.
Note that I happen to know that my function waitSpmen() does not trash R24
and R25, otherwise I would not be able to call it where I do. Anyway,
perhaps this will put you on the right track.
Graham.
----- Original Message -----
From: "Dinesh Kumar" <address@hidden>
To: <address@hidden>
Sent: Tuesday, July 06, 2004 11:46 PM
Subject: [avr-gcc-list] In line assembly
Hi Experts,
Im new to GCC for AVR. I need to use C and assembly together. I would like
to know how I can put in line assembly in GCC. Looks like 'pragma' is not
working.
Thanks in advance
Regards
Din
/***************************************************************************
****
* Function readProgramMemory() - read a word (two bytes) from program
memory
* (Flash) at a specified address. The function argument is the byte
address
* from which data is to be read. The function returns the value at that
byte
* address and the one after it packed in little-endian order into an
unsigned
* short integer (16-bit word).
*
* This function is Copyright (C) 2004 Graham Davies, all rights reserved.
*/
static unsigned short readProgramMemory( unsigned short address )
{
register unsigned short result asm( "r24" );
waitSpmen(); /* don't continue until SPMEN is clear */
asm( "MOVW R30, R24" ); /* move address to z pointer (R30,R31) */
asm( "LPM" ); /* read first byte (to R0) */
asm( "MOV R24, R0" ); /* store as least significant byte */
asm( "INC R30" ); /* move up the address by one byte */
asm( "LPM" ); /* read second byte */
asm( "MOV R25, R0" ); /* store as most significant byte */
if ( address >= APP_END )
{
result = 0xAAAA;
}
return ( result );
} /* end of function readProgramMemory() */