Im trying to use several registers on the M4/tm4c1294 in a way to avoid write every time the same register number.
The question is how to make the number of the register and if the reference is correct.
Let say Im working with the RCGCGPIO, so from the data sheet, the RCGCGPIO has the base address
0x400F.E000
and the offset
0x608
so the address to work for would be
0x400FE608
The general view of the assembler code is
RCGCGPIO_ADDRES EQU 0x400FE608 /*Making the mask at start
AREA....CODE
MORE CODE
LDR R1,=RCGCGPIO_ADDRES
ORR R0.....
The reference and the adress is valid?
Best Answer
First off assembly language is defined by the assembler, the program you use to turn the assembly language into machine code. So no reason to assume that gnu assembler vs keil vs arm vs others are the same.
so some gnu assembler code that demonstrates what Elliot was saying...and more.
You can use EQU or .EQU or equivalents to basically do a search and replace in the code. The syntax varies by assembler. AREA and SECTION and such are often not required but if you like/need them go for it.
The first line is like yours, this is pseudo code. The =something means the address of something just like &something in C. The arm instruction set is like mips and some others where there isnt enough room in the encoding for a full sized constant, so it is generally best but there are exceptions to load an immediate you cant fit into the instruction by putting it nearby and doing a pc-relative load. Normally you would use this to load an address of something, but you can, if the assembler supports this, use this to save on typing to load constants of any bit pattern.
The assembler has done this for the first instruction it has turned that into a pc-relative load from address 0x10024 which will put that value into r1, as desired.
The second instruction is more like what this pseudo code was intended for, since we dont know what the address of a label will be when we write the code this is a way to have the assembler both generate the address and place it nearby and generate a pc-relative load. Which it has done the label hello is at address 0x10020, and the instruction generated loaded the value from address 0x10028 into r2.
Without the equals means I want to load the thing at the label hello.
And the fourth one is there to show that at least gnu assembler will create a mov immediate if it can.
Now that we know what the tool is doing we could have just done that ourself.
this solution does the exact same thing with respect to your constant, but it takes more up front code. But you control where you want this word placed rather than the assembler trying to find a place.