avra icon indicating copy to clipboard operation
avra copied to clipboard

Improper warning on inversion operator

Open Vov4ick opened this issue 4 years ago • 2 comments

When immediate instruction (ldi, andi, etc) has second operand with inversion operator and MSB of its expression is set, for example, ~(128), this produces constant out of range warning. Result of assembly is correct.

Vov4ick avatar Dec 04 '20 16:12 Vov4ick

I'll look into this more later, but I'm guessing it's because the internal representation of integers is more than 8bits, so when 128 gets inverted, the result isn't 127. For now you could silence the warning by doing low(~128).

Ro5bert avatar Dec 04 '20 17:12 Ro5bert

There's a comment related to this in the usage file:

The expression (~0x80) is a Bitwise Not operation. This operator returns the input expression with all its bits inverted. If 0x80 represents -128, then 0x7f, or +127 should be ok. If this is considered as a 32-bit expression (AVRA internal representation), then it appears to be more like oxffffffff-0x80 or 0xffffffff^0x80. The result would then be 0xffffff7f. The assembler would then have to be told or it would have to decide, based on context, how much significance to assign to the higher bits. I have also encountered such conditions with various assemblers, including AVRA. To make sure the assembler does what I really want, I use a construct like 0xff-0x80 or 0xff^0x80. This way the bit significance cannot extend beyond bit-7 and there cannot be any misunderstanding.

Ro5bert avatar Jan 04 '21 03:01 Ro5bert