Author Topic: Comparing a qword (unsigned) to real8  (Read 1106 times)


  • Member
  • *****
  • Posts: 2028
  • beer glass
Re: Comparing a qword (unsigned) to real8
« Reply #30 on: June 23, 2022, 09:34:44 PM »
-Whenever you load an integer onto the fpu, it automatically ALWAYS considers it as a SIGNED integer. Trying to load the qword 264-1 (i.e. FFFFFFFFFFFFFFFF), the fpu would consider it as the value of -1.
so in .data section use signed versions of WORD DWORD etc SWORD SDWORD is useless,but is it only works for .IF macro comparisions ?
SIMD fan and macro fan
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."


  • Member
  • *****
  • Posts: 12691
  • Assembler is fun ;-)
    • MasmBasic
Re: Comparing a qword (unsigned) to real8
« Reply #31 on: June 23, 2022, 10:20:37 PM »
For the record, here the essentials of an optimised version:

Code: [Select]
MyR10 REAL10 9223372036854775808.0 ; 2^63
MyQW QWORD 9223372036854775806 ; 2^63-2
  fld MyR10
  xor esi, esi
fild MyQW
test byte ptr MyQW[7], 128
.if !Zero?
fadd FP4(18446744073709551616.0)  ; translate a negative number to its unsigned equivalent
fcomi ST, ST(1) ; could be fcomip, but we want to print the value
.if Zero?
PrintLine "equal"
.elseif Carry?
PrintLine Str$("ST=%i is smaller than ST(1)", ST(0))
PrintLine Str$("ST=%i is bigger than ST(1)", ST(0))
fstp st
add dword ptr MyQW, 1
adc dword ptr MyQW[4], 0
inc esi
  .Until esi>=5

Code: [Select]
ST=9223372036854775806 is smaller than ST(1)
ST=9223372036854775807 is smaller than ST(1)
ST=9223372036854775809 is bigger than ST(1)
ST=9223372036854775810 is bigger than ST(1)