Re: **YIKES**
2008-02-28 by Don Kinzer
--- In AVR-Chat@yahoogroups.com, Tom <tjkeller1@...> wrote: > undefined reference to `r22' > None of R22, R23, R30 or R31 are referenced explicitly > ANYWHERE in this code That's true, but the compiler assigns locally defined variables like 'var1', etc. to registers as it pleases. The problem is that you're insisting on using 'ldi' where you should be using 'mov'. If you go back and check you'll see that I changed it for you in my last reply but you ignored it. The line: " ldi R16, %0 \n" gets expanded to something like: ldi R16, r22 The assembler knows that you can't have a register reference as the second argument to 'ldi' so it assumes that 'r22' is the name of a variable. Since you haven't defined a variable named r22 anywhere it issues the "undefined reference" message. When you encounter error messages like that that you can't comprehend, it is often useful and instructive to examine the .lst file in the area corresponding to the inline assembly code. In this case, it looks something like this: 32 /* #APP */ 33 000c 00E0 ldi R16, r21 34 000e 10E0 ldi R17, r20 35 0010 20E0 ldi R18, r25 36 0012 30E0 ldi R19, r24 37 0014 832F mov r24, R19 38 0016 922F mov r25, R18 39 0018 412F mov r20, R17 40 001a 502F mov r21, R16 Don Kinzer ZBasic Microcontrollers http://www.zbasic.net