x86 instructions to set parity, overflow, & sign flags

半世苍凉 提交于 2019-12-02 00:07:52

问题


We have the STC instruction to set the carry flag. Do we have similar instructions for parity, overflow, sign flags etc? I have tried STP, STS etc but it seems these don't exist!


回答1:


No, those commands don't exist. The way you find out is by reading the instruction reference manuals carefully.

They don't really need to exist. You can effectively implement them pretty easily. Here's one of many ways, if you don't mind other bits getting set:

STP:  XOR  AL,AL  ; resets parity bit
      XOR  AL,1   ; ... then set parity bit

STO:  OR   AL, 0FFh
      SUB  AL, 080h ; sets overflow

STS:  OR   AL, 0FFh ; sets sign bit

If you insist on setting just the specific bit:

      PUSHFD
      OR    dword ptr[ESP], <bitmask_for_flag_bit> ; see Intel manual
      POPFD

Silicon space being precious, CPU designers tend not to provide instructions for things that are easily done. (STC is left over from 8080 days, where it was useful in doing various kinds of multiprecision arithmetic and not damaging registers was a Very Good Thing).



来源:https://stackoverflow.com/questions/33644649/x86-instructions-to-set-parity-overflow-sign-flags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!