29.10.2014 Views

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Compiler</strong> Features<br />

/* Declare PSR as a register variable <strong>for</strong> <strong>the</strong> "apsr" register */<br />

register PSR apsr __asm("apsr");<br />

void set_Q(void)<br />

{<br />

apsr.b.Q = 1;<br />

}<br />

See also Example 4-3.<br />

Example 4-3 Clearing <strong>the</strong> Q flag in <strong>the</strong> APSR using a named register variable<br />

register unsigned int _apsr __asm("apsr");<br />

__<strong>for</strong>ceinline void ClearQFlag(void)<br />

{<br />

_apsr = _apsr & ~0x08000000; // clear Q flag<br />

}<br />

Disassembly:<br />

ClearQFlag<br />

MRS<br />

BIC<br />

MSR<br />

BX<br />

r0,APSR ; <strong>for</strong>merly CPSR<br />

r0,r0,#0x80000000<br />

APSR_nzcvq,r0; <strong>for</strong>merly CPSR_f<br />

lr<br />

See also Example 4-4.<br />

Example 4-4 Setting up stack pointers using named register variables<br />

register unsigned int _control __asm("control");<br />

register unsigned int _msp __asm("msp");<br />

register unsigned int _psp __asm("psp");<br />

void init(void)<br />

{<br />

_msp = 0x30000000;<br />

_control = _control | 3;<br />

_psp = 0x40000000;<br />

}<br />

// set up Main Stack Pointer<br />

// switch to User Mode with Process Stack<br />

// set up Process Stack Pointer<br />

Disassembly, compiled using --cpu=7-M:<br />

init<br />

MOV<br />

MSR<br />

MRS<br />

ORR<br />

MSR<br />

MOV<br />

MSR<br />

BX<br />

r0,0x30000000<br />

MSP,r0<br />

r0,CONTROL<br />

r0,r0,#3<br />

CONTROL,r0<br />

r0,#0x40000000<br />

PSP,r0<br />

lr<br />

<strong>ARM</strong> DUI 0375C Copyright © 2007-2008, 2011 <strong>ARM</strong>. All rights reserved. 4-17<br />

ID061811<br />

Non-Confidential

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!