Re: [avr-gcc-list] in-line assembler
Hi, I don't know what you intended to do but I guess this is more like it (read the value and write it back): I personally prefer the %[] construction. uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld %[reg] , %[adr] \n\t sts %[adr] , %[reg] \n\t : [reg] =r (byte) : [adr] e (ram_address)); return byte; } You're construction of sts %0, __tmp_reg__ is not correct. GCC is trying to feed sts r24 as first argument, which is invalid. You are feeding him the uninitialized variable 'byte'. Which is also allocate to R24. HTH, Wouter Robert von Knobloch schreef: Hello, I've been trying to decipher the intricacies of in-line assembler (using the Inline Assembler Cookbook as my guide). I have a very simple application that I cannot seem to realise. I want a C function that will return the contents of the RAM address that I give it as argument. My assembler-based function looks like this: file is hex.c = uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld __tmp_reg__, %a1\n\t sts %0, __tmp_reg__\n\t : =r (byte) : e (ram_address)); return byte; } and is called from rambyte = get_ram_byte(i ); u_hex8out(rambyte); // Print byte as 8-bit hex. Trying to compile this results in ~/Monitor/hex.c:5: undefined reference to `r24' If I comment out the line sts %0, __tmp_reg__\n\t then it compiles and I see that the parameter is passed in R24,25, copied to R30,31[Z] and the value is read into R0 [__tmp_reg__]. I cannot see what is wrong with the sts command or why R24 is mentioned. Can anybody help me ? Many thanks, Robert von Knobloch. ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
[Fwd: Re: [avr-gcc-list] in-line assembler]
Hi Wouter, thanks for responding. This is not quite what I want, but your comment about the sts is interesting. I want to achieve this: uint8_trambyte; uint16_t ram_address; void get_ram_byte(void) { asm (push R28\n\t push R29\n\t lds r29, ram_address + 1\n\t lds r28, ram_address\n\t ld __tmp_reg__, Y\n\t sts rambyte, __tmp_reg__\n\t pop R29\n\t pop R28::); } Which works but completely ignores the inline-assembler stuff which would do automatic register saving etc. I want to pass a uint16_t address as the argument and get a uint8-t byte returned (which is the contents of the address in ram. Here is the sts that I want to achieve - namely storing the __tmp_reg__ contents into the variable rambyte. Of course this should become the return value (must I store this in a variable first or can the compiler know to return this in whatever the usual register is for a uint8_t () ?. Btw your example compiled OK but did not assemble. Robert Hi, I don't know what you intended to do but I guess this is more like it (read the value and write it back): I personally prefer the %[] construction. uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld %[reg] , %[adr] \n\t sts %[adr] , %[reg] \n\t : [reg] =r (byte) : [adr] e (ram_address)); return byte; } You're construction of sts %0, __tmp_reg__ is not correct. GCC is trying to feed sts r24 as first argument, which is invalid. You are feeding him the uninitialized variable 'byte'. Which is also allocate to R24. HTH, Wouter Robert von Knobloch schreef: Hello, I've been trying to decipher the intricacies of in-line assembler (using the Inline Assembler Cookbook as my guide). I have a very simple application that I cannot seem to realise. I want a C function that will return the contents of the RAM address that I give it as argument. My assembler-based function looks like this: file is hex.c = uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld __tmp_reg__, %a1\n\t sts %0, __tmp_reg__\n\t : =r (byte) : e (ram_address)); return byte; } and is called from rambyte = get_ram_byte(i ); u_hex8out(rambyte); // Print byte as 8-bit hex. Trying to compile this results in ~/Monitor/hex.c:5: undefined reference to `r24' If I comment out the line sts %0, __tmp_reg__\n\t then it compiles and I see that the parameter is passed in R24,25, copied to R30,31[Z] and the value is read into R0 [__tmp_reg__]. I cannot see what is wrong with the sts command or why R24 is mentioned. Can anybody help me ? Many thanks, Robert von Knobloch. ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Re: [avr-gcc-list] in-line assembler
Oke I had some more coffee: uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld %[reg], %a[adr] \n\t st %a[adr], %[reg] \n\t : [reg] =r (byte) : [adr] e (ram_address)); return byte; } I only compiled, not assembled... This compiles and assembles. Note the extra 'a' in front of adr and the st instead of sts HTH, Wouter Wouter van Gulik schreef: Hi, I don't know what you intended to do but I guess this is more like it (read the value and write it back): I personally prefer the %[] construction. uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld %[reg] , %[adr] \n\t sts %[adr] , %[reg] \n\t : [reg] =r (byte) : [adr] e (ram_address)); return byte; } You're construction of sts %0, __tmp_reg__ is not correct. GCC is trying to feed sts r24 as first argument, which is invalid. You are feeding him the uninitialized variable 'byte'. Which is also allocate to R24. HTH, Wouter Robert von Knobloch schreef: Hello, I've been trying to decipher the intricacies of in-line assembler (using the Inline Assembler Cookbook as my guide). I have a very simple application that I cannot seem to realise. I want a C function that will return the contents of the RAM address that I give it as argument. My assembler-based function looks like this: file is hex.c = uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld __tmp_reg__, %a1\n\t sts %0, __tmp_reg__\n\t : =r (byte) : e (ram_address)); return byte; } and is called from rambyte = get_ram_byte(i ); u_hex8out(rambyte); // Print byte as 8-bit hex. Trying to compile this results in ~/Monitor/hex.c:5: undefined reference to `r24' If I comment out the line sts %0, __tmp_reg__\n\t then it compiles and I see that the parameter is passed in R24,25, copied to R30,31[Z] and the value is read into R0 [__tmp_reg__]. I cannot see what is wrong with the sts command or why R24 is mentioned. Can anybody help me ? Many thanks, Robert von Knobloch. ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Re: [Fwd: Re: [avr-gcc-list] in-line assembler]
Many thanks for your help Wouter. No, it's not a pointer to pointer, just: load Y-register with address load temp with what is addressed by Y store temp to my return variable which is done here : lds r29, ram_address + 1\n\t // Load high byte of Y lds r28, ram_address\n\t // Load low byte of Y ld __tmp_reg__, Y\n\t // Fet value at Y into __tmp_reg__ sts rambyte, __tmp_reg__\n\t // Store __tmp_reg__ into named variable 'rambyte'. // It's this last line that I have not yet achieved using the 'proper' syntax. but it is wrong. I seem to have solved my immediate problem but still don't quite understand how to save __tmp_reg__ to a named variable. Just for info, the much simplified: uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld %0, %a1 : =r (byte) : e (ram_address)); return byte; } works fine (I don't really need the temp storage as %0 gets loaded from the Y-reg directly. The declaration and usage of 'byte' is completely discarded by the compiler, it just chooses R24 as %0 and uses that as its uint8_t return: 0666 get_ram_byte: uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld %0, %a1 : =r (byte) : e (ram_address)); 666:fc 01 movwr30, r24 668:80 81 ldr24, Z return byte; } 66a:08 95 ret Anyway, many thanks for your help Wouter, I'll try to figure out storage later. Robert. Wouter van Gulik wrote: Robert von Knobloch schreef: Hi Wouter, thanks for responding. This is not quite what I want, but your comment about the sts is interesting. I want to achieve this: uint8_trambyte; uint16_t ram_address; void get_ram_byte(void) { asm (push R28\n\t push R29\n\t lds r29, ram_address + 1\n\t lds r28, ram_address\n\t ld __tmp_reg__, Y\n\t sts rambyte, __tmp_reg__\n\t pop R29\n\t pop R28::); } Which works but completely ignores the inline-assembler stuff which would do automatic register saving etc. I want to pass a uint16_t address as the argument and get a uint8-t byte returned (which is the contents of the address in ram. So you want a pointer to a pointer? So in C it would be something like this: get_ram_byte(char **pp) { char c; char *p = *pp; c = *p; *p = c; return c; } Here is the sts that I want to achieve - namely storing the __tmp_reg__ contents into the variable rambyte. Of course this should become the return value (must I store this in a variable first or can the compiler know to return this in whatever the usual register is for a uint8_t () ?. You must use a C variable to return the value. Of course you could just tell it to store it to R24 (which is the return register for an uint8_t). But this might will lead to compile warnings and faulty code when GCC decides to inline. So don't use __tmp_reg__ but replace it with the construction from my previous mail. Btw your example compiled OK but did not assemble. Robert Hi, I don't know what you intended to do but I guess this is more like it (read the value and write it back): I personally prefer the %[] construction. uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld %[reg] , %[adr] \n\t sts %[adr] , %[reg] \n\t : [reg] =r (byte) : [adr] e (ram_address)); return byte; } You're construction of sts %0, __tmp_reg__ is not correct. GCC is trying to feed sts r24 as first argument, which is invalid. You are feeding him the uninitialized variable 'byte'. Which is also allocate to R24. HTH, Wouter Robert von Knobloch schreef: Hello, I've been trying to decipher the intricacies of in-line assembler (using the Inline Assembler Cookbook as my guide). I have a very simple application that I cannot seem to realise. I want a C function that will return the contents of the RAM address that I give it as argument. My assembler-based function looks like this: file is hex.c = uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld __tmp_reg__, %a1\n\t sts %0, __tmp_reg__\n\t : =r (byte) : e (ram_address)); return byte; } and is called from rambyte = get_ram_byte(i ); u_hex8out(rambyte); // Print byte as 8-bit hex. Trying to compile this results in ~/Monitor/hex.c:5: undefined reference to `r24' If I comment out the line sts %0, __tmp_reg__\n\t then it compiles and I see that the parameter is passed in R24,25, copied to R30,31[Z] and the value is read into R0 [__tmp_reg__]. I cannot see what is wrong with the sts command or why R24 is mentioned. Can anybody help me ? Many thanks, Robert von Knobloch. ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org
[Fwd: Re: [Fwd: Re: [avr-gcc-list] in-line assembler]]
Thanks Jan, I have reached this conclusion too, I didn't understand the compiler/assembler interaction (and still don't fully, I can't get an sts var, Y to work, but I'll work at it). Btw. I like using silly names for variables, but only in very small demo scripts ;-) Robert Robert, I think you want this: uint8_t get_ram_byte(uint16_t ram_address) { uint8_tbyte; asm (ld %0, %a1\n\t : =r (byte) : e (ram_address)); return byte; } By using the =r constraint you tell the compiler that it shall allocate a register and after the asm routine it shall use its content as the byte variable (which is, btw., a really bad idea for a name of a variable). JW ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Re: [Fwd: Re: [Fwd: Re: [avr-gcc-list] in-line assembler]]
Robert von Knobloch schreef: Thanks Jan, I have reached this conclusion too, I didn't understand the compiler/assembler interaction (and still don't fully, I can't get an sts var, Y to work, but I'll work at it). Is it me or are you looking for st var, Y (note the missing trailing s). HTH Wouter ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
[avr-gcc-list] Strange error in avr-gcc 4.3.3 - relocation truncated to fit: R_AVR_13_PCREL
Hi avr-gcc list I have noticed a strange error (list at bottom of post) , and Jörg adviced me to forward the question here for a 2'nd opinion I just tried to compile uracoli (http://www.nongnu.org/uracoli/index.html) Source : http://download.savannah.nongnu.org/releases/uracoli/uracoli-0.0.10-src.zip Using the new avr-gcc 4.3.3 linux buildscript by the sticky on avr-freaks. I know that script , as i maintain it based on Jörg's freebsd patches. The script builds avr-gcc-4.3.3 w. binutils2.19.1 and then avr-libc-1.6.7 URL: http://www.avrfreaks.net/index.php?name=PNphpBB2file=viewtopict=42631 Source : http://www.avrfreaks.net/index.php?name=PNphpBB2file=downloadid=15350 You might have to register on avrfreaks , in order to download it. I'm using a fully updated Ubuntu 8.10 , and have build avr-gcc with the above mentioned script. In order to build uracoli one must install scons (just an apt-get or synaptic install on ubuntu) http://www.scons.org/ Change to the extracted source and do a make ... Here is the Tail of the console build output. Regards Bingo from AVR Freaks ]) avr-gcc -o build/tiny230/xmpl/xmpl_trx_rxaack.o -c -Wall -Wundef -gstabs -Os -mmcu=attiny84 -Dtiny230 -DBOOT_LOADER_ADDRESS=0x0 -DF_CPU=800UL -Iinstall/inc -Ibuild/tiny230/xmpl/Inc -ISrc/Xmpl/Inc Src/Xmpl/xmpl_trx_rxaack.c avr-gcc -o build/tiny230/xmpl/xmpl_trx_rxaack_tiny230.elf -Wl,-Map=build/tiny230/xmpl/xmpl_trx_rxaack_tiny230.map -mmcu=attiny84 build/tiny230/xmpl/xmpl_trx_rxaack.o -Linstall/lib -lradio_tiny230 -lio_tiny230 Install file: build/tiny230/xmpl/xmpl_trx_rxaack_tiny230.elf as install/bin/xmpl_trx_rxaack_tiny230.elf avr-objcopy -O ihex build/tiny230/xmpl/xmpl_trx_rxaack_tiny230.elf build/tiny230/xmpl/xmpl_trx_rxaack_tiny230.hex Install file: build/tiny230/xmpl/xmpl_trx_rxaack_tiny230.hex as install/bin/xmpl_trx_rxaack_tiny230.hex avr-gcc -o build/tiny230/xmpl/xmpl_radio_stream.o -c -Wall -Wundef -gstabs -Os -mmcu=attiny84 -Dtiny230 -DBOOT_LOADER_ADDRESS=0x0 -DF_CPU=800UL -Iinstall/inc -Ibuild/tiny230/xmpl/Inc -ISrc/Xmpl/Inc Src/Xmpl/xmpl_radio_stream.c Src/Xmpl/xmpl_radio_stream.c: In function 'main': Src/Xmpl/xmpl_radio_stream.c:60: warning: passing argument 1 of 'buffer_stream_init' discards qualifiers from pointer target type Src/Xmpl/xmpl_radio_stream.c:62: warning: assignment from incompatible pointer type Src/Xmpl/xmpl_radio_stream.c:63: warning: assignment from incompatible pointer type Src/Xmpl/xmpl_radio_stream.c:64: warning: assignment discards qualifiers from pointer target type avr-gcc -o build/tiny230/xmpl/xmpl_radio_stream_tiny230.elf -Wl,-Map=build/tiny230/xmpl/xmpl_radio_stream_tiny230.map -mmcu=attiny84 build/tiny230/xmpl/xmpl_radio_stream.o -Linstall/lib -lradio_tiny230 -lio_tiny230 /usr/local/avr-gcc-4.3.3-libc-1.6.7-14-Jun-2009/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr25/crttn84.o: In function `__bad_interrupt': ../../../../../../source/avr-libc-1.6.7/crt1/gcrt1.S:193: relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in /usr/local/avr-gcc-4.3.3-libc-1.6.7-14-Jun-2009/bin/../lib/gcc/avr/4.3.3/avr25/libgcc.a(_exit.o) scons: *** [build/tiny230/xmpl/xmpl_radio_stream_tiny230.elf] Error 1 scons: building terminated because of errors. make: *** [all] Error 2 bi...@t43:~/avr/uracoli-rf-library/uracoli-0.0.10-src$ ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
RE: [avr-gcc-list] Strange error in avr-gcc 4.3.3 - relocationtruncated to fit: R_AVR_13_PCREL
-Original Message- From: avr-gcc-list-bounces+eric.weddington=atmel@nongnu.org [mailto:avr-gcc-list-bounces+eric.weddington=atmel@nongnu. org] On Behalf Of Carsten Sent: Tuesday, August 11, 2009 2:45 PM To: avr-gcc-list@nongnu.org Subject: [avr-gcc-list] Strange error in avr-gcc 4.3.3 - relocationtruncated to fit: R_AVR_13_PCREL Hi avr-gcc list I have noticed a strange error (list at bottom of post) , and Jörg adviced me to forward the question here for a 2'nd opinion I just tried to compile uracoli (http://www.nongnu.org/uracoli/index.html) snip Here is the Tail of the console build output. avr-gcc -o build/tiny230/xmpl/xmpl_radio_stream_tiny230.elf -Wl,-Map=build/tiny230/xmpl/xmpl_radio_stream_tiny230.map -mmcu=attiny84 build/tiny230/xmpl/xmpl_radio_stream.o -Linstall/lib -lradio_tiny230 -lio_tiny230 /usr/local/avr-gcc-4.3.3-libc-1.6.7-14-Jun-2009/bin/../lib/gcc /avr/4.3.3/../../../../avr/lib/avr25/crttn84.o: In function `__bad_interrupt': ../../../../../../source/avr-libc-1.6.7/crt1/gcrt1.S:193: relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in /usr/local/avr-gcc-4.3.3-libc-1.6.7-14-Jun-2009/bin/../lib/gcc /avr/4.3.3/avr25/libgcc.a(_exit.o) scons: *** [build/tiny230/xmpl/xmpl_radio_stream_tiny230.elf] Error 1 scons: building terminated because of errors. make: *** [all] Error 2 bi...@t43:~/avr/uracoli-rf-library/uracoli-0.0.10-src$ Hi Carsten, I don't see the math library being linked in the link command line (-lm). Please try that. @Axel: You probably need to clean up all the warnings too. ;-) Eric Weddington ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list