xbyak/sample/no_flags.cpp

26 lines
490 B
C++
Raw Permalink Normal View History

2023-12-26 17:06:48 -07:00
#include <stdio.h>
#include <xbyak/xbyak.h>
struct Code : Xbyak::CodeGenerator {
Code(bool nf) {
xor_(eax, eax); // CF = 0
mov(eax, -1);
if (nf) {
2023-12-26 17:16:06 -07:00
puts("no flags (with T_nf)");
2023-12-26 17:06:48 -07:00
add(eax|T_nf, eax, 1); // does not change CF
} else {
2023-12-26 17:16:06 -07:00
puts("change flags (without T_nf)");
2023-12-26 17:06:48 -07:00
add(eax, eax, 1); // CF = 1
}
adc(eax, 0); // eax = CF ? 1 : 0
ret();
}
};
int main() {
for (int i = 0; i < 2; i++) {
Code c(i);
printf("i=%d ret=%d\n", i, c.getCode<int(*)()>()());
}
}