Some C instruction disappears when I complie the project, ATtiny416

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

Hi everyone,

 

I'm using the ATtiny416 with the Microhip Studio 7, and I have encountered a problem.

 

When I compile some instruction disappear on the disassembled file, and in fact ther are not executed

 

In particular when copying a value from an array to a global/local variable, and all istruction that use that varible disappear.

 

Example

 

unit8_t array[] = { 1 , 6, 10, 4};
uint8_t ciccio = array[0];

 

There is nothing in the disassembled file...

How can I solve this problem?

 

PS: Usually I code with assembly, but this is a simple project so I decided to use C.

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

Those that are not used by the optimization will be deleted.
If you don't want to be deleted, suppress it.

volatile unit8_t array[] = { 1 , 6, 10, 4};
volatile uint8_t ciccio = array[0];

 

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

As Kabasan says, this will be due to compiler optimisation.

 

See: https://www.avrfreaks.net/forum/tutcoptimization-and-importance-volatile-gcc

 

Although that tutorial focuses on avr-gcc (as used by Microchip Studio), Note that optimisation is a general feature of (pretty much) any compiler for any target.

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

Thanks, now I understand everything!!

 

I knew that the problem it was related to me because I don't know the complier very well.

 

Have a nice day and thank you to the immediate reply laughheart