简体   繁体   中英

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.

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? 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. 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;
  • build a 64-bit application. Then you can use 64-bit rax etc. instead of 32-bit eax .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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