Index: ChangeLog =================================================================== RCS file: /cvsroot/avr-libc/avr-libc/ChangeLog,v retrieving revision 1.331 diff -u -u -r1.331 ChangeLog --- ChangeLog 15 Feb 2004 20:04:32 -0000 1.331 +++ ChangeLog 18 Feb 2004 22:53:00 -0000 @@ -1,3 +1,8 @@ +2004-02-18 Joerg Wunsch + + * doc/api/inline_asm.dox: Fix use of _SFR_IO_ADDR() in inline asm. + * doc/api/faq.dox: Ditto. + 2004-02-15 Joerg Wunsch * libc/stdlib/malloc.c: Fix bug #2143 (malloc wrap around top of RAM) @@ -15,7 +20,7 @@ * include/avr/delay.h: Ditto. * include/avr/interrupt.h: Ditto: * include/avr/timer.h: Ditto. - + 2004-02-13 Joerg Wunsch * libc/stdio/vfscanf.c: Apply patch #2554: fix %ul format. Index: doc/api/faq.dox =================================================================== RCS file: /cvsroot/avr-libc/avr-libc/doc/api/faq.dox,v retrieving revision 1.29 diff -u -u -r1.29 faq.dox --- doc/api/faq.dox 18 Oct 2003 20:18:57 -0000 1.29 +++ doc/api/faq.dox 18 Feb 2004 22:53:03 -0000 @@ -354,7 +354,7 @@ assembler. One way to avoid this problem is: \code -asm volatile("sbi %0, 0x07" : "I" (PORTB):); +asm volatile("sbi %0, 0x07" : "I" (_SFR_IO_ADDR(PORTB)):); \endcode \note \c avr/io.h already provides a sbi() macro definition, which can be used Index: doc/api/inline_asm.dox =================================================================== RCS file: /cvsroot/avr-libc/avr-libc/doc/api/inline_asm.dox,v retrieving revision 1.14 diff -u -u -r1.14 inline_asm.dox --- doc/api/inline_asm.dox 8 Sep 2003 22:33:36 -0000 1.14 +++ doc/api/inline_asm.dox 18 Feb 2004 22:53:04 -0000 @@ -95,17 +95,17 @@ Let's start with a simple example of reading a value from port D: \code -asm("in %0, %1" : "=r" (value) : "I" (PORTD) : ); +asm("in %0, %1" : "=r" (value) : "I" (_SFR_IO_ADDR(PORTD)) ); \endcode -Each \c asm statement is devided by colons into four parts: +Each \c asm statement is devided by colons into (up to) four parts: -# The assembler instructions, defined as a single string constant: \code "in %0, %1" \endcode -# A list of output operands, separated by commas. Our example uses just one: \code "=r" (value) \endcode -# A comma separated list of input operands. Again our example uses one - operand only: \code "I" (PORTD) \endcode + operand only: \code "I" (_SFR_IO_ADDR(PORTD)) \endcode -# Clobbered registers, left empty in our example. You can write assembler instructions in much the same way as you would write @@ -116,7 +116,7 @@ The general form is \code -asm(code : output operand list : input operand list : clobber list); +asm(code : output operand list : input operand list [: clobber list]); \endcode In the code section, operands are referenced by a percent sign followed by a @@ -124,7 +124,7 @@ forth. From the above example: \c %0 refers to "=r" (value) and
-\c %1 refers to "I" (PORTD). +\c %1 refers to "I" (_SFR_IO_ADDR(PORTD)). This may still look a little odd now, but the syntax of an operand list will be explained soon. Let us first examine the part of a compiler listing which @@ -150,7 +150,7 @@ avoid this, you can add the volatile attribute to the \c asm statement: \code -asm volatile("in %0, %1" : "=r" (value) : "I" (PORTD) : ); +asm volatile("in %0, %1" : "=r" (value) : "I" (_SFR_IO_ADDR(PORTD))); \endcode The last part of the \c asm instruction, the clobber list, is mainly used to @@ -636,7 +636,7 @@ asm volatile("in %0,%1" "\n\t" "out %1, %2" "\n\t" : "=&r" (input) - : "I" (port), "r" (output) + : "I" (_SFR_IO_ADDR(port)), "r" (output) ); \endcode @@ -855,8 +855,8 @@ "L_%=: " "sbic %0, %1" "\n\t" \ "rjmp L_%=" \ : /* no outputs */ \ - : "I" ((uint8_t)(port)), \ - "I" ((uint8_t)(bit)) \ + : "I" (_SFR_IO_ADDR(port)), \ + "I" (bit) \ ) \endverbatim @@ -864,6 +864,20 @@ usage might create \c L_1405 or whatever. In any case, the labels became unique too. +Another option is to use Unix-assembler style numeric labels. They are +explained in \ref faq_asmstabs. The above example would then look like: + +\verbatim#define loop_until_bit_is_clear(port,bit) \ + __asm__ __volatile__ ( \ + "1: " "sbic %0, %1" "\n\t" \ + "rjmp 1b" \ + : /* no outputs */ \ + : "I" (_SFR_IO_ADDR(port)), \ + "I" (bit) \ + ) +\endverbatim + + \section asm_c_stubs C Stub Functions Macro definitions will include the same assembler code whenever they are @@ -909,7 +923,7 @@ "in %A0,%1" "\n\t" "in %B0,(%1) + 1" : "=r" (result) - : "I" (port) + : "I" (_SFR_IO_ADDR(port)) ); return result; }