flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Heap > why is in most assembler languages MOV not CPY?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
MSrobots2



Joined: 21 Oct 2017
Posts: 2
why is in most assembler languages MOV not CPY?
I think the MOV in most assembler languages is a complete miss naming.

It never moves a value it always creates a copy and leaves the old value where it is.

it should be named CPY not MOV

Mike
Post 22 Oct 2017, 01:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15241
Location: 1I/ʻOumuamua
ARM have defined CPY in their mnemonics.

Z80 uses LD.

AT&T uses MOV<size>

But to actually answer your question you'd need to ask the original designers of the CPU opcodes. If they are still alive?
Post 22 Oct 2017, 02:02
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 6951
Location: ˛                              ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣ Posts: 6699
i guess mov is easier to type than cpy, and mov looks cleaner than cpy Wink
Post 22 Oct 2017, 03:11
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 868
Actually, I agree. Or name should be "set" since in some architectures (x86) you can also use constants and such. "Copy" makes sense there but it's a bit less intuitive.


Code:
set eaxebx
set eax5

etc
Post 22 Oct 2017, 15:46
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6633
Location: Kraków, Poland
I personally like the LD and ST that some architectures use. It would in fact fit x86 too, as there are separate opcodes that could be called LD (MOV reg,mem) and ST (MOV mem,reg), but Intel chose to use a common mnemonic for multiple instructions, perhaps to make it easier to remember.
Post 22 Oct 2017, 20:40
View user's profile Send private message Visit poster's website Reply with quote
_shura



Joined: 22 May 2015
Posts: 60
let instead of set. IMHO it sounds better Very Happy.
But this is a question I also had for a long time. I guess, there is no reason.
Post 22 Oct 2017, 21:42
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 868
I have nightmares with "let" due to "math speak"...
Post 23 Oct 2017, 12:08
View user's profile Send private message Reply with quote
_shura



Joined: 22 May 2015
Posts: 60
let furs = not ( having nightmares ) Razz
Post 23 Oct 2017, 18:07
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15241
Location: 1I/ʻOumuamua
In x86 MOV is a very common opcode to see in the source code. So why not remove it completely? Just put the operands without an opcode.

Code:
eax,ebx ;mov eax,ebx
add eax,ebx ;add eax,ebx
cx,5 ;mov cx,5

It could save some typing. It is not ambiguous. You could think of it as a blank opcode meaning MOV.

Code:
        eax,ebx ;blank opcode
add     eax,ebx ;explicit opcode
        cx,5    ;blank opcode

Post 24 Oct 2017, 03:59
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 868
Nah, but:

Code:
eax = ebx
cx = 5

is good. Cool
Post 24 Oct 2017, 17:30
View user's profile Send private message Reply with quote
_shura



Joined: 22 May 2015
Posts: 60
well, you could define eax, ebx, ... as a macro and match the arguments like this:

Code:

irp namealahaxeax, \
          clchcxecx, \
          dldhdxedx, \
          blbhbxebx
  macro name arguments*
    match == operandsarguments
      mov nameoperands
    else
      err `name': invalid operands'
    end match
  end macro
end irp


Post 24 Oct 2017, 18:12
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15241
Location: 1I/ʻOumuamua
Don't forget about these also:

Code:
mov rsi,[mem]
mov [mem],rax
mov byte[mem],0xff

Post 25 Oct 2017, 01:30
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1577
Location: Ukraine
Smile

Code:

    eax ; mov eax,0

Post 25 Oct 2017, 09:47
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15241
Location: 1I/ʻOumuamua

shoorick wrote:

Code:
    eax ; mov eax,0



Code:
macro a { xor eax,eax } ;works for both 32-bit and 64-bit modes

Post 25 Oct 2017, 12:07
View user's profile Send private message Visit poster's website Reply with quote
_shura



Joined: 22 May 2015
Posts: 60
memory as source-operand should work with this code, for memory as destination-operand you can do this:

Code:

irp namebyteworddword
  macro name arguments*
    match [ memory ] == operandsarguments
      mov name [ memory ], operands
    else
      err `name': invalid operands'
    end match
  end macro
end irp



but

Code:

eax ] = 1



is not possible afaik.
why should

Code:

eax



equal to

Code:

mov eax0



?
anyway, some extra bits:

Code:

irp namebyteworddword
  macro name arguments*
    match [ memory ] == operandsarguments
      mov name [ memory ], operands
    else match [ memory ] ++, arguments
      inc name [ memory ]
    else match [ memory ] --, arguments
      dec name [ memory ]
    else
      err `name': invalid operands'
    end match
  end macro
end irp
irp namealahaxeax, \
          clchcxecx, \
          dldhdxedx, \
          blbhbxebx
  macro name arguments*
    match == operandsarguments
      mov nameoperands
    else match ++, arguments
      inc name
    else match --, arguments
      dec name
    else
      err `name': invalid operands'
    end match
  end macro
end irp


Post 25 Oct 2017, 14:54
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15241
Location: 1I/ʻOumuamua

_shura wrote:
why should

Code:

eax



equal to

Code:

mov eax0



?

Yah, it should be xor eax,eax Twisted Evil
Post 25 Oct 2017, 15:29
View user's profile Send private message Visit poster's website Reply with quote
_shura



Joined: 22 May 2015
Posts: 60
I mean, if I read a single line »eax« in my code, it is not obvious what this mean. I looks like a function call:

Code:

call eax



but not like

Code:

xor eaxeax



and even a function call should look more like

Code:

eax()



which can be done with:

Code:

struc (symbol? definition&
  match =(=), definition
    call symbol
  else match =( arguments =), definition
    callFunction eaxarguments
  else
    err `symbol': what do ya want from me?'
  end match
end struc



but you have to implement »callFunction« yourself.
Post 25 Oct 2017, 15:40
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15241
Location: 1I/ʻOumuamua

_shura wrote:
and even a function call should look more like

Code:

eax()



We don't write C code here. Laughing
Post 25 Oct 2017, 16:26
View user's profile Send private message Visit poster's website Reply with quote
_shura



Joined: 22 May 2015
Posts: 60
so eax = 1 should not allowed too Very Happy
Post 25 Oct 2017, 18:00
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6633
Location: Kraków, Poland

_shura wrote:
but

Code:

eax ] = 1



is not possible afaik.

You could do that with "macro ?" if you really wanted.
Post 25 Oct 2017, 18:55
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.