The MASM Forum

General => The Laboratory => Topic started by: jj2007 on May 03, 2016, 09:00:20 PM

Title: Inconsistent assigning of negative constants
Post by: jj2007 on May 03, 2016, 09:00:20 PM
include \masm32\include\masm32rt.inc ; plain Masm32

@signed$ MACRO arg ; returns signed immediate as string (borrowed from MasmBasic)
  if arg lt 0
EXITM @CatStr(<->, %(-arg))
  else
EXITM %arg
  endif
endm

  negnum=80000000h
  echo using 80000000h:
  if negnum lt 0
echo number is negative
  else
echo number is positive
  endif
  tmp$ CATSTR <  TheNumber=>, %negnum
  % echo tmp$
  tmp$ CATSTR <  TheNumber=>, @signed$(negnum)
  % echo tmp$

  echo

  negnum=-2147483648

  echo using -2147483648:
  if negnum lt 0
echo number is negative
  else
echo number is positive
  endif
  tmp$ CATSTR <  TheNumber=>, %negnum
  % echo tmp$
  tmp$ CATSTR <  TheNumber=>, @signed$(negnum)
  % echo tmp$

.code
start:
  exit
  .err <--- ok -->
end start


Output:

using 80000000h:
number is positive
TheNumber=2147483648
TheNumber=2147483648

using -2147483648:
number is negative
TheNumber=2147483648
TheNumber=-2147483648


IMHO 80000000h and -2147483648 should be, ehm, roughly the same ::)
Title: Re: Inconsistent assigning of negative constants
Post by: qWord on May 03, 2016, 10:00:39 PM
MASM constants range from -4294967295 to 4294967295.

See https://sourceforge.net/p/jwasm/bugs/47/
Title: Re: Inconsistent assigning of negative constants
Post by: jj2007 on May 03, 2016, 10:28:03 PM
Quote from: qWord on May 03, 2016, 10:00:39 PM
MASM constants range from -4294967295 to 4294967295.

Good to know, thanks :t
Quotesymbolic constants ( EQU and '=' ) do have 32+1 bits
Title: Re: Inconsistent assigning of negative constants
Post by: nidud on May 03, 2016, 10:58:41 PM
deleted
Title: Re: Inconsistent assigning of negative constants
Post by: jj2007 on May 03, 2016, 11:45:10 PM
> cmp   rax,4294967297      ; Error A2235: Constant value too large: 100000001h

I wonder, though, why the comparison of a "33-bit" number to a 64-bit register should fail ::)
Title: Re: Inconsistent assigning of negative constants
Post by: nidud on May 04, 2016, 12:40:17 AM
deleted