https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70677

--- Comment #2 from night_ghost at ykoctpa dot ru ---
all code samples from
https://github.com/night-ghost/minimosd-extra/tree/master/MinimOsd_Extra. When
I try to isolate a piece of code with a bug in one file, it is compiled
differently than in their native place.

Same stack usage in this code:

#include <Arduino.h>

#define SCK_PIN   13
#define MISO_PIN  12
#define MOSI_PIN  11

class SPI
{
  public:
    SPI(void);
     static byte transfer(byte);
};

SPI::SPI()
{
  // initialize the SPI pins
  pinMode(SCK_PIN, OUTPUT);
  pinMode(MOSI_PIN, OUTPUT);
  pinMode(MISO_PIN, INPUT);
}

byte SPI::transfer(byte value){
  SPDR = value;
  while (!(SPSR & (1<<SPIF))) ;
  return SPDR;
}

void MAX_write(byte addr, byte data){
    register byte d=data;
    SPI::transfer(addr);
    SPI::transfer(d);
}

will be 

void MAX_write(byte addr, byte data){
     f06:<----->cf 93       <-->push<-->r28
     f08:<----->df 93       <-->push<-->r29
     f0a:<----->1f 92       <-->push<-->r1
     f0c:<----->cd b7       <-->in<---->r28, 0x3d<----->; 61
     f0e:<----->de b7       <-->in<---->r29, 0x3e<----->; 62
    register byte d=data;
    SPI::transfer(addr);
     f10:<----->69 83       <-->std<--->Y+1, r22<------>; 0x01
     f12:<----->0e 94 e2 2e <-->call<-->0x5dc4<>; 0x5dc4 <_ZN3SPI8transferEh>
    SPI::transfer(d);
     f16:<----->69 81       <-->ldd<--->r22, Y+1<------>; 0x01
     f18:<----->86 2f       <-->mov<--->r24, r22
     f1a:<----->0e 94 e2 2e <-->call<-->0x5dc4<>; 0x5dc4 <_ZN3SPI8transferEh>
}
     f1e:<----->0f 90       <-->pop<--->r0
     f20:<----->df 91       <-->pop<--->r29
     f22:<----->cf 91       <-->pop<--->r28
     f24:<----->08 95       <-->ret

as one can see, "data" variable saved in stack, not in register

Reply via email to