int smplSize = 48;
int Smpl[48];
for(int i = 0; i < smplSize; i++) Smpl[i] = 0x0;
Smpl[smplSize-1] = 0x1;
int *ptrToSmpl = &Smpl[0];
printf("Sample @%p of Size %i :\n",(void*)ptrToSmpl,smplSize);
asm volatile(
"@ ------------------------------------------------- \n"
"@ Invert the sample \n"
"@ ------------------------------------------------- \n"
//"0: \n"
"ldr r2,[r3] \n"
//"cmp r2,#0x1 \n"
//"bne 1f \n"
"add r2,#0x1 \n"
//"add r2,#0x1 \n"
"str r2,[r3] \n"
//"ldr r1, .0 \n"
//"bx r1 \n"
//"1: \n"
:
: "r" (ptrToSmpl)
: "r3", "memory"
);
printf("Sample[0] = %i" , Smpl[0]);
编辑:
正如你可以看到我想要通过操纵手臂上的内联汇编数组的一个变量,但我总是得到一个段错误。 我怎样才能访问,而段错误的记忆?
printf("Hello inline asmTest start!\n\n");
int smplSize = 48;
int Smpl[48];
for(int i = 0; i < smplSize; i++) Smpl[i] = 0x0;
Smpl[smplSize-1] = 0x1;
int *ptrToSmpl = &Smpl[0];
printf("Sample @%p of Size %i :\n",(void*)ptrToSmpl,smplSize);
asm volatile(
"@ ------------------------------------------------- \n"
"@ Invert the sample \n"
"@ ------------------------------------------------- \n"
//"0: \n"
"ldr r2,%[ptrToSmpl] \n"
//"cmp r2,#0x1 \n"
//"bne 1f \n"
"add r2,#0x1 \n"
//"add r2,#0x1 \n"
"str r2,%[ptrToSmpl] \n"
//"ldr r1, .0 \n"
//"bx r1 \n"
//"1: \n"
:
: [ptrToSmpl]"r" (ptrToSmpl)
:
);
printf("Sample[0] = %i" , Smpl[0]);
好吧,我这样做了,但现在我得到一个“/tmp/cczQDyiw.s|72|Error:internal_relocation(类型:OFFSET_IMM)不固定起来|” 编译它的时候。
BTW:我可以内联汇编代码“组织[PROGRAMM中的ADRESS]”?
printf("Hello inline asmTest start!\n\n");
int smplSize = 48;
int Smpl[48];
for(int i = 0; i < smplSize; i++) Smpl[i] = 0x0;
Smpl[smplSize-1] = 0x1;
int *ptrToSmpl = &Smpl[0];
printf("Sample @%p of Size %i :\n",(void*)ptrToSmpl,smplSize);
asm volatile(
"@ ------------------------------------------------- \n"
"@ Invert the sample \n"
"@ ------------------------------------------------- \n"
"init: \n"
"ldr r0,%[ptrToSmpl] \n"
"loop : \n"
"ldr r4,[r0] \n"
"cmp r4,#0x0 \n"
"bne end \n"
"add r4,#0x1 \n"
"str r4,[r0] \n"
"add r0,#0x1 \n"
"b loop \n"
"end: \n"
:
: [ptrToSmpl]"r" (ptrToSmpl)
: "r0" , "r4", "memory"
);
printf("Sample[0] = %i" , Smpl[0]);
编辑2:
正如你可以看到上面还那里有在adressing我觉得一个错误。 该错误消息现在是:“/tmp/ccE69oZd.s|75|Error:未定义的符号R6用作立即值|” 但是没有任何地方R6。