我有一个关于在64位乘法的x86大会实现的问题。我已经发布了代码,只要我能够理解它。我不知道其他人做了什么(也可能是我已经犯了错误)。任何方向将不胜感激。大会:与32位寄存器的64位乘法
dest at %ebp+8
x at %ebp+12
y at %ebp+16
movl 16(%ebp), %esi //Move y into %esi
movl 12(%ebp), %eax //Move x into %eax
movl %eax, %edx //Move x into %edx
sarl $31, %edx //Shift x right 31 bits (only sign bit remains)
movl 20(%ebp), %ecx //Move the low order bits of y into %ecx
imull %eax, %ecx //Multiply the contents of %ecx (low order bits of y) by x
movl %edx, %ebx //Copy sign bit of x to ebx
imull %esi, %ebx //Multiply sign bit of x in ebx by high order bits of y
addl %ebx, %ecx //Add the signed upper order bits of y to the lower order bits (What happens when this overflows?)
mull %esi //Multiply the contents of eax (x) by y
leal (%ecx,%edx), %edx
movl 8(%ebp), %ecx
movl %eax, (%ecx)
movl %edx, 4(%ecx)
2乘以32位值并不能真正算作64位乘法。那么如何移动长度为20(%ebp)的位移动y的任何位,除非y是64位值,但是结果中没有64位位置(dest仅为32位),除非它应该覆盖x ... –
这将带符号的32位整数与带符号的64位整数相乘,产生带符号的64位结果。只需在2^32的基础上在纸上制作出来。 –