What does “set accordingly” in Intel Assembly mean? [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-12-23 13:23:00

问题


Here is what I see in the documentation of Intel x86-64 for the neg instruction that is confusing.

"The OF, SF, ZF, AF, and PF flags are set according to the result."

I'm assuming that sf = dest < 0, zf = dest == 0, but can't figure out how the other flags are set.

I see this "set according to the result" phrase everywhere and would appreciate your help in understanding what it means precisely. I'm working on a compiler so the information is surely important.


回答1:


So all the of the flags are set based off the operation performed, which is what the phrase "set according to the result" means.

3.4.3.1 Status Flags

The status flags (bits 0, 2, 4, 6, 7, and 11) of the EFLAGS register indicate the results of arithmetic instructions, such as the ADD, SUB, MUL, and DIV instructions. The status flag functions are:

  • CF (bit 0) Carry flag — Set if an arithmetic operation generates a carry or a borrow out of the most- significant bit of the result; cleared otherwise. This flag indicates an overflow condition for unsigned-integer arithmetic. It is also used in multiple-precision arithmetic.
  • PF (bit 2) AF (bit 4) Auxiliary Carry flag — Set if an arithmetic operation generates a carry or a borrow out of bit 3 of the result; cleared otherwise. This flag is used in binary-coded decimal (BCD) arithmetic.
  • ZF (bit 6) Zero flag — Set if the result is zero; cleared otherwise.
  • SF (bit 7) Sign flag — Set equal to the most-significant bit of the result, which is the sign bit of a signed integer. (0 indicates a positive value and 1 indicates a negative value.)
  • OF (bit 11) Overflow flag — Set if the integer result is too large a positive number or too small a negative number (excluding the sign-bit) to fit in the destination operand; cleared otherwise. This flag indicates an overflow condition for signed-integer (two’s complement) arithmetic.

Of these status flags, only the CF flag can be modified directly, using the STC, CLC, and CMC instructions. Also the bit instructions (BT, BTS, BTR, and BTC) copy a specified bit into the CF flag.

Only the CF flag can be modified directly. The others are set based on the operations.

Source - Intel



来源:https://stackoverflow.com/questions/40478386/what-does-set-accordingly-in-intel-assembly-mean

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