cancel
Showing results for 
Search instead for 
Did you mean: 

assembler code to set registers

stm322
Associate II
Posted on November 17, 2008 at 06:22

assembler code to set registers

7 REPLIES 7
stm322
Associate II
Posted on May 17, 2011 at 12:52

Hello,

I try to set register in assembler.

I want store the value 0x00000114 in the register address 0x40021014.

I tried the following code,

mov r3, 0x40021014

mov r4, 0x00000114

str r4, [r3]

bit it doesn t work. I ve got a compiling error on the mov instruction.

If somebody can help.

Thanks in advance.

paulsmitton9
Associate III
Posted on May 17, 2011 at 12:52

Hello,

you haven't mentioned which compiling error, or even which compiler you are using.

I'd reccommend that you examine some assembler produced by your c compiler (if you have one) and use that as a guide. GCC seems to like to use decimal constants prefixed with an #. Your assembler may not recognise 0x notation.

stm322
Associate II
Posted on May 17, 2011 at 12:52

Thanks Paul,

I m using Green Hills compiler.

I did copy some examples from their application.

I'm now doing

mov r3, #(1073877012) //0x40021014

mov r4, #(276) //0x00000114

str r4, [r3]

The instruction mov r4 is fine, but for the instruction mov r3, I ve got an ''out of range'' error.

Regarding the mov r4 instruction, I'm not sure the compiler knows it is a 32 bit value to store.

paulsmitton9
Associate III
Posted on May 17, 2011 at 12:52

I think 0x40021014 is too many bits for an immediate value.

You could try storing it nearby, and loading it into the register,

or splitting it up, and adding it in.

i.e.

mov r3, 0x00001014

add r3, 0x00020000

add r3, 0x40000000

(may need slightly different steps)

I think someone else will have a better answer than mine.

picguy
Associate II
Posted on May 17, 2011 at 12:52

Change code to...

ldr r3, =0x40021014

mov r4, 0x00000114

str r4, [r3]

Or better...

baseRCC equ 0x40021000

RCC_AHBENR equ 0x014

; (and other equ's as well)

ldr r3, =baseRCC

movs r4, 0x00000114

str r4, RCC_AHBENR[r3]

the equal sign tells teh assembler to create a literal

ldr finishes the job using a PC relative addressing

I think Cortex has a pair of 32-bit instructions that can load a full 32-bit value in a register. Somebody look and respond to this thread

fastmapper
Associate II
Posted on May 17, 2011 at 12:52

If you can use the Thumb-2 instructions (such as on the ARM Cortex processors), there are additional ways to do this including the following with inline constants:

movw r3, 0x1014

movt r3, 0x4002

movs r4, 0x0114

str r4, [r3]

This sets the least significant 16 bits of r3, then the most significant 16 bits.

... and this trick should work in the case that you only need to store a halfword:

movs r3, 0x0114

movt r3, 0x4002

strh r3, [r3, 0x1014 - 0x0114]

The ARM Cortex also provides bit banding that could be used to set or clear individual bits without disturbing anything else.

stm322
Associate II
Posted on May 17, 2011 at 12:52

Thanks everybody for your help.

It is working now.

fastmapper I did try

movw r3, 0x1014

movt r3, 0x4002

movs r4, 0x0114

str r4, [r3]

but for the instruction ''movs r4, 0x0114'' I ve got a compiling error out of range.

I put this instruction at mov r4, 0x00000114 and it is working.

But everything working fine now. Thanks again.