Thanks for the help so far, it's appreciated

Moderator: Moderators
Code: Select all
temp = A + val;
if( carry_set )
temp += 1;
V_flag = (temp ^ A) & (temp ^ val) & 0x80;
Code: Select all
V_flag = (A ^ temp) & (A ^ val) & 0x80;
Code: Select all
case ADC:
M=READMEM(rPC+1);
R=M + rA + (fC ? 1 : 0);
fV = (rA^R) & (M^R) & 0x80;
rA = R&0x00FF; /* Copies the LSB of R into the accumulator */
fC = R>>8; /* Stores MSB of result into carry */
STEP(2,2); /* Macro that increases the PC and decreases the cycles */
break;
To my knowledge, casting to an integer data type of smaller size truncates the value by removing the most significant bits. So the result would be predictable.johnnie wrote:What I am kinda uncertain about, is whether moving a 16 bit integer into a single byte yields a predictable result, even when the MSB of the 16-bit integer is zero (as is the case in my operations).
As long as the destination type is unsigned, it just truncates upper bits. If unsigned char is 8 bits on your machine (which it is on almost everything these days),johnnie wrote: What I am kinda uncertain about, is whether moving a 16 bit integer into a single byte yields a predictable result, even when the MSB of the 16-bit integer is zero (as is the case in my operations).