#11852 - Ribe - Tue Oct 21, 2003 6:56 pm
I just started out with arm asm, and I instantly encountered a problem (surprise, surprise).
For some reason, i can't do an ADD or SUB using two registers and a number, ( ADD r1,r2, value) , or use CMP r,value ... It works just fine when I use registers ( ADD, r1, r2, r3), but I can't imagine it's supposed to be like this? I'm using the AS compiler.
#11853 - poslundc - Tue Oct 21, 2003 7:07 pm
Constants in assembly language can only have eight significant bits. That is to say, 245 (0xF5) would be valid, and so would 62,720 (0xF500), but 62,721 (0xF501) would be invalid, since it cannot be represented by a simple rotation of an eight-bit constant.
To get more than eight significant bits, you need to either manually form your constant in a register (such as by orr-ing the bits together), or load the constant from somewhere local to your code in memory using ldr.
I'm not sure (insofar as I've never had the occasion to try it), but I believe if you prefix your constant with an equal sign (eg. =62,721), then put the directive ".pool" at the end of your code, then the compiler will intelligently determine if it's quicker to just move your constant in or load it from memory (in which case it will be stored at the location .pool). Someone may have to correct me on this, though.
Dan.