News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Adding two 64 bit long numbers in Masm 32

Started by maelirou, March 31, 2016, 09:13:27 AM

Previous topic - Next topic

Mikl__

QuoteWe argue about it because we like arguing...
Benissimo!

jj2007

I love that icon :t Beer & chips for the lurkers, yeah :greensml:

qWord

Mikl__,

your solution is inconvenient because it needs 4 times more memory accesses than the classical approach, beside that the later one is branch-free. Also the results 8th Byte must be zeroed out before going into your code (static initialization does not count in general context).

Quote from: Mikl__ on April 26, 2016, 11:36:36 AMAnd it seemed to me is suitable both for 8-and for 64-bit microprocessors and doesn't depend on length of composed.
If you are interested in portability than you are wrong in using assembler. Your code might (depending on the memory addresses) run in x64, but I don't know any 8 Bit MCU that accept above code. Of course, the algorithm will work with any ISA that allows to add with carry.
MREAL macros - when you need floating point arithmetic while assembling!

raymond

QuoteI thought that it is obvious without explanations

In my opinion, this does not hold in assembly. I strongly believe in my signature "Whenever you assume ..."
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

Mikl__

Hi, qWord!
Quoteyour solution is inconvenient because it needs 4 times more memory accesses than the classical approach, beside that the later one is branch-free. Also the results 8th Byte must be zeroed out before going into your code (static initialization does not count in general context).
maelirou didn't set a task of optimization of the program for speed or the volume occupied in memory. Your answers (at everything to you respect) are maintenance of dispute for the sake of the dispute
QuoteWe argue about it because we like arguing...

TouEnMasm


I will argue with c

;asm call
invoke calcul,OneReal,TwoReal,addr result
// Adding two REAL
int calcul(double truc,double chose,double * presult)
{
*presult = truc + chose;
return 0;
};
;32 bits
_calcul PROC ; COMDAT
; File h:\pratique\math_asm_c\feuille_calcul_c.c
; Line 21
push ebp
mov ebp, esp
sub esp, 64 ; 00000040H
push ebx
push esi
push edi
; Line 22
movsd xmm0, QWORD PTR _truc$[ebp]
addsd xmm0, QWORD PTR _chose$[ebp]
mov eax, DWORD PTR _presult$[ebp]
movsd QWORD PTR [eax], xmm0
; Line 23
xor eax, eax
; Line 24
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
_calcul ENDP

;64 bits
calcul PROC ; COMDAT
mov QWORD PTR [rsp+24], r8
movsd QWORD PTR [rsp+16], xmm1
movsd QWORD PTR [rsp+8], xmm0
push rbp
sub rsp, 64 ; 00000040H
mov rbp, rsp
movsd xmm0, QWORD PTR truc$[rbp]
addsd xmm0, QWORD PTR chose$[rbp]
mov rax, QWORD PTR presult$[rbp]
movsd QWORD PTR [rax], xmm0
xor eax, eax
lea rsp, QWORD PTR [rbp+64]
pop rbp
ret 0
calcul ENDP

Fa is a musical note to play with CL

raymond

QuoteI will argue with c

To continue the argument, which part of your code checks for overflow of 64-bit integers???
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

TouEnMasm

The cool thing with C is that there is just to ask and it is found
http://stackoverflow.com/questions/199333/how-to-detect-integer-overflow-in-c-c
http://stackoverflow.com/questions/15655070/how-to-detect-double-precision-floating-point-overflow-and-underflow
Fa is a musical note to play with CL

raymond

Quotewhich part of your code checks for overflow of 64-bit integers

I was asking about the code you actually posted as examples, and to be more specific when you used floats to perform the addition.
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

TouEnMasm

none
but you have this solution for double
http://forums.codeguru.com/showthread.php?525081-double-overflow-detection
Fa is a musical note to play with CL

qWord

MREAL macros - when you need floating point arithmetic while assembling!