I'm trying to add two registers together in ARM Assembly, by dereferencing the first two registers, and then storing the result in the third register.
At the moment I have 3 variables & a function, which are as follows;
extern void my_function(int* x, int* y, int* total);
int main(void){
int x = 1; //R0
int y = 2; //R1
int total = 0; //R2
while(1){
my_function(&x, &y, &total);
printf("\x1b[5;5HTotal = %d, total");
}
}
And a function this does the following
With the first two registers, I'm trying to dereference them, add them together and store the result in a third register. This is my assembly code;
ldr r4, [r0] @ Dereference r0, and store the address in R4
ldr r4, [r1] @ Dereference r1, and store the address in R4
add r2, r0, r1 @ Add r0 & r1 together, and store in R2
str r4, [r2] @ Store r2 address in r4
When I print this out, the answer is 0.
My question is, when I do the first two lines in assembly, does ldr r4, [r0]
get replaced with ldr r4, [r1] which is causing the output to be 0?
Do they each need to be stored in their own register?
Or am I just basically printing out the total (r2)?