I am writing an x86 interpreter in Java and have a Python script that tests my implementations of x86 instructions against its real counterparts using NASM. According to this test all flags are set correctly, besides the carry flag. The interesting part is:
long result;
switch (op) {
case ADD:
result = Math.abs(x) + Math.abs(y);
if (result > U_MAX)
registers.carry_flag = true;
else
registers.carry_flag = false;
break;
where U_MAX is 4294967295L (all 32 bits set).
All answers that I found didn't realize that carry and overflow are two different things. So, how can I implement the carry flag correctly in Java?