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 ...
随机推荐
- 蓝桥杯 问题 1117: K-进制数 (递归)
题目链接 题目描述 考虑包含N位数字的K-进制数. 定义一个数有效, 如果其K-进制表示不包含两连续的0. 考虑包含N位数字的K-进制数. 定义一个数有效, 如果其K-进制表示不包含两连续的0. 例: ...
- Ubuntu 查看CPU温度
按照这篇文章: http://www.webupd8.org/2014/06/psensor-updated-with-option-to-display.html
- 安装odbc驱动
1.下载对应的驱动 (32位/64位) http://www.oracle.com/technetwork/database/database-technologies/instant-client/ ...
- Workflow规则收藏
豆瓣电影 查看电影评分等详细信息 查看图片EXIF 图铃机器人 快递查询 翻译 手机号码归属地 音乐视频下载 获取附近的免费WIFI
- linux动态追踪神器——Strace实例介绍【转】
Strace是Linux下一款通用的进程动态跟踪工具,用来追踪程序执行时的系统调用和所接收的信号.其应用方法如下图(部分). 首先,简单说说它的使用参数,Strace的参数包括输出参数.过滤参数.统计 ...
- 【译】Asp.Net Identity与Owin,到底谁是谁?
送给正在学习Asp.Net Identity的你 :-) 原文出自 trailmax 的博客AspNet Identity and Owin. Who is who. Recently I have ...
- 用Java检测远程主机是否能被连接
有人推荐使用java的Runtime.exec()方法来直接调用系统的Ping命令.也有人完成了纯Java实现Ping的程序,使用的是Java的NIO包(native io, 高效IO包).我个人认为 ...
- javaScript对金额处理的方式
例如 var price = $("#price").val(); 此时price 为字符串格式 假使我们想将其乘以100 可以选择 price*100将其转换为数值格式 但是有些 ...
- pyqt5-组件
组件(widgets)是构建一个应用的基础模块.PyQt5有广泛的各式各样的组件,包含:复选按钮(QCheckBox),切换按钮(ToggleButton),滑块条(QSlider),进度条(Prog ...
- Archlinux安装笔记
由于自己的电脑上暂时还没有足够的硬盘空间,所以先暂用虚拟机来装一下Archlinux,在安装好VMware Workstation之后,从Archlinux官网的下载页面下载到了最新的镜像文件.之后新 ...