我有一個關於在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的基礎上在紙上製作出來。 –