1. 前面配置arm交叉编译环境。

2. 配置好qemu-arm

C语言代码string-switch.c:

#include <stdio.h>
#include <stdlib.h>
 
extern void strswp(char *str1, char *str2);
 
int main(void)
{
   char str1[10] = "123456789";
   char str2[10] = "abcde";
  
   strswp(str1, str2);    //调汇编函数
 
   printf("buf1 = %s\nbuf2 = %s\n",str1, str2);
   return 0;
}

汇编代码 switch.S:

	.global strswp
	.type strswp,function
strswp:
   ldrb v1, [a1]
   ldrb v2, [a2]
  
   cmp v1, #0
   cmpne v2, #0
   beq quit
  
   strb v1, [a2], #1 
   strb v2, [a1], #1 
   b strswp
 
quit:
   mov pc, lr
   .end

终端进入到string_switch.c所在的文件夹执行编译命令:

arm-linux-gcc -static string-switch.c switch.S -o string-switch

生成arm可执行文件string-switch

然后终端执行:

qemu-arm string-switch

输出结果:

buf1 = abcde6789
buf2 = 12345

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2021-06-05
  • 2021-07-29
  • 2021-12-29
  • 2022-01-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
  • 2022-02-03
  • 2021-06-17
相关资源
相似解决方案