0

This program reads values from text file and compare or value are greater or not. The problem is that I can't load a constant value as a criteria for ucomisd function. The value in this case are always 0. Can you suggest how to sort out this problem? I searched also other methods how to load the constant value to yasm however it doesn't worked neither.

       global  st_did_suma   
        section .text
;-----------------------------------------------------------------------------
;   double st_did_suma(double* matrica, uint64_t N)
;                         rdi          rsi  
;-----------------------------------------------------------------------------
st_did_suma:
        push rbx
        push r11
        push r8
        push rcx
        push rdx 
        push rbp

        
        mov rax, rsi
        mul rsi
       
        xorpd   xmm0, xmm0      
        cmp     rsi, 0                
        je      .end

        cmp     rsi, 1        
        jnz     .next  
          movsd   xmm0, qword [rdi]     
          jmp   .end


        
  .next:
        add     rdi, 8             
        dec     rsi  
        
        
        movsd   xmm1, qword [rdi]
        mov eax, 100.0                   ; XMM2 VALUE ALLWAYS 0
        movd xmm2, eax
        
        
        ucomisd  xmm1, xmm2    ;         COMPARE FUNCTION
        jb  .else
        mov r10, 1             ;         ANSWER
        cvtsi2sd xmm0, r10
        jnz     .next              
        

   .else:
   subsd xmm1, xmm1
   addsd xmm0, xmm1           ; ANSWER
   jmp .end
   .end:

        pop rbp
        pop rdx 
        pop rcx
        pop r11
        pop r8
        pop rbx
        ret   
    
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
jacob3143
  • 11
  • 2
  • 3
    Interesting; YASM does assemble `mov eax, 100.0` to `mov eax,0x42c80000`, the bit-pattern for an IEEE binary32 float that represents that number. (NASM rejects that syntax.) Then you use that 32-bit value as the bottom of the mantissa for a 64-bit `double` with `ucomisd`, so `0x0000000042c80000` represents a tiny subnormal number, very close to 0 but not equal to it. Anyway, the normal thing is to put FP constants in memory, like compilers do: [How to remove "noise" from GCC/clang assembly output?](https://stackoverflow.com/q/38552116) – Peter Cordes Dec 29 '21 at 20:30
  • 2
    Almost a duplicate of [How to move a floating-point constant value into an xmm register?](https://stackoverflow.com/q/47946389) but that's showing `movss` loads for `float` values, and the whole issue here is that you're mixed up between float and double. – Peter Cordes Dec 29 '21 at 20:36
  • Re: the printing as `0` part: [How to print a single-precision float with printf](https://stackoverflow.com/q/37082784) is an example of using a float bit-pattern as the bottom of a double, but that's a side-note to that question so not a good duplicate. Perhaps [Can we store a floating point in a regular register?](https://stackoverflow.com/q/55623357) is relevant? Hmm, no, not really. – Peter Cordes Dec 29 '21 at 21:12

0 Answers0