在MUL上携带标志大于2^128?

发布于 2025-01-25 01:53:24 字数 359 浏览 2 评论 0 原文

如果以下代码导致大于2^128的东西会产生(输出)吗?

mov rdx, -1 //rdx = 0xff...f
mov rax, -1 //rax = 0xff...f
mov rbx, -1 //rbx = 0xff...f
mul rbx     //result will be bigger than 128 bits therefore will be pushed out of rdx
jc end
...
end: ret

因此,我的问题归结为使用合并的寄存器RAX:rdx用于 mul 操作时的行为。 JC 会在RDX寄存器上自动看柔软,或者在结果大于RAX时触发?

if the following code results in something bigger than 2^128 will it produce a carry (out)?

mov rdx, -1 //rdx = 0xff...f
mov rax, -1 //rax = 0xff...f
mov rbx, -1 //rbx = 0xff...f
mul rbx     //result will be bigger than 128 bits therefore will be pushed out of rdx
jc end
...
end: ret

So my question boils down to how the carry flag behaves when using the combined registers rax:rdx for muloperations. Will jc look automatically soley at the rdx register or also trigger when the result is bigger than rax?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞慾 2025-02-01 01:53:24

请参阅Intel的手册...
如果结果的上半部分(RDX,EDX,DX或AH)为零,则MUL清除CF,则设置为零。

mul 具有两个相同宽度的输入。只有输出是双宽。

CF不用于测量整个事物的溢出,因为两个64位乘法无法导致129位结果,因此在这种意义上是不可能的。

cf实际上表示下半场的溢出。原始8086没有非湿型乘数( imul ecx,esi ),因此您必须使用 mul imul ,即使您没有t关心高半结果。知道结果仍然适合一个寄存器是有用的,尤其是在16位的世界中,比最宽的可用寄存器较大的值比x86-64更为普遍。

Refer Intel's Manual please... https://www.felixcloutier.com/x86/mul#flags-affected
MUL clears the CF if the upper half of the result (RDX, EDX, DX, or AH) is zero, else it's set.

mul has two inputs of the same width. Only the output is double-width.

CF is not used to measure overflow of the whole thing, as two 64 bit multiplicands cannot result into a 129 bit result, so an overflow in that sense is not possible.

CF actually indicates overflow of the low half. Original 8086 didn't have non-widening multiply (imul ecx, esi), so you had to use mul or imul even if you didn't care about the high-half result. Knowing that the result still fit in one register was potentially useful, especially in a 16-bit world where values wider than the widest available register were more common than on x86-64.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文