Code: Select all

```
static uint32_t AddCommon(uint32_t a, uint32_t b, uint32_t cin)
{
uint32_t sum = a + (b + cin);
if (b == 0xffffffff && cin == 1)
{
C_FLAG = 1;
F_FLAG = 0;
}
else
{
switch (OpSize.Op[0])
{
case sz8:
{
C_FLAG = TEST(sum & 0x100);
F_FLAG = TEST((a ^ sum) & (b ^ sum) & 0x80);
}
break;
case sz16:
{
C_FLAG = TEST(sum & 0x10000);
F_FLAG = TEST((a ^ sum) & (b ^ sum) & 0x8000);
}
break;
case sz32:
{
C_FLAG = TEST(sum < a);
F_FLAG = TEST((a ^ sum) & (b ^ sum) & 0x80000000);
}
break;
}
}
return sum;
}
```

Code: Select all

```
C_FLAG = TEST(((a & 0xff) + (b & 0xff) + cin) & 0x100);
C_FLAG = TEST(((a & 0xffff) + (b & 0xffff) + cin) & 0x10000);
C_FLAG = TEST(sum < a || sum < b); //this maybe used for all three cases
```

Code: Select all

```
F_FLAG = (a^b)&0x80000000 ? 0 : !!((a^sum)&0x80000000);
```

Code: Select all

```
static uint32_t AddCommon(uint32_t a, uint32_t b, uint32_t cin)
{
uint32_t sum = a + b + cin;
C_FLAG = TEST(sum < a || sum < b);
F_FLAG = TEST((a ^ sum) & (b ^ sum) & 0x80000000);
return sum;
}
```