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 />

return s.i * 3;<br />

/* can change 's' */<br />

从 汇 编 语 言 调 用 C++<br />

示 例 5-18 和 示 例 5-19 显 示 如 何 从 汇 编 语 言 调 用 C++。<br />

示 例 5-18 定 义 被 调 用 的 C++ 函 数<br />

struct S {<br />

// has no base classes or virtual functions<br />

S(int s) : i(s) { }<br />

int i;<br />

};<br />

extern "C" void cppfunc(S * p) {<br />

// Definition of the C++ function to be called from ASM.<br />

// The body is C++, only the linkage is C<br />

p->i += 5;<br />

}<br />

在 <strong>ARM</strong> 汇 编 语 言 中 , 输 入 C++ 函 数 名 并 使 用 带 有 链 接 指 令 的 “ 跳 转 ” 调 用 它 :<br />

示 例 5-19 定 义 汇 编 语 言 函 数<br />

AREA Asm, CODE<br />

IMPORT cppfunc<br />

; import the name of the C++<br />

; function to be called from Asm<br />

f<br />

EXPORT<br />

f<br />

STMFD sp!,{lr}<br />

MOV r0,#2<br />

STR r0,[sp,#-4]! ; initialize struct<br />

MOV r0,sp ; argument is pointer to struct<br />

BL cppfunc ; call 'cppfunc' so it can change<br />

; the struct<br />

LDR r0, [sp], #4<br />

ADD r0, r0, r0,LSL #1<br />

LDMFD sp!,{pc}<br />

END<br />

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

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

Saved successfully!

Ooh no, something went wrong!