You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Testing with the mos-sim target (or c64 or atari8, but not mos-nes) -Os (others too):
#include<stdint.h>#include<stdio.h>// http://www.6502.org/source/general/SWN.html// this requires noinline or else it gets things wrong/* __attribute__((noinline)) */uint8_tnybbleswap(uint8_tv) {
asm(
// put these is so we can locate the instructions when inline"sei \n cli \n"//"asl \n""adc #$80 \n""rol \n""asl \n""adc #$80 \n""rol \n"
: "+a"(v) : : "a", "p");
returnv;
}
intmain() {
for (auto i=0; i <= 0xfe; i++) {
auto v2=nybbleswap(i);
*(volatilechar*)0x2000=i;
*(volatilechar*)0x2001=v2;
// printf("%x %x\n", i, v2);
}
return0;
}
Accordingly, this is undefined behavior. I think I'd like the compiler to emit a warning for this if that's possible; it appears that there are similar warnings in Clang for other platforms, so it may be a matter of hooking it up. See #385 for this.
I'm bumping #385 up to a P0 due to the number of times this has come up; a bad inline assemble experience may be a serious risk for the project. I'll take a look at this in the near future and see if there's anything we can do about the user experience; but the rules themselves are out of our hands.
Using this code:
Testing with the mos-sim target (or c64 or atari8, but not mos-nes) -Os (others too):
We get the following:
If we uncomment the printf:
There is a missing
txa
at 0x235The text was updated successfully, but these errors were encountered: