tags:

views:

103

answers:

4
+1  Q: 

Assembly? LD & MOV

What's the difference between that instructions? By example in the ARM9 processor, it shouldn't be:

ASM: mov r0, 0
C: r0 = 0;

ASM: ld r0, 0
C: r0 = 0;

?

I don't know why to use one or other :S

+6  A: 

It must be:

ASM: mov r0, 0
C:   r0 = 0;

ASM: ld r0, 0
C:   r0 = *(pc + 0);

Check out this reference card, must have if you're developing for ARM on ASM.

Andrejs Cainikovs
Oh so with ld I'm getting the content of a memory address... thank you!
Puyover
+1  A: 

Try this guide: ARM Assembler Guide

Lior
+1  A: 

Usually the LoaD instructions are used to load data from memory (directly or indirectly) into a register, while the MOVe instruction "moves" (copies) data from an operand to a register. In the ARM case, the source operand is a value (a constant) or a register (and both can be shifted/rotated before copying into the destination register).

So the first (mov r0, #0?), set to 0 the register r0; the second (a pseudo-op for ldr?) should load the data pointed by pc (r15) plus offset 0, and so be equivalent to r0 = *(pc + 0))

ShinTakezou
Thanks. I will update my answer.
Andrejs Cainikovs
A: 

Whether it is called MOV or LD depends on the particular assembly language. For example, the Z80 assembly language uses LD for everything, including assignment between registers and assignment of immediate values to registers.

In general you should always look up the meaning of mnemoics in the particular assembly language you are using.

starblue
Well, actually with ARM there are both instructions, and they're very different. MOV loads an immediate value (from another reg., or a value encoded in the opcode) into a register - no memory access. With LDR, a register is loaded from memory. I agree 100% with your last sentence.
Dan
I agree. The specifics of assembly is that it is architecture dependent. Reason of this that every architecture may have/has it's own machine code commands/specifics.
Andrejs Cainikovs