The MASM Forum Archive 2004 to 2012

Specialised Projects => Assembler/Compiler Technology => Topic started by: qWord on June 12, 2009, 11:29:34 AM

Title: warning on SHR and masm 8,9,10
Post by: qWord on June 12, 2009, 11:29:34 AM
hi,

I've discovered that masm (8,9,10) doesn't like negative values (values declared using '-': -1,-2,-3 ...) for shifting with SHR.
If the value was declared using negative sign ('-'), the result is always -1 (0ffffffffh):

; this works with all masm versions
test_value = 0ffffffffh
%echo @CatStr(%(test_value SHR 31))

; wrong result with masm 8,9,10 ,correct with 6 and 7
test_value = -1
%echo @CatStr(%(test_value SHR 31))

; the same with other value
test_value = -123
%echo @CatStr(%(test_value SHR 16))

Is this a known bug?

regards, qWord
Title: Re: warning on SHR and masm 8,9,10
Post by: ToutEnMasm on June 12, 2009, 03:50:23 PM

Not bug .If SHL and SHR exist,it's not to have negative value.Number of shift (32 bits) go threw 31 to 0.Masm can do nothing best.
Title: Re: warning on SHR and masm 8,9,10
Post by: qWord on June 12, 2009, 05:32:37 PM
hi ToutEnMasm ,

Did you mean that SHR should behaves like sar (Shift Arithmetic Right)? -That make no sens to me.
Also: Masm Version 6 and 7 returns the correct value (IMHO)  while Version 8,9 and 10 allways return -1.

EDIT:
I've figured out:

-12345678 SHR 16   ; or (-12345678) SHR 16
is interpreted as:
NOT(12345678 SHR 16)


regards,
qWord
Title: Re: warning on SHR and masm 8,9,10
Post by: Mark Jones on June 13, 2009, 01:23:01 AM
Add yet another layer of abstraction... ::)

How much more can we take, before programming becomes too abstract, too difficult? Already, staying "on top" of this ship is proving difficult, as each ship sinks and is replaced by the next...  </soapbox>
Title: Re: warning on SHR and masm 8,9,10
Post by: ToutEnMasm on June 13, 2009, 05:51:19 AM

I have misanderstood what you are saying. I believe that you want to make a negative shift  .
Here is some tests who explain where is the problem.
Quote
.const
bugtest equ -12345678 SHR 16
.code
start:
   mov eax,-12345678     ;0FF439EB2h correct
   shr eax,16                  ;correct result 0FF43H
   mov ecx,bugtest ;shift.asm(125) : error A2022:instruction operands must be the same size

Make your try without macro.
The generated error seem to be a change in the type of constant
The macro can outpass this problem and made one error.