News:

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

Main Menu

Inconsistent assigning of negative constants

Started by jj2007, May 03, 2016, 09:00:20 PM

Previous topic - Next topic

jj2007

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 ::)

qWord

MASM constants range from -4294967295 to 4294967295.

See https://sourceforge.net/p/jwasm/bugs/47/
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

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

nidud

#3
deleted

jj2007

> 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 ::)

nidud

#5
deleted