简体   繁体   English

在汇编 x86 中乘以 3 个数字

[英]multiplying 3 numbers in assembly x86

So here is the numbers所以这里是数字

a = 234234  
b = 2394729  
c = 12323  
a*b*c = 6912302836717278  

but i am getting this result: 3945371358.但我得到了这个结果:3945371358。

I think i have to use LONG because it is over the int's limit but i don't know how,because there is no long in assembly x86, what i have to change?我想我必须使用 LONG,因为它超过了 int 的限制,但我不知道如何,因为装配 x86 中没有 long,我必须改变什么? Thanks in advance提前致谢

%include "io.inc"
section .bss
a resd 1
b resd 1
c resd 1
section .text
global CMAIN
CMAIN:
    mov ebp, esp; for correct debugging
   xor eax,eax
    GET_UDEC 4,a
    GET_UDEC 4,b
    GET_UDEC 4,c
    mov eax,dword[a] 
    mov ebx,dword[b] 
    imul ebx
    mov ecx,dword[c]
    imul ecx
    PRINT_UDEC 4, eax
    xor eax, eax
    ret

It is true that multiplying the two smallest values in your example results in a 32-bit number, but only just.确实,将示例中的两个最小值相乘会得到一个 32 位的数字,但仅此而已。 You can't assume that this will always be the case.你不能假设情况总是如此。 So you have two choices:所以你有两个选择:

  • implement 64x64-bit multiplication by hand, using schoolbook multiplication;使用教科书乘法手动实现 64x64 位乘法;
  • build a 64-bit application.构建一个 64 位应用程序。 Then you can use 64-bit rax etc. instead of 32-bit eax .然后您可以使用 64 位rax等代替 32 位eax

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM