|
有用gcc做arm开发的吗?想问一下使用内联汇编如何进行内存地址操作(如使用ldr、str指令)?我现在可以完成寄存器相关指令的操作,但涉及到内存访问的代码老是编译不过。
如下是一段字符拷贝的简单代码,编译通过。
# lcd.s - An example of String copy
.section .data
srcstr:
.asciz "String Copy Test.\n"
.section .bss
.lcomm dststr, 19
.section .text
.globl _start
_start:
ldr r1, =srcstr
ldr r0, =dststr
loop:
ldrb r2, [r1], #1
cmp r2, #0
beq stop
strb r2, [r0], #1
b loop
stop:
.end
下面是内联汇编代码:
int strcopy(void)
{
char *srcstr = "Good Morning!\n";
char *dststr = "Morning Good!\n";
__asm__("strloop:\n\t"
"ldrb r2, [%1], #1\n\t"
"cmp r2, #0\n\t"
"beq stop\n\t"
"strb r2, [%0], #1\n\t"
"b strloop\n\t"
"stop:\n\t"
".end"
: "=m"(dststr)
: "r"(srcstr), "0"(dststr));
}
编译的出错信息如下:
Error: register expected, not '[fp,#-20]],#1' -- `strb r2,[[fp,#-20]],#1'
arm-elf-gcc扩展asm格式的文档也找不到,有关占位符的constraint定义是否支持x86下的m方式?如何使用,有人做过吗? |
|