I'm quite new to inline assembly, so I need your help to be sure that I use it correctly. I need to add assembly code inside my C code that is compiled with the Risc-v toolchain. Please consider the following code:
int bar = 0xFF00;
int main(){
volatile int result;
int k;
k = funct();
int* ptr;
ptr = &bar;
asm volatile (".insn r 0x33, 0, 0, a4, a5, a3":
"=m"(*ptr), "=r"(result):
[a5] "m"(*ptr), [a3] "r"(k) :
);
}
...
What I want to do is bar = bar+k
. Actually, I want to change the content of the memory location that bar
resides in. But the code that I wrote gets the address of bar
and adds it to k
. Does anybody know what the problem is?