5

Moving data in assembly language:

MOV B, A

If I move content from internal register A to register B, what happens to content of register A? Is it deleted? Stays unchanged?

7
  • 1
    Which assembly language? – 8bittree Nov 21 '16 at 21:34
  • 3
    Possible duplicate of Why is the copying instruction usually named MOV? – Erik Eidt Nov 21 '16 at 21:52
  • @ErikEidt : Partially is. – Lu Ka Nov 22 '16 at 18:19
  • 1
    There are many assembly languages. Usually at least one for each Instruction Set Architecture (ISA). You can't simply write x86 assembly and expect to get results that make sense when running the converted machine code on a MIPS cpu, if it will even run at all. MIPS has no eax register, so what's it supposed to do when when you tell it to add eax, 5? – 8bittree Nov 22 '16 at 18:28
  • 1
    @LuKa If you hand the x86 instruction add eax, 5 to a MIPS assembler, and are lucky, it will reject it. If you're unlucky, it will turn it into... something. If you run it through an x86 assembler that uses Intel syntax, you might get the bytes 0x6683C005. Or you might get 0x0505000000, or something other equivalent instruction. The first seems to be a bltz (branch if less than zero) instruction in MIPS. The second would be 1.25 MIPS instructions. Halting execution would only happen if you're very, very lucky. More likely you'll just end up running a bunch of random instructions. – 8bittree Nov 23 '16 at 16:13
2

The MOV command will leave the contents of register A alone. From some x86 documentation (emphasis added):

The mov instruction copies the data item referred to by its second operand (i.e. register contents, memory contents, or a constant value) into the location referred to by its first operand (i.e. a register or memory).

http://www.cs.virginia.edu/~evans/cs216/guides/x86.html

There are many other assembly languages, but you can count on most modern languages working the same way.

3
  • What about if I want to clear data from register A after its content was copied to B register? Is there instruction for that? – Lu Ka Nov 22 '16 at 10:42
  • @LuKa, clear register A to what value? Zero? Why not just store a zero there? – Wildcard Nov 22 '16 at 12:16
  • 2
    @LuKa, just set register A equal to whatever value you want after you run a MOV command. – riwalk Nov 22 '16 at 20:12
1

The answer depends heavily on the CPU and assembly language you're targeting:

The source is left unchanged for a move.

Out of curiosity, and nostalgy, a couple of older CPUs used other covnetions as well:

  • the good old PDP11 (ok there is little risk that you'll target this nowadays) had the move in the other direction: MOV source, target
  • the still old family of Motorala 68K had a MOVE source, target
  • the PowerPC had no MOV, but uses several variants of loads and stores, the first using targe, source, and the second source, target. It also had several variants of move but called differently keepng from the naming convention only the first letter.
1
  • Thank you for you answer and time. I didn't know that different CPUs have different "layouts" for source and target addresses. I have just began with studying basics of programming, plus I'm doing it on my own so I think I am going to have a lot more similar questions in the future :D – Lu Ka Nov 22 '16 at 10:48

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.