问题描述
我有一点点的8086仿真器和我已经像一个长期的错误2年现在AF无法正常运行子内,并添加说明。
我现在计算其价值的方式是这样的8位数字和加减:
uint8_t有基地= ...,SUBT = ...
基地=基本和放大器; 0xF的;
SUBT = SUBT&放大器; 0xF的; //隔离底部蚕食
如果((int16_t)基SUBT大于7 ||(int16_t)基SUBT&下; -7){
flags.af = 1;
}其他{
flags.af = 0;
}
(假设像子基地的指令,SUBT
)
和添加是这样的:
uint8_t有基地= ...,加法器= ...
基地=基本和放大器; 0xF的;
加法=加法器与放大器; 0xF的; //隔离底部蚕食
如果(基地+加法大于7 ||基地+加法< -7){
flags.af = 1;
}其他{
flags.af = 0;
}
(像指令添加基地,加法器
)
我如何正确计算AF标志在我的模拟器这样的指令?
flags.af =(((基SUBT)及〜0xF的)!= 0);
检查是否上部比特是除零任何东西,这将指示上溢或下溢出在底面4位
下面是一个版本,这是一个有点接近原件。注意,两个4位的量之间的差值不会比15更大同样地,除了将永远不会小于0
flags.af =((int16_t)基SUBT< -15);flags.af =((int16_t)基地+加法器→15);
把周围一个布尔前pression括号是只是一种风格$矿的对$ pference,我知道他们是多余的。
I have a little 8086 emulator and I've had a long standing bug for like 2 years now that AF does not behave properly inside of sub and add instructions.
My current way of computing its value is this for 8 bit numbers and subtraction:
uint8_t base=... , subt=...
base=base&0xF;
subt=subt&0xF; //isolate bottom nibble
if((int16_t)base-subt>7 || (int16_t)base-subt<-7){
flags.af=1;
}else{
flags.af=0;
}
(assuming an instruction like sub base,subt
)
And for adding it's like this:
uint8_t base=... , adder=...
base=base&0xF;
adder=adder&0xF; //isolate bottom nibble
if(base+adder>7 || base+adder<-7){
flags.af=1;
}else{
flags.af=0;
}
(for an instruction like add base,adder
)
How do I properly calculate the AF flag in my emulator for such instructions?
flags.af = (((base-subt) & ~0xf) != 0);
Checks to see if the upper bits are anything except zero, which would indicate an overflow or underflow out of the bottom 4 bits.
Here's a version that's a little closer to your original. Note that the difference between two 4-bit quantities will never be greater than 15. Likewise the addition will never be less than 0.
flags.af = ((int16_t)base-subt < -15);
flags.af = ((int16_t)base+adder > 15);
Putting parentheses around a boolean expression is just a style preference of mine, I know they're redundant.
这篇关于解释AF标志在x86指令是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!