IAR EWAR 内联汇编 调用外部函数 Error[Og005], Error[Og006]
How do I call a C function in another module from inline assembler in IAR EWARM?
I have a bit of assembly in a hard fault handler.
The assembly is basically meant to pass the current stack pointer as a parameter (in R0). It looks like so...
__asm(" mov r0, sp\n"
" bl SavePC\n"
" bx lr");
This works fine when SavePC is in the same c file.
However, when SavePC is placed in another c file I have no luck.
I have tried to IMPORT the function like so...
__asm("IMPORT SavePC\n"
" mov r0, sp\n"
" bl SavePC\n"
" bx lr");
... but I must be doing something incorrect. The compiler reports the following...
Error[Og005]: Unknown symbol in inline assembly: "IMPORT"
Error[Og005]: Unknown symbol in inline assembly: "SavePC"
Error[Og006]: Syntax error in inline assembly: "Error[54]: Expression can not be forward"
Error[Og005]: Unknown symbol in inline assembly: "SavePC"
Error while running C/C++ Compiler
The c file with the assembly includes the header file with the SavePC prototype...
extern void SavePC(unsigned long);
Suggestions?
Your code won't work even with a correct call.
bl _SavePC // LR be changed
bx lr // while (1){}
What do you think will be the value in the LR
register in the bx lr
instruction?
The address of the instruction itself!
The bl
instruction has put it there. This is effectively a while (1);
with a bx instruction.
A nested function call looks more like this:
push {lr}
bl _SavePC
pop {pc}
To get the stack register one uses the corresponding CMSIS functions:
__get_MSP()
for the Main Stack Pointer (MSP)__get_PSP()
for the Process Stack Pointer (PSP)
Using extern is a bad habit since it is prone to errors. C-99 standard provides an safe alternative for extern. You should write the function prototype in the header file without extern keyword. Then include the header file in both C files. The linker is then responsible for linking the function in different files.
Example:
File : custom_header.h
void SavePC(unsigned long);
File : source_c_file.c
#include "custom_header.h" void SavePC(unsigned long)
{
....
.... .... }
File : user_c_file.c
#include "custom_header.h" void someFunction(void)
{
.
.
. __asm("mov r0, sp\n"
" push {lr}
" bl SavePC\n"
" pop {pc}"); .
.
.
}
IAR EWAR 内联汇编 调用外部函数 Error[Og005], Error[Og006]的更多相关文章
- IAR EWAR 内联汇编 Error[Og010], Error [Og005], Error [Og006]
Error [Og005] + [Og006] when using inline assembler EW targets: 430, ARM, AVR EW component: C/C++ co ...
- gcc 在c代码中内嵌汇编调用c函数: 只是证明曾经我来过
我怕我不写下来,将来我都不记得我还在 c 中嵌套过汇编语言,用汇编代码调用一个c函数的过程. 折腾了一下午,在网上查看相关的资料,然后照葫芦画瓢地在c代码中嵌套汇编,希望解决我所遇到的问题,可最后发现 ...
- x64内联汇编调用API(需intel编译器,vc不支持x64内联汇编)
#include "stdafx.h" #include <windows.h> STARTUPINFOW StartInfo = {0}; PROCESS_INFO ...
- 在Visual C++中使用内联汇编
一.内联汇编的优缺点 因为在Visual C++中使用内联汇编不需要额外的编译器和联接器,且可以处理Visual C++中不能处理的一些事情,而且可以使用在C/C++中的变量,所以非常方便.内联汇编主 ...
- GNU C内联汇编(AT&T语法)
转:http://www.linuxso.com/linuxbiancheng/40050.html 内联汇编提供了可以在C或C++代码中创建汇编语言代码,不必连接额外的库或程序.这种方法对最终程序在 ...
- C语言中递归什么时候能够省略return引发的思考:通过内联汇编解读C语言函数return的本质
事情的经过是这种,博主在用C写一个简单的业务时使用递归,因为粗心而忘了写return.结果发现返回的结果依旧是正确的.经过半小时的反汇编调试.证明了我的猜想,如今在博客里分享.也是对C语言编译原理的一 ...
- 通过调用C语言的库函数与在C代码中使用内联汇编两种方式来使用同一个系统调用来分析系统调用的工作机制
通过调用C语言的库函数与在C代码中使用内联汇编两种方式来使用同一个系统调用来分析系统调用的工作机制 前言说明 本篇为网易云课堂Linux内核分析课程的第四周作业,我将通过调用C语言的库函数与在C代码中 ...
- VC++线程函数内怎么调用外部函数
VC++线程函数内怎么调用外部函数 1.把外部函数做成静态函数,就可以直接调用了.2.把外部函数所在的对象通过线程函数参数传到线程里面来,这样线程里可以使用此对象及其函数了.
- 最牛X的GCC 内联汇编
导读 正如大家知道的,在C语言中插入汇编语言,其是Linux中使用的基本汇编程序语法.本文将讲解 GCC 提供的内联汇编特性的用途和用法.对于阅读这篇文章,这里只有两个前提要求,很明显,就是 x86 ...
随机推荐
- 使用Cobbler批量部署Linux和Windows:CentOS/Ubuntu批量安装(二)
通过前面服务端的部署,已经配置好了 Cobbler Server 端,接下来开始进行 CentOS/Ubuntu 的批量安装,在进行 CentOS/Ubuntu 批量安装时,也需要通过Cobbler来 ...
- spring的普通类中获取session和request对像
在使用spring时,经常需要在普通类中获取session,request等对像. 1.第一钟方式,针对Spring和Struts2集成的项目: 在有使用struts2时,因为struts2有一个接口 ...
- 清理电脑文件夹中的Thumbs.db文件
@echo off del f:Thumbs.db /f/s/q/a exit 对应修改磁盘号, 保存批处理文件执行即可
- Oracle 数据库和监听器开机自启动两种实现方法
数据库和监听器开机自启动 编辑oratab文件: 修改:orcl:/u01/app/oracle/product/11.2.0/db_1:N orcl:/u01/app/or ...
- java 内部类使用 .this 和 .new
如果需要生成对外部类对象的引用,可以使用外部类的名字后面紧跟圆点和this,这样产生的引用自动地具有正确的类型,这一点在编译器就被知晓并受到检查,因此并没有运行时开销 //: innerclasses ...
- MySQL的架构模型
看到大牛用户DB架构部的Keithlan<数据库性能优化之查询优化>,在学习过程发现很多不错的东西,就把它保存下来,分享给大家,因为作者说了一句很经典的话:“if you want to ...
- 常用的 Windows 键
常用的 Windows 键 Windows 键 + 空格键 功能:透明化所有窗口,快速查看桌面.使用此快捷键可以立即将目前所有打开的窗口透明化,以便查看桌面. Windows 键 + 字母键“D” ...
- 《MySQL技术内幕 InnoDB存储引擎 》学习笔记
第1章 MySQL体系结构和存储引擎 1.3 MySQL存储引擎 数据库和文件系统最大的区别在于:数据库是支持事务的 InnoDB存储引擎: MySQL5.5.8之后默认的存储引擎,主要面向OLTP ...
- hdu 5038 (2014北京网络赛G 排序水题)
题意:有n个数字,带入10000 - (100 - ai) ^ 2公式得到n个数,输出n个数中频率最大的数,如果有并列就按值从小到大都输出输出,如果频率相同的数字是全部的n个数,就输出Bad....题 ...
- A Connection to the remote computer could not be established
Go to device manager: uninstall WAN Miniport (IP), Wan Miniport(IPv6) and Wan Miniport (PPTP). Refre ...