AVR GCC strange behavior : missing code lines when mixing with asm code

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It seems that lines are missing in the disassembly file when using __asm__

 

Here is my code :

int8_t test(uint8_t * data) {
	uint8_t value;
	value=data[0];
	value++;
	value++;
	__asm__(
		"	neg		%[value]"
		: [value] "=r" (value)
	);
	data[1]=value;	// store back elsewhere
	return(0);
} // end of test

 

The value is not loaded and the 2 increments seems to miss also :

00000ff2 <test>:
int8_t test(uint8_t * data) {
	uint8_t value;
	value=data[0];
	value++;
	value++;
	__asm__(
     ff2:	21 95       	neg	r18
		"	neg		%[value]"
		: [value] "=r" (value)
	);
	data[1]=value;	// store back elsewhere
     ff4:	fc 01       	movw	r30, r24
     ff6:	21 83       	std	Z+1, r18	; 0x01
	return(0);
} // end of test
     ff8:	80 e0       	ldi	r24, 0x00	; 0
     ffa:	08 95       	ret

00000ffc <testtest>:

 

I am using gcc version 5.4.0 (AVR_8_bit_GNU_Toolchain_3.6.2_1759)

 

Any idea ?

This topic has a solution.

AVR inside

Last Edited: Sat. Sep 19, 2020 - 11:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

try

 

asm(" neg %0" : "=r" (value) : "0" (value) );

 

You want value to be input and output operand.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Value is input and output :

__asm ("neg %0" : "+r" (value));

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Many thanks to both of you as both works !

I  also found complete explanation of inline asm here : https://www.nongnu.org/avr-libc/...

 

I have another question what's the difference between asm, __asm__ and __asm ??

Which one should be used in "classical" situations ?

The difference is explained between asm and __asm__ but do not find __asm !

 

I also noted that there's a problem with layout of online version of the documentation, the __ seems to be interpreted as bold modifier :

 

 

 

and pdf version (can be found here : https://www.nongnu.org/avr-libc/)

 

I will try to report it !

AVR inside

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As the original question is now answered, please mark the solution - see Tip #5 in my signature (below) for instructions.

 

doomstar wrote:
I have another question

Best to keep to one question per thread - makes it a lot easier for people searching to find answers.

Also makes it easier to see from the thread list what a thread is about.

 

You can always give links to cross-reference between threads.

 

Which one should be used in "classical" situations ?

IMO, inline assembler should generally be avoided:

 

https://www.avrfreaks.net/commen...

 

https://www.avrfreaks.net/commen...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Best to keep to one question per thread -
I totally don't agree but what do I know? I'm only a moderator.