cancel
Showing results for 
Search instead for 
Did you mean: 

Setting up a 'global variable' using DCD

lo0446
Associate II
Posted on March 26, 2014 at 15:08

I have a jump table currently set-up like this

ProcTable

 DCD Proc1

 DCD Proc2

 DCD Proc3

EndTable

Another part of my program that is acting as a processes manager which needs to keep track of the number of the process so it can calculate a stack pointer (PSP) for it so that each program has it's only section of the stack. I'm trying to use some sort of 'global variable' like this 

''ProcCount DCD 0'' 

I then want to increment the value stored in ProcCount although I'm having trouble getting this to work, most examples I can find involve reading the value of ProcCount but never writing/updating the other way. I was trying to do something like this:

 LDR r2,=ProcCount

 ADD r4,r4,#1

 STR r4, [r2]

 NOP

 LDR r5,ProcCount

 NOP

I'm trying to add #1 to ProcCount then reading it back into r5 to check that it has changed (Nothing changes r5 stays at 0x0)

5 REPLIES 5
Posted on March 26, 2014 at 18:12

 LDR r2,=ProcCount

 LDR r4, [r2]

 ADD r4,r4,#1

 STR r4, [r2]

 NOP

 LDR r5,ProcCount

 NOP

Might want to ensure that ProcCount is placed in a RAM/DATA section
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lo0446
Associate II
Posted on March 26, 2014 at 19:44

Hi Clive that's great,

I still don't get anything back into r5 when loading from ProcCount. I'm in Handler mode with Privilege using the MSP stack. Maybe the way I have set it up means I can't write back to it. How would I ensure it is placed in the RAM/DATA section as you mentioned?

Thanks!

lo0446
Associate II
Posted on March 26, 2014 at 20:05

I've just realised when fetching the address for ProcCount its in the 0x8 range which I believe is ROM, I know 0x2 is RAM. How do ensure ProcCount is in RAM so I can write back to it?

Thanks!

Posted on March 26, 2014 at 20:36

;...
AREA |.data|, DATA, READWRITE, ALIGN=3
ProcCount DCD 0
;...
AREA |.text|, CODE, READONLY

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lo0446
Associate II
Posted on March 26, 2014 at 21:23

Great thanks Clive, I had just about figured out what you were getting at after looking through the ARM setup files but couldn't quite get it working, your example worked.

I get an error ''.\file.axf: Error: L6286E'' when running the program now. If I comment out the line from the example given earlier ''LDR r1, ProcCount'' the error goes away, which I did to be able to run the program to try to debug it.

When loading the address into r2 I now get something in the 0x2 range which is great.

However when we get to ''LDR r4, [r2]'' I get ''0x2A001E52'' which I'm not expecting. Shouldn't [r2] dereference the address, which I think should have ''0'' in from our DCD instruction earlier. I'm in Thread mode, privileged, MSP if that makes a difference.

Thanks