例如:我需要别名温度到r16寄存器。在标准atmel`c编译器可以通过.def伪指令来完成:
.def temp=r16
但在AVR-AS(气)它不`吨的工作。
我尝试这样做:
.set temp, r16
#define temp r16
#define temp $r16
这种方法不`吨与登记工作,只能用常量。我想写这样的:
ldi temp,0xff
请帮忙)
#define temp r16
这是我会怎么做它。
但是,如果您使用C预处理指令(如#define
,#ifdef
等),不能直接通过程序来as
但你必须首先调用预处理。
如果您是通过调用as
运行gcc
“间接”,则可以使用文件扩展名.S
(大写的“S”),而不是.s
(小写字母“S”)。这告诉gcc
的汇编文件包含预处理指令。
另外,您可以使用gcc
命令行选项-x assembler-with-cpp
。这告诉gcc
,它应该忽略的文件扩展名并把文件像.S
文件(即使文件名以.c
结束)。
在这里,你有三种选择:
1) gcc -o myFile.o -c myFile.S
2) gcc -o myFile.o -x assembler-with-cpp -c myFile.s
3) cpp -o temporaryFile.s myFile.s
as -o myFile.o temporaryFile.s
人们可以使用注册名额不变。
$ cat t.s
.equiv temp, 16
.text
ldi r16, 0xCC
ldi temp, 0xAA
.end
$ avr-as t.s
$ avr-objdump -d a.out
a.out: формат файла elf32-avr
Дизасемблювання розділу .text:
00000000 <.text>:
0: 0c ec ldi r16, 0xCC ; 204
2: 0a ea ldi r16, 0xAA ; 170
事实上,我用preprocesor的寄存器名称重新定义常量
#define r16 16 // and so on
所以,我可以在宏中使用算术表达式像
//---------------------------------- word add
.macro add_w dst:req, src:req
add \dst, \src $ adc \dst+1, \src+1
.endm