Ro5bert / avra

Assembler for the Atmel AVR microcontroller family
GNU General Public License v2.0
153 stars 39 forks source link

Improper warning on inversion operator #26

Open Vov4ick opened 3 years ago

Vov4ick commented 3 years ago

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.

Ro5bert commented 3 years ago

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 commented 3 years ago

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.