Hi folks,
In the process of adding rounding to divisions performed using right-shifting, I've looked into the generated assembler code.. I've found something strange:
uint16_t t16 = prvMonitoring.Pressure; int32_t pressure = t16; pressure -= prvPressureConfigCurrent.Config.Zero; return pressure >> 16;
generates the following assembler code:
int16_t xPressureGet() { uint16_t t16 = prvMonitoring.Pressure; 9be: 20 91 ec 01 lds r18, 0x01EC 9c2: 30 91 ed 01 lds r19, 0x01ED int32_t pressure = t16; 9c6: 40 e0 ldi r20, 0x00 ; 0 9c8: 50 e0 ldi r21, 0x00 ; 0 pressure -= prvPressureConfigCurrent.Config.Zero; 9ca: 80 91 f4 01 lds r24, 0x01F4 9ce: 90 91 f5 01 lds r25, 0x01F5 9d2: a0 e0 ldi r26, 0x00 ; 0 9d4: b0 e0 ldi r27, 0x00 ; 0 9d6: 28 1b sub r18, r24 9d8: 39 0b sbc r19, r25 9da: 4a 0b sbc r20, r26 9dc: 5b 0b sbc r21, r27 9de: 9a 01 movw r18, r20 9e0: 55 27 eor r21, r21 9e2: 37 fd sbrc r19, 7 9e4: 50 95 com r21 9e6: 45 2f mov r20, r21 return pressure >> 16; 9e8: c9 01 movw r24, r18 9ea: 08 95 ret }
The instructions between 9e0 and 9e8 have no effect on the returned value in r18/19 whatsoever, so why are they generated? they change the value of r20/21 to 0xffff when pressure < 0, but for what reason?
If I remove ">>16", they are not generated.
cheers..
hOOver