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?

Lucenzo97
  • 293
  • 4
  • 11
  • 1
    Which assembly language? – 8bittree Nov 21 '16 at 21:34
  • 3
    Possible duplicate of [Why is the copying instruction usually named MOV?](http://softwareengineering.stackexchange.com/questions/222254/why-is-the-copying-instruction-usually-named-mov) – Erik Eidt Nov 21 '16 at 21:52
  • @ErikEidt : Partially is. – Lucenzo97 Nov 22 '16 at 18:19
  • @8bittree : Isn't there only one assembly language. Aren't only higher-level languages different among themselves? – Lucenzo97 Nov 22 '16 at 18:21
  • 1
    There are many assembly languages. Usually at least one for each [Instruction Set Architecture (ISA)](https://en.wikipedia.org/wiki/Instruction_set). 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
  • @8bittree probably "freezes" or the execution process stops, right? – Lucenzo97 Nov 22 '16 at 21:43
  • 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 Answers2

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.

riwalk
  • 7,660
  • 3
  • 29
  • 32
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.
Christophe
  • 74,672
  • 10
  • 115
  • 187
  • 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 – Lucenzo97 Nov 22 '16 at 10:48