在ARM的程序框架下,写一个内嵌的汇编程序,实现strcat的功能
发布网友
发布时间:2022-05-06 21:34
我来回答
共3个回答
热心网友
时间:2023-09-20 19:50
#define U8 unsigned char
#include <string.h>
#include <stdio.h>
#define TRUE 1
#define FALSE 0
//#pragma import(__use_no_semihosting_swi) // ensure no functions that use semihosting
void my_strcat(const char* str1, const char* str2)
{
int ch1;
__asm
{
loop:
ldrb ch1, [str1], #1
cmp ch1,#0
bne loop
sub str1,str1,#1
loop2:
ldrb ch1, [str2], #1
strb ch1, [str1],#1
cmp ch1,#0
bne loop2
};
}
int main(void)
{
const char* b = "Hello World!";
char a[30];
strcpy(a,"I am allright!");
printf("before strcat :b=%s\n",b);
__asm{
MOV R0, a
MOV R1, b
BL my_strcat, {R0, R1}
};
printf("after strcat :b=%s\n",b);
}
这个回答够标准了吧...
热心网友
时间:2023-09-20 19:50
friend obj& operator+(obj& rhs,obj& dst)
{
strcat(rhs.str,dst.str);
return rhs;
}
热心网友
时间:2023-09-20 19:51
#include <stdio.h>
void mystrcat(char *dest,char *src)
{
__asm__ __volatile__ (
"mov r0, #0x0\n"
"mov r1, %[src]\n"
"mov r2, %[dest]\n"
"loop:\n"
"ldrb r0, [r2],#0x1\n"
"cmp r0, #0\n"
"bne loop\n"
"sub r2,#1\n"
"beq cat\n"
"cat:\n"
"ldrb r0,[r1],#0x1\n"
"strb r0,[r2],#0x1\n"
"cmp r0,#0\n"
"beq end\n"
"bne cat\n"
"end:\n"
:
:[dest]"r"(dest),[src]"r"(src)
:"r0","r1","r2"
);
}
int main(int argc, char *argv[])
{
char a[32] = "hello";
char b[16] = "world";
mystrcat(a,b);
printf("a : %s\n",a);
return 0;
}