C166 Interfacing C to Assembler
Interfacing C to Assembler
You can easily interface your C programs to routines written in XC16x/C16x/ST10 assembly language.
The A166 Assembler is a macro assembler that emits object modules in OMF166 format.
By following a few programming rules, you can call assembly routines from C and vice versa.
Public variables declared in the assembly module are available to your C programs.
There are several reasons to call an assembly routine from your C program.
- You have assembly code already written that you wish to use.
- You need to improve the speed of a particular function.
- You want to manipulate SFRs or memory-mapped I/O devices directly from assembly.
This section describes how to write assembly routines that can be directly interfaced to C programs.
For an assembly routine to be called from C, it must be aware of the parameter passing
and return value conventions used in C functions.
For all practical purposes, the assembly routine must appear to be a C function.
Function Parameters
C functions pass up to five parameters in registers (R8-R12).
Bit parameters are passed in R15.
Parameters that do not fit into R8-R12 are passed on the user stack
and are accessed using [R0+#disp] instructions.
The following examples demonstrate the C166 parameter passing conventions:
void func1 (
char a) /* 1st parameter passed in R8 */
The above function has one argument that easily fits into a single 16-bit register (R8).
void func2 (
int b, /* 1st parameter passed in R8 */
int c, /* 2nd parameter passed in R9 */
int near *d, /* 3rd parameter passed in R10 */
char e, /* 4th parameter passed in R11 */
char f) /* 5th parameter passed in R12 */
The above function has five arguments. All fit into R8-R12.
void func3 (
long g, /* 1st parameter passed in R8/R9 */
int far *h, /* 2nd parameter passed in R10/R11 */
int i, /* 3rd parameter passed in R12 */
long j) /* 4th parameter cannot be located in registers */
The above function has four arguments. The first three use all available registers. The fourth argument must be passed on the user stack.
void func4 (
double k, /* 1st parameter passed in R8/R9/R10/R11 */
long j) /* 2nd parameter LSW passed in R12 */
/* MSW passed on the user stack */
The above function has two arguments. The first argument uses four of the five registers.
The LSW of the second argument is passed in R12 and the MSW is passed on the user stack.
void func5 (
bit m, /* 1st parameter passed in R15.0 */
bit n) /* 2nd parameter passed in R15.1 */
The above function has two bit arguments that passed in R15.
void func6 (
char o, /* 1st parameter passed in R8 */
bit p, /* 2nd parameter passed in R15.0 */
char q, /* 3rd parameter passed in R9 */
bit r) /* 4th parameter passed in R15.1 */
The above function has four arguments (two are bits) that are passed in registers and in R15 (for the bits).
Function Return Values
Function return values are always passed using MCU registers.
The following table lists the possible return values and the registers used for each.
| Return Type | Register | Description |
|---|---|---|
| bit | R4.0 | Single bit returned in R4.0. |
| char, unsigned char |
RL4 | Single byte type returned in RL4. |
| int, unsigned int, near pointer |
R4 | Two byte (16-bit) type returned in R4. |
| long, unsigned long, far pointer, huge pointer |
R4 & R5 | LSB in R4, MSB in R5. |
| float | R4 & R5 | 32-Bit IEEE format. |
| double | R4-R7 | 64-Bit IEEE format. |
Register Usage
Assembler functions may destroy the contents of R1-R12, PSW, MDL, MDH, MDC, and DPP0.
When invoking a C function from assembly, assume that these registers are destroyed.
When using the MAC directive the compiler uses in addition the MAC registers MSW, MAL, MAH, MRW, and IDX0.
When code is generated with the MAC directive, these registers are used by C functions (in addition to the register listed above).
When invoking a C function form assembly you need therefore to assume that these registers are destroyed too.
The following registers have special meaning and must be preserved by the assembler subroutine.
| Register | Description |
|---|---|
| R0 |
R0 is the user stack pointer. |
| R13 |
This register may be used but its contents must be saved (on entry) and restored (before returning). |
| R14 |
This register may be used but its contents must be saved (on entry) and restored (before returning). |
| R15 |
This register may be used but its contents must be saved (on entry) and restored (before returning). |
| DPP1 |
This DPP register may not be modified by assembler subroutines. |
| DPP2 |
This DPP register may not be modified by assembler subroutines. |
| DPP3 |
If DPP3 is modified in the assembler subroutine, it must be reset to 3 (SYSTEM PAGE) before returning. |
Note
- DPP0 is used only when the MOD167 C166 Compiler directive is not specified.
- If your assembler programs alter DPP0, the DPPUSE L166 Linker directive may not be used to assign DPP0 to the near memory area.
- If your assembler programs alter DPP0 or DPP3, the NODPPSAVE C166 Compiler directive may not be used to bypass saving and restoring DPP0 and DPP3 in interrupts.
C166 Interfacing C to Assembler的更多相关文章
- 关于如何在C语言中嵌入汇编命令
转载自:http://www.keil.com/support/docs/2308.htm C51: GETTING INLINE ASSEMBLY TO WORK Information in th ...
- Fixed-point multiplication (C166 A*B/B)
I want to multiply two fixed point numbers. After the multiplication I have to shift the result so t ...
- Assembler : The Basics In Reversing
Assembler : The Basics In Reversing Indeed: the basics!! This is all far from complete but covers ab ...
- Jena TDB 101 Java API without Assembler
Update on 2015/05/12 ongoing tutorials site on https://github.com/zhoujiagen/semanticWebTutorialUsin ...
- Jena TDB assembler syntax
1 introduction Assembler is a DSL of Jena to specify something to build, models and dataset, for exa ...
- Solaris 11 system package 安装与更新(如:assembler)
最近在VirtualBox虚拟机中导入了Solaris 11.3.在里面安装Oracle数据库时,先行条件检查没通过,提示缺少程序包assembler. 在网上看了许多,这方面的信息还比较少.最后在O ...
- More x64 assembler fun-facts–new assembler directives(转载)
原文地址 The Windows x64 ABI (Application Binary Interface) presents some new challenges for assembly pr ...
- x64 assembler fun-facts(转载)
原文地址 While implementing the x64 built-in assembler for Delphi 64bit, I got to “know” the AMD64/EM64T ...
- c166 -div
unsigned short a=10; unsigned short b; unsigned short c;unsigned long d; b = (unsigned short)(d/2400 ...
随机推荐
- 顶 兼容各种浏览器js折叠菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- org-mode
org-mode 编辑 目录 1简介 2扩展 1简介编辑 Org-模式(Org-mode)是文本编辑软件Emacs的一种支持内容分级显示的编辑模式.这种模式支持写 to-do 列表,日志管 ...
- struts 中 s:iterator 使用注意事项
后台定义类 public class Course_pj { private String _id; private String _courseid; private String _course_ ...
- Linux makefile教程之make运行八[转]
make 的运行 —————— 一 般来说,最简单的就是直接在命令行下输入make命令,make命令会找当前目录的makefile来执行,一切都是自动的.但也有时你也许只想让 make重编译某些文件, ...
- 分享一些Comet开发经验
前言 本comet技术主要用于数据库持久层的 穿越防火墙 远程访问.只要有一台中继网站,任意地点的数据库都能被访问. Comet概念介绍 WebIM.网页的客服.meebo等大家听说过了.最近还有个兄 ...
- Delphi VclSkin使用教程
1. TSkinData TSkinData 主要用于美化你的程序, 只要把TSkinData控件放下去,它就能自动美化所有窗体. 属性 Active: 使用或取消对程序的美化. DisableT ...
- 字节顺序重置及“#include <algorith.h>”相关的STL最重要的头文件提醒
这两天在写一个程序,需要将二进制文件中的数据以指定结构读入内存,说明文档中有提到大端序和小端序(Big Endian or Little Endian) 的概念,就找了一下字节顺序重置的算法,在一篇名 ...
- nagios监控linux设置
本章主要用来设置nagios的相关配置文件,从而能实现对linux系统的监控. 在进行监控相关服务的时候,nagios会周期性的调用插件去监测服务器的状态,nagios自带的所有插件都放在如下目录: ...
- JavaScript中,{}+{}等于多少?
最近,Gary Bernhardt 在一个简短的演讲视频“Wat”中指出了一个有趣的 JavaScript 怪癖: 在把对象和数组混合相加时,会得到一些意想不到的结果. 本篇文章会依次讲解这些计算结果 ...
- mapreduce编程模型你知道多少?
上次新霸哥给大家介绍了一些hadoop的相关知识,发现大家对hadoop有了一定的了解,但是还有很多的朋友对mapreduce很模糊,下面新霸哥将带你共同学习mapreduce编程模型. mapred ...