We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi All,
Please bear with me, I'm new to ARM/Assembly and just trying to get to grips with how to use it.
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
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)
Any advice would be much appreciated!
If the DCD is defined in the code section, then it is likely that the value resides in read-only memory. You need to ensure that the global variable is in an area that the linker places in RAM, for example:
; // Code located in flash/ROM code section AREA ||.text||, CODE, READONLY EXPORT main ; // Read value of "global_value" into R0 get_global_value PROC LDR r1,=global_value LDR r0,[r1] BX lr ENDP ; // Set value of "global_value" to that in R0 set_global_value PROC LDR r1,=global_value STR r0,[r1] BX lr ENDP ; // Simple main loop that just gets, increments and sets main BL get_global_value ADDS r0,r0,#1 BL set_global_value B main ALIGN LTORG ; // Global variable located in RAM data section AREA ||.data||, DATA global_value DCD 0 END
hth
Simon.