关于增量、减量和乘法的一些汇编问题
我面临一些问题,因为我正在学习的 IA-32 汇编电子书中没有明确涵盖这些问题:
1-EFLAGS 寄存器状态部分中的零位是受“INC”(递增)和“Dec”(递减)指令影响的状态位中唯一的位还是奇偶校验位也受到影响?< br> 2-mul(无符号整数乘法)指令会影响EFLAGS寄存器的状态部分吗?
最后还有一句我不知道是否理解清楚:
“IMUL 指令可用于有符号和无符号整数,但必须注意结果不使用目标的最高有效位。对于较大的值,IMUL 指令仅对以下有效:有符号整数。”
我的想法是,当您要使用此指令(具有三种格式)进行无符号整数乘法时,操作数的最高有效位应该为零,因此在这种情况下不使用该位;一旦意图进行有符号整数乘法,操作数自然会使用最高有效位作为符号位,那么我是对的吗?
I'm facing some questions since they're not clearly covered in the IA-32 assembly ebook I'm studying:
1-Is the zero bit in status part of EFLAGS register the only bit among status bits affected by "INC" (increment) and "Dec" (decrement) instructions or the parity bit is affected as well?
2-Does mul (unsigned integer multiplication) instruction affect status part of EFLAGS register?
And finally there's a sentence I'm not sure whether I understand clearly:
"the IMUL instruction can be used by both signed and unsigned integers, although you must be careful that the result does not use the most significant bit of the destination. For larger values, the IMUL instruction is only valid for signed integers."
My conception is that when you're going to use this instruction(that has three formats) for unsigned integer multiplication, the operands ought to have a zero in their most significant bit so no use of that bit in this case; and once the intention is to do signed integer multiplication, operands will use the most significant bit naturally as their sign bit, So am I right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
许多/大多数指令集参考资料会告诉您哪些标志受哪些指令影响,例如:
http://home.comcast.net/~fbui/intel.html
一些参考手册中的每条指令都有该信息,有些手册有一个单独的表格,其目的是显示哪些标志受到影响,而这些手册可能不会告诉您每条指令哪些标志受到影响。
在文档的其他地方,您必须找到字母的含义,大多数处理器指的是 Z、V、N 和 C。我上面链接的参考资料当然使用不同的符号来指示标志,因此您必须找到一个表格来告诉您哪些标志是哪些,然后查找问题中提出的说明。
这涵盖了问题 1 和问题 2。
对于第三个问题,当您回答“从按位角度来看有符号数和无符号数有什么区别”这个问题时,您就会明白了。我发现用 2 或 3 位来思考是最容易的,因为我知道基本概念是可以扩展的。例如,以 3 位来思考,位模式 0b011 如何解释为无符号位模式,如何解释为有符号位模式? 0b111 呢? 0b001 呢?还有0b101?如果使用无符号数,0b011 乘以 0b010 会得到什么?作为有符号的数字?
如果答案还不明显,则写下三位操作数的所有 64 个组合,假设数字被视为无符号来计算结果,然后使用被视为有符号的数字来计算结果。如果您没有犯任何错误,正如相关语句指示的那样,如果两个操作数的高位已设置,那么您将不会在有符号和无符号数学之间得到相同的结果。如果高位清除,您将得到相同的结果。原因来自于理解有符号与无符号的编码或使用另一个术语,二进制补码。
现在尝试一些有趣的 4 位情况(一些设置了高位,一些没有设置)并确定 4 位是否得到与 3 位相同的结果,然后也许使用计算器尝试一些 8 或 16 位数字并决定该规则是否适用于任意位数或是否发生变化。然后确定您所学到的有关 3 位数字的知识是否回答或至少澄清了与 IA-32 IMUL 指令中操作数大小相关的陈述/问题。
Many/most instruction set references will tell you which flags are affected by which instructions, this one for example:
http://home.comcast.net/~fbui/intel.html
Some reference manuals have that info per instruction, some have a separate table whose purpose is to show what flags are affected and those might not tell you per instruction what flags are affected.
Elsewhere in the documentation you will have to find what the letters mean, most processors refer to Z,V,N,and C. The reference I linked above of course uses different symbols to indicate the flags, so you have to find a table to tell you which flags are which, and then look up the instructions asked in the question.
That covers questions 1 and 2.
For the third question, the understanding will come when you answer the question "what is the difference from a bitwise perspective between signed and unsigned numbers". I find it easiest to think in terms of 2 or 3 bits, knowing that the basic concepts scale up. So for example thinking in terms of 3 bits, how is the bit pattern 0b011 interpreted as an unsigned bit pattern, how is it interpreted as a signed bit pattern? What about 0b111? What about 0b001? And 0b101? And what does a 0b011 times 0b010 give you if done using unsigned numbers? As signed numbers?
If the answer is not apparent yet then write down all 64 combinations of three bit operands, compute the result assuming the numbers are considered unsigned, next to that compute the result with the numbers considered as signed. If you have made no mistakes as the statement in question indicates if the upper bit on either of the operands is set then you wont get the same result between the signed and unsigned math. If the upper bit is clear you will get the same results. The reason comes from understanding the encoding of signed vs unsigned or to use another term, twos complement.
Now try a few interesting 4 bit cases (a few with an upper bit set and a few without) and decide if you get the same results for 4 bit as you did with 3, then perhaps with a calculator try some 8 or 16 bit numbers and decide if the rule applies for any number of bits or if it changes. Then decide if what you learned about 3 bit numbers answers or at least clarifies the statement/question relative to the size of the operands in the IA-32 IMUL instruction.
1) 否,受影响的标志是 O、S、Z、A 和 P。
2) 是的,预测(有用)标志是 O 和 C,但标志 S、Z、A 和 P 在 IMUL 指令之后是不可预测的。
3) 是的,最后一位 (MSB) 是符号,如果符号为 0,则数字为正数,因此两种数字类型的除法算法相同。
1)No, efected flags are O,S,Z,A and P.
2)Yes, predicted (usefull) flags are O and C, but flags S,Z,A and P are after IMUL instruction unpredicted.
3) Yes, last bit (MSB) is sign, if sign is 0 then number is positive so division algorithem is the same for both numbers types.