Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

assembly - x86 instructions to set parity, overflow, & sign flags

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...