10.07.2015 Views

MPLAB® C30 C 编译器用户指南

MPLAB® C30 C 编译器用户指南

MPLAB® C30 C 编译器用户指南

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MPLAB ® <strong>C30</strong> 用 户 指 南例 8-1:C 和 汇 编 混 合 编 程/*** file: ex1.c*/extern unsigned int asmVariable;extern void asmFunction(void);unsigned int cVariable;void foo(void){asmFunction();asmVariable = 0x1234;}文 件 ex2.s 定 义 了 链 接 应 用 程 序 需 要 使 用 的 asmFunction 和 asmVariable。 汇 编文 件 还 说 明 了 如 何 调 用 C 函 数 foo, 以 及 如 何 访 问 C 定 义 的 变 量 cVariable。;; file: ex2.s;.text.global _asmFunction_asmFunction:mov #0,w0mov w0,_cVariablereturn.global _begin_main:call _fooreturn.bss.global _asmVariable.align 2_asmVariable: .space 2.end在 C 文 件 ex1.c 中 , 使 用 了 标 准 的 extern 关 键 字 声 明 了 对 汇 编 文 件 中 定 义 的 符 号的 外 部 引 用 ; 注 意 汇 编 源 文 件 中 的 asmFunction 或 _asmFunction 是 一 个 void 函数 , 进 行 了 相 应 声 明 。在 汇 编 文 件 ex1.s 中 , 通 过 使 用 .global 汇 编 伪 指 令 , 使 符 号 _asmFunction、_main 和 _asmVariable 全 局 可 见 , 并 可 被 任 何 其 他 源 文 件 访 问 。 仅 引 用 了 符 号_main, 未 进 行 声 明 ; 因 此 , 汇 编 器 将 其 视 为 外 部 引 用 。下 面 的 MPLAB <strong>C30</strong> 示 例 展 示 了 如 何 调 用 带 两 个 参 数 的 汇 编 函 数 。 call1.c 中 的 C 函数 main 调 用 call2.s 中 带 两 个 参 数 的 asmFunction。DS51284C_CN 第 96 页© 2005 Microchip Technology Inc.

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

Saved successfully!

Ooh no, something went wrong!