Hello.
Simulide version 1.0.0, the AVR kernel incorrectly executes the CP instruction, namely, the "S" flag is incorrectly set, which is why the signed comparison does not work correctly. Version 0.4.15-SR10 works correctly. Here is the test (arduino):
Simulide 1.0.0 writes: 64 -64 0 FFFFFF9D
Simulide 0.4.15-SR10 writes: 64 -64 64 FFFFFF8D
Real Arduino writes: 64 -64 64 FFFFFF8D
The bug in the file src/mcusim/cores/avr/avrcore.cpp, line 54:
Simulide version 1.0.0, the AVR kernel incorrectly executes the CP instruction, namely, the "S" flag is incorrectly set, which is why the signed comparison does not work correctly. Version 0.4.15-SR10 works correctly. Here is the test (arduino):
- Code:
void setup() {
Serial.begin(115200);
int8_t a = 64, b = -64;
Serial.print(a);
Serial.print(' ');
Serial.print(b);
Serial.print(' ');
asm volatile(
" cp %0, %1\n"
" brge m1\n"
" ldi %0,0\n"
"m1:\n"
" in %1,__SREG__\n"
: "+r" (a), "+r" (b)
);
Serial.print(a);
Serial.print(' ');
Serial.println(b, HEX);
}
void loop()
{
}
Simulide 1.0.0 writes: 64 -64 0 FFFFFF9D
Simulide 0.4.15-SR10 writes: 64 -64 64 FFFFFF8D
Real Arduino writes: 64 -64 64 FFFFFF8D
The bug in the file src/mcusim/cores/avr/avrcore.cpp, line 54:
- Code:
write_S_Bit( S_S, sn ^ STATUS(S_V) );
- Code:
write_S_Bit( S_S, static_cast<bool>(sn) ^ static_cast<bool>(STATUS(S_V)) );
Last edited by arcachofo on Tue Oct 11, 2022 9:09 pm; edited 1 time in total (Reason for editing : Mark as solved (green color))