Assembly? LD & MOV


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





@DrBeco: Why did you tag this intel-syntax (stackoverflow.com/tags/intel-syntax/info)? That makes no sense; this is an ARM question. Intel-syntax is one of two major flavours of syntax for x86, which is a separate architecture. x86's mov instruction can have a memory, register, or immediate source, and doesn't have a separate ld instruction.
– Peter Cordes
Jun 30 at 0:01



mov


ld





Hi @PeterCordes, I tagged it for clarifying the operand order, only (first DST, second SRC). But I see your point, ok.
– Dr Beco
Jun 30 at 0:05





@DrBeco: I'm not aware of a destination-last flavour of ARM asm existing in the first place to require clarification. Plus, the r0 = 0 C version already removes any ambiguity for people who don't know that ARM is always output(s) first, like most asm syntaxes for most architectures.
– Peter Cordes
Jun 30 at 0:09


r0 = 0




4 Answers
4



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.





Oh so with ld I'm getting the content of a memory address... thank you!
– Puyover
Jul 10 '10 at 14:35



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))


mov r0, #0


ldr


r0 = *(pc + 0)





Thanks. I will update my answer.
– Andrejs Cainikovs
Jul 10 '10 at 14:47



Try this guide: ARM Assembler Guide



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.





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
Jul 11 '10 at 15:21





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
Jul 14 '10 at 17:04






@Dan: ARM assemblers use ldr r0, =0x1234 as a pseudo-instruction which might load from a literal pool, or could use ALU instruction(s) to create the constant in the register. So LDR isn't always a load!
– Peter Cordes
Jun 30 at 0:05


ldr r0, =0x1234





@PeterCordes - great point. I think I was referring to the LDR instruction, as opposed to the LDR pseudo-instruction (what's life without confusion!)
– Dan
2 days ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV