3

Recently, I read the C++ of std::mov, and I thought of a question as the title.

Assume initial value following:

int a= 1;
int b= 2;

I think:

Situation 1,

after move (a <- b):

a= 2 , b=  

b is null because moved

Situation 2,

after copy (a <- b):

a=2  , b=2 

I know std::move of C++ is Situation 1

Which Situation is mov ( mov %b %a ) of Assembly lang.?

This is my question.

curlywei
  • 682
  • 10
  • 18
  • 2
    it does a copy... – Wagner Patriota Sep 13 '19 at 01:36
  • Hi @Wagner Patriota: Thanks your reply. I know this question too stupid.... I am not familiar with assembly. So, answer is **Situation 2**? – curlywei Sep 13 '19 at 01:44
  • 5
    @curlywei yes, a `mov` in assembly is a copy, not a move. And your C++ reference is not a very good one, because `std::move()` is just a typecast and does not actually move anything. Using `std::move()` in the assignment of POD types, like `int`, is also a copy, not a move. – Remy Lebeau Sep 13 '19 at 01:55
  • there are countless different assembly languages, different processors different syntax per processor depending on the tools vendors, etc. but a move is a copy, in general the source is not destroyed, read the value in this register or memory location and write that value to this (other) register or memory location, which is a "copy" of something in english because the source is not destroyed. If there such a processor where the source is destroyed it is usually a different instruction or it is a special function of a peripheral/memory and not related to the instruction set. – old_timer Sep 13 '19 at 02:41
  • *Most* processor assembly languages have only one destination and one or more sources. – Mirko Sep 13 '19 at 02:51
  • In situation 1 b Is not null, because b Is of type int. Only pointers can be null. – slepic Sep 13 '19 at 06:25

1 Answers1

4

In every architecture I've worked with, a MOV copies the value, and leaves the source untouched. There's a very simple reasoning for this. Assembly is the "base-level" of what people work with, and needs to be the smallest constituent parts. Therefor, each instruction does as little as it needs to do to get the job done. That way, there's less of a chance of unintended behavior and there are more precise combinations possible.

Bakna
  • 535
  • 1
  • 5
  • 13