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]);
Edit:
As you can see I want to manipulate a variable of an array via the inline assembler on arm, but I always get a segfault. How can I access the memory without segfault?
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]);
Ok, I did so, but now I get a "/tmp/cczQDyiw.s|72|Error: internal_relocation (type: OFFSET_IMM) not fixed up|" when compiling it.
BTW: Can I "org [Adress of the programm]" the inline asm code ?
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]);
Edit 2:
As you can see above theres still a bug in the adressing I think. The error message now is: "/tmp/ccE69oZd.s|75|Error: undefined symbol r6 used as an immediate value|" but there's no r6 anywhere.