Thanks for your quick reply. Actually i implemented addition8bit function by my own. And it looks like this:
Code: Select all
int emulator::arithm_flags8( unsigned char x, unsigned char y, int p )
{
if (((p & 0x100) >> 8) == 1) flags |= 1 ; //cary flag
else flags &= 0xfe ;
p = (unsigned char) p ;
if (parity_flag(p)) flags |= 0x04; //parity flag
else flags &= 0xfb ;
if (((x^y^p) & 0x10) != 0) flags |= 0x10 ; //aux flag
else flags &= 0xef ;
if (p == 0) flags |= 0x40 ; // zero flag
else flags &= 0xbf ;
if (sign(p)) flags |= 0x80 ; // sign flag
else flags &= 0x7f ;
// overflow flag
if ((((x^(~v))&(x^y)) & 0x80) != 0) flags |=0x800 ; // i looked for this function from retro emulator.. but seems // //something don't work correct
else flags &= 0xf7ff ;
}
But find that overflow flag doesn't works correctly. I posted test values in my previous post. Maybe you know why ?
And few tips from you post: Just wrote simple code to check if your solution( A ^ B ^ C) is correct:
Code: Select all
#include <stdio.h>
int main()
{
for (int i=0; i <=1; i++)
{
for (int j=0; j<=1; j++)
{
for (int k=0; k<=1; k++)
{
printf("%d %d %d = %d \n", i, j, k, i ^ j ^ k) ;
}
}
}
}
programs gives:
0 0 0 = 0
0 0 1 = 1
0 1 0 = 1
0 1 1 = 0
1 0 0 = 1
1 0 1 = 0
1 1 0 = 0
1 1 1 = 1
And it's not right as http://intelliwiki.kylesblog.com/index.php/Overflow_Flag logic A ^ C ^ B expression truetable.
And if A ^ B ^C expression good that i'm did wrong ? And can you post overflow check for Subtraction ?
Actually now i looking for simple solution and it's like this:
Code: Select all
if (!sign(a) && !sign(b) && sign(c)) overflow = 1 ;
else if (sign(a) && sign(b) && !sign(c)) overflow = 1 ;
else overflow = 0 ;
Just looked in overflow truetable and write all variations
And one things intel manauls says:
imm8 — An immediate byte value. The imm8 symbol is a signed number
between –128 and +127 inclusive. For instructions in which imm8 is combined
with a word or doubleword operand, the immediate value is sign-extended to
form a word or doubleword. The upper byte of the word is filled with the topmost
bit of the immediate value.
• imm16 — An immediate word value used for instructions whose operand-size
attribute is 16 bits. This is a number between –32,768 and +32,767 inclusive.
I i'm reading imm8 as unsigned char in my emu project. So maybe unsigned/signed problem ? But check all sign's in my arithm_flags8 function and all signs look good. So maybe there's bug in this function if ((((x^(~v))&(x^y)) & 0x80) != 0) ; ?
Thanks again