MOV (x86 instruction)
From Wikipedia, the free encyclopedia
In the x86 assembly language, the MOV instruction is a mnemonic for the copying of data from one location to another. The x86 assembly language actually contains a number of different opcodes that perform a move. Depending on whether the processor is in real mode or protected mode, and an override instruction is used, the instruction may transfer 8-bits, 16-bits, or 32-bits of data. Data may be copied to and from memory and registers.[1]
One has to notice that using the mnemonic move for this operation may be seen as a misnomer, as the physical concept of moving an object from A to B (with place A now being empty) is changed to the concept of making a copy of the object at A to B (and possibly overwriting what was placed at B before). The following is an example of Intel syntax. The example copies the value in register Y into register X:
MOV X, Y
This operation is represented by the following pseudocode:
X := Y
In AT&T assembler syntax, the above operation would be accomplished as follows:
MOVB $Y, X
Either X or Y can include addressing information.
The arguments for the MOV commands can be either a register, segment register or a memory address. since the command is executed in a single CPU work cycle, not all combinations of arguments are possible. possible combinations:
move the content of the register bx into the register ax
MOV ax, bx
move the content of the register ax into the memory block with the specified address
MOV [address], ax
A combination which is not possible, is a move from memory to memory, for example :
MOV [address1], [address2]
to achieve this, another MOV must be used:
MOV ax, [address2] MOV [address1], ax
Usually, there is one set of opcodes for
MOV register, [address] MOV [address], register
Also there are special MOV opcodes for accessing control registers:
MOV ax,CR0 MOV CR0,ax
(Same for other control registers, test registers, and debug registers.)
If you want to move different sizes of data, consider using movzx. Example movzx syntax:
MOVZX EAX,BH
(The above code moves the higher byte of the 16-bit register BX into the 32-bit register EAX.) An example of what movzx does:
MOVZX EAX,AL
will move the value of AL into EAX, padding it with zeroes. For example, if AL was 0x2F, EAX would be set to 0x0000002F.