01.12.2014 Views

RealView Compilation Tools Developer Guide - ARM Information ...

RealView Compilation Tools Developer Guide - ARM Information ...

RealView Compilation Tools Developer Guide - ARM Information ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

混 合 使 用 C、C++ 和 汇 编 语 言<br />

}<br />

EOR x, r0, x<br />

}<br />

return x;<br />

5.1.5 示 例<br />

示 例 5-2 和 第 5-10 页 的 示 例 5-3 中 示 范 了 一 些 可 以 有 效 使 用 内 联 汇 编 语 言 的 方 法 。<br />

启 用 和 禁 用 中 断<br />

通 过 读 取 CPSR 标 志 并 更 新 第 7 位 , 可 以 启 用 或 禁 用 中 断 。 示 例 5-2 显 示 如 何 使<br />

用 可 以 内 联 的 小 函 数 完 成 此 操 作 。<br />

在 Examples_directory\inline\irqs.c. 中 也 有 此 代 码 。<br />

这 些 函 数 仅 在 特 权 模 式 下 起 作 用 , 因 为 在 “ 用 户 ” 模 式 下 不 能 更 改 CPSR 和<br />

SPSR 的 控 制 位 。<br />

示 例 5-2 中 断<br />

__inline void enable_IRQ(void)<br />

{<br />

int tmp;<br />

__asm<br />

{<br />

MRS tmp, CPSR<br />

BIC tmp, tmp, #0x80<br />

MSR CPSR_c, tmp<br />

}<br />

}<br />

__inline void disable_IRQ(void)<br />

{<br />

int tmp;<br />

__asm<br />

{<br />

MRS tmp, CPSR<br />

ORR tmp, tmp, #0x80<br />

MSR CPSR_c, tmp<br />

}<br />

}<br />

int main(void)<br />

{<br />

<strong>ARM</strong> DUI 0203BSC © 2002、 2003 <strong>ARM</strong> Limited 版 权 所 有 。 保 留 所 有 权 利 。 5-9

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

Saved successfully!

Ooh no, something went wrong!