Passing a variable to a specific register in assembly

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 16, 2016 by lpcware
Content originally posted in LPCWare by Danjovic on Sat Aug 03 21:15:19 MST 2013
Let's assume I have an structure of integers called Parameters

struct {
   int HLines;
   int CLines;
} paramters_t;

paremeters_t Parameters;

How do I perform the following instruction using Inline Assembly?

asm([color=#30f]"ldr r3,=&Parameters"[/color]) 

At first glance it might seem a trivial question, but I could not manage to do it even after several trials and errors and after scrutinizing the ethernut tutorial about Inline Assembly

Please notice that I must choose the register instead of letting the compiler choose it.

The reason I am doing that is because I want to access each element of the matrix by simply adding an offset to the LDR/STR instructions.

for example

ldr r0,[r3,#4] [color=#0c0]; load R0 with value CLines using only one instruction[/color]

If one of those values points for example to a peripheral register, I can access the peripheral by using only 2 cycles

for example assuming that the 4th element of the structure contains the address of SSP0_Base Register...

ldr r0,[r3,#010] [color=#090]; load R0 with SSP_0 Base address[/color]
ldr r0,[r0,#00C] [color=#090]; load R0 with the SSP_0 Status Register[/color]

My intention is to use this strategy for saving the use of registers and also instruction cycles on a video generator I am doing using LPC1111/201. Such generator is demanding that part of the code to be hand optimized.

Thanks in advance