I guess I just don't understand signed numbers in asm like I thought I did. Why doesn't this if block work?

In my code, the MessageBox never gets executed.

```
```

dwSomeNumber DWORD ?

mov dwSomeNumber, -10

.IF dwSomeNumber<0

invoke MessageBox, ...

.ENDIF

In my code, the MessageBox never gets executed.

Try this, a signed DWORD is an SDWORD

You can also cast it from a regular DWORD like this

```
dwSomeNumber SDWORD ?
```

mov dwSomeNumber, -10

.IF dwSomeNumber<0

invoke MessageBox, ...

.ENDIF

You can also cast it from a regular DWORD like this

```
dwSomeNumber DWORD ?
```

mov dwSomeNumber, -10

.IF SDWORD PTR dwSomeNumber<0

invoke MessageBox, ...

.ENDIF

So this would make the SDWORD range -2147483648 to 2147483648 right?

Hi RDaneel,

Something like that:

-(2^31) to + (2^31)-1

-2147483648 to 2147483647

Something like that:

-(2^31) to + (2^31)-1

-2147483648 to 2147483647

If you're using MASM32, the use of the "<" and ">" in an IF statement unfortunately only gets replaced by a

(I don't know how other assemblers treat such IF statements.)

Raymond

**jc**or a**jnc**instruction. That negates comparing negative numbers which would need the "jl" or "jg" instructions.(I don't know how other assemblers treat such IF statements.)

Raymond

rdaneel,

The default interpretation for .IF statements in MASM for memory contents is unsigned. Unsigned numbers can never be interpreted by the CPU as negative, only positive. That means the assembler will use conditional jumps like JA, JAE, JB, JBE, etc. If you want the number to be interpreted as signed, then it needs to use instructions like JG, JGE, JL, JLE, etc. Donkey showed you how to direct MASM to interpret the number as signed. Unsigned numbers have a positive range twice as large as signed numbers because they have one more bit to use for their magnitude. Ratch

The default interpretation for .IF statements in MASM for memory contents is unsigned. Unsigned numbers can never be interpreted by the CPU as negative, only positive. That means the assembler will use conditional jumps like JA, JAE, JB, JBE, etc. If you want the number to be interpreted as signed, then it needs to use instructions like JG, JGE, JL, JLE, etc. Donkey showed you how to direct MASM to interpret the number as signed. Unsigned numbers have a positive range twice as large as signed numbers because they have one more bit to use for their magnitude. Ratch

Is it the high-order bit that is used as the sign bit?

For intel, it's the 31th bit.

rdaneel ,

Yes, that is true IF the number is interpreted as a signed number. If it is interpreted as a unsigned number, then all the bits of the word are used to represent a positive or zero number. There is no negative representation for unsigned numbers. If is important that you know for sure what the method of comparision between two numbers is going to be. Otherwise your results are not going to happen according to your expectations. Ratch

Is it the high-order bit that is used as the sign bit?

Yes, that is true IF the number is interpreted as a signed number. If it is interpreted as a unsigned number, then all the bits of the word are used to represent a positive or zero number. There is no negative representation for unsigned numbers. If is important that you know for sure what the method of comparision between two numbers is going to be. Otherwise your results are not going to happen according to your expectations. Ratch