【问题标题】:"mov" of "assembly language" meant copy or move? [duplicate]\"mov\" of \"assembly language\" meant copy or move? [duplicate]
【发布时间】:2019-09-13 13:18:13
【问题描述】:

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++ isSituation 1

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

This is my question.

【问题讨论】:

  • it does a copy...
  • Hi @Wagner Patriota: Thanks your reply. I know this question too stupid.... I am not familiar with assembly. So, answer isSituation 2?
  • @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.
  • 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.
  • Mostprocessor assembly languages have only one destination and one or more sources.

标签: c++ assembly move mov


【解决方案1】:

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.

【讨论】:

    猜你喜欢
    • 2022-12-04
    • 2016-11-01
    • 2019-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多