Reputation: 374
I have been trying to do some simple manipulations in assembly for the ARM M0+ processor.
Thus far I have failed.
I want to allocate two variables, a & b to some values, 3 & 8, then I want to set one variable to the value of the other.
In any higher level language I would only need
int a = 3;
int b = 8;
b = a;
So far in assembly I figured out how to allocate and set variables.
a DCD 3
b DCD 8
And I figured out how to get the value and address of the variables
LDR r0, =a ; r0 = &a
LDR r0, [r0] ; r0 = a
This is where I'm getting stuck, how do I store the value of r0 into the varaible b?
Upvotes: 2
Views: 5337
Reputation: 16626
Just reverse the load operation into store operation, i.e. you need address of memory where is reserved space for b
:
LDR r1, =b ; r1 = &b (do not overwrite "a" value in r0)
And then you store the "a" value into memory there:
STR r0, [r1] ; b = r0 (a)
This seems like stuff which should be part of any basic tutorial or book, so maybe try to look for one, "guessing" everything about assembly on your own, using only instruction set manual is vital practice later, but for basics using also some tutorial or book to get you started much faster, assembly is not "guessing" friendly.
Keep in mind the CPU instructions are designed by the HW design of the CPU, so their inner "logic" is compromise between what "programming logic" of high level languages may need and use, and what set of transistors can do effectively (HW logic), assembly is not as much "programming language", as it is "HW desing of CPU description", so if you keep expecting "programming" logic, you will often run into weird things (which make perfect sense once you try to consider the HW way of thinking and then those weird things are hidden by high-level programming languages compilers, so ordinary programmer doesn't need to know exactly how the HW operates).
Upvotes: 5