My question about a simple instruction code of an ARM micro-controller.

LDR R2, [R1]

In the above instruction I interpret it as: R1 a RAM memory register and R2 is a processor register. What I understand from this was R1 represents the memory content in RAM and R2 is a processor register. So it says: Go to the address of R1 in RAM memory and load its contents to the processor's R2 register. Is that right? R1 is in RAM but R2 is in processor?


Your wording is weird, so I can't decide whether you have the correct interpretation or a wrong one.

Physically, all ARM registers are in the CPU. They hold (32 bit) values. In the instruction you ask about the value in R1 is used as a memory address. The value at that address in memory (and the next 3 addresses, because the memory is byte-addressed and the LDR loads 32 bits) is loaded into register R2.

This is the sheet from my ARM assembler course that illustrates this instruction. It is partly in Dutch, and covers the more general case where an offset is applied to the R1 value.

The green block at the left is the CPU with its registers, the enclosing yellowish block is the microcontroller, which contains both the CPU and the (RAM) memory.

enter image description here

|improve this answer|||||
  • \$\begingroup\$ Thanks for the answer, actually that was the source of my confusion. The terminology. Sometimes people call the RAM memory locations as RAM register. Do you mean the word "register" only used for the 32-bit locations inside the CPU? So register in ARM is only used for the CPU? Did I understand you well as follows: Register R2 is 32-bit and locates in CPU; R1 is 1byte(8 Bit) and locates in RAM. Is that right? \$\endgroup\$ – user16307 Mar 19 '16 at 22:05
  • 1
    \$\begingroup\$ All registers are in the CPU, and are 32 bits. Those bits can bse used as a RAM address, but that doesn't phyiscally move the register, it is still in the CPU. Also, in an ARM there is no distinction between data and address registers: each register can be used in either role. (The 68000 for instance does distinguish between data and address registers). \$\endgroup\$ – Wouter van Ooijen Mar 19 '16 at 22:08
  • \$\begingroup\$ Well actually no, not all registers are in the CPU, especially on ARM parts where memory mapped special function registers are common. What is correct is that all CPU registers are in the CPU, and R0 through R31 are CPU registers. \$\endgroup\$ – Chris Stratton Mar 19 '16 at 22:23
  • \$\begingroup\$ @Chris Stratton But many tutorials show CPU registers from R0 to R15. What are the rest 15 for? \$\endgroup\$ – user16307 Mar 19 '16 at 22:29
  • \$\begingroup\$ Sorry, my momentary mistake. R0-R15 is correct in your case. There are other conceptually similar designs with 32 numbered registers. \$\endgroup\$ – Chris Stratton Mar 19 '16 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.