Ok. Why not start to implementing sh2 asm into z80 core (really need it to speed up the emu). Here is the ADD instruction from z80 emu with x86 asm: #define ADD(value) \ asm ( \ " addb %2,%0 \n" \ " lahf \n" \ " setob %1 \n" /* al = 1 if overflow */ \ " addb %1,%1 \n" \ " addb %1,%1 \n" /* shift to P/V bit position */ \ " andb $0xd1,%%ah \n" /* sign, zero, half carry, carry */ \ " orb %%ah,%1 \n" \ :"=r" (_A), "=r" (_F) \ :"r" (value), "1" (_F), "0" (_A) \ ) What it really do. It's adds "value" to "_A" and sets flags at "_F". In case of flags at "_F" it uses x86 AH register to check is the value overflow/carry/sign/zero. So, here is comments: addb %2,%0 - adds value to 0 (_A) move result to _A lahf - loads AH register with status flags (those flags are very close to Z80 ones which must later be set to _F. So, _F is somewhat like AH). Status flags setted by result of addb %2,%0 (they are SIGN, ZERO, PARITY, OVERFLOW, CARRY) setob %1 - sets _F to 0x01 if the overflow flag is 1. addb %1,%1 addb %1,%1 - so if the _F = 00000001 then we got 00000100 parity/overflow bit^ if the _F = 00000000 (no overflow) - 00000000 parity/overflow bit^ and by this we already have setted Parity/Overflow flag of Z80 register F andb $0xd1, %%ah - check for other flags (sign, zero, half carry, carry) in AH? 0xd1 is the mask of those registers - so if 1=1 then 1?? Not sure about this one.... little addition: adn what?? We check those flags and result placed into memory position of 0xd1 - but what relation it have to _F?? And does this resets overflow bit? orb %%ah,%1 - if overflow flag in AH or in _F = 1 then set it to 1??????? why? And dont we already sets overflow flag in _F (i.e. as i understand this can only check for overflow - because we dont have anything more in _F register) why we do this twice? Or the _previous_ andb function somehow (??? how???) sets _F register with other flags form AH (which choosed by mask 0xd1) ??? And im not sure: is this only sets Parity/Overflow flag to _F (i.e. without settings other flags to _F). I.E. this code always output _F as 0x00 or 0x04 (from overflow bit)?? But what about all other registers (sign/zero/carry/h-carry)? Z80 needs them but why code outputs only overflow bit? Why used two last instructions (logical and, or)? if it no output to F?????????? Btw, if do only output _F as 0x04 (00000100) or 0x00 (00000000) (but i think it's wrong) we can do such code: __asm__ volatile ( \ addv %0,%2 - (add value to _A, place it into_A set T-bit as follows: overflow = 1; not overflow = 0) movt %1 - move overflow bit (1 or 0) to _F shll2 %1 (is this ok - or in case of 32bits regs of sh2 it's totally wrong?) - shift overflow bit to it propertly position in _F Please, if you can help, mail me at sludge@zmail.ru