MOV (x86 instruction)
Encyclopedia
In the x86 assembly language
X86 assembly language
x86 assembly language is a family of backward-compatible assembly languages, which provide some level of compatibility all the way back to the Intel 8008. x86 assembly languages are used to produce object code for the x86 class of processors, which includes Intel's Core series and AMD's Phenom and...

, the MOV instruction is a mnemonic
Mnemonic
A mnemonic , or mnemonic device, is any learning technique that aids memory. To improve long term memory, mnemonic systems are used to make memorization easier. Commonly encountered mnemonics are often verbal, such as a very short poem or a special word used to help a person remember something,...

 for the copying of data from one location to another. The x86 assembly language has a number of different move instructions. Depending on whether the program is in a 16-bit or 32-bit code segment (in protected mode
Protected mode
In computing, protected mode, also called protected virtual address mode, is an operational mode of x86-compatible central processing units...

) and whether an override instruction prefix is used, a MOV instruction may transfer 8-bit
8-bit
The first widely adopted 8-bit microprocessor was the Intel 8080, being used in many hobbyist computers of the late 1970s and early 1980s, often running the CP/M operating system. The Zilog Z80 and the Motorola 6800 were also used in similar computers...

s, 16-bit
16-bit
-16-bit architecture:The HP BPC, introduced in 1975, was the world's first 16-bit microprocessor. Prominent 16-bit processors include the PDP-11, Intel 8086, Intel 80286 and the WDC 65C816. The Intel 8088 was program-compatible with the Intel 8086, and was 16-bit in that its registers were 16...

s, or 32-bit
32-bit
The range of integer values that can be stored in 32 bits is 0 through 4,294,967,295. Hence, a processor with 32-bit memory addresses can directly access 4 GB of byte-addressable memory....

s of data (or 64-bit
64-bit
64-bit is a word size that defines certain classes of computer architecture, buses, memory and CPUs, and by extension the software that runs on them. 64-bit CPUs have existed in supercomputers since the 1970s and in RISC-based workstations and servers since the early 1990s...

s in x86-64 mode). Data may be copied to and from memory and registers.

The word move for this operation is, strictly speaking, a misnomer: it has little to do with the physical concept of moving an object from A to B, with place A then becoming empty; a MOV instead makes a copy of the state of the object at A and overwrites the old state of B in this process. This is reflected in some other assembly languages by using words like load, store or copy instead of move.

The following is an example of Intel syntax, which copies the value in register Y into register X:
MOV X, Y

This operation is represented by the following pseudocode
Pseudocode
In computer science and numerical computation, pseudocode is a compact and informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading...

:
X := Y
While MOV X, Y is equivalent to X := Y, the reverse is often not true, especially in high-level programming languages where X := Y will translate into more complex assembly language.

In AT&T assembler syntax, the above operation would be accomplished as follows:
MOV Y, X
X and Y may be immediate values, registers, or memory references. Instruction suffixes are not necessary with AT&T syntax except in the case of immediate data to memory. Some possible suffixes are movb (byte, 8 bits), movw (word, 16 bits), movl (long, 32 bits), and movq (quad, 64 bits).

Either X or Y can include addressing information.

The operands for the MOV commands can either be registers, a segment register or a memory address since the command is executed in a single CPU
Central processing unit
The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...

 work cycle. There is a succession as in:

move the contents of the register bx into the register ax
MOV ax, bx

move the contents of the register ax into the referenced memory block
MOV [address], ax

Memory to memory moves, such as
MOV [address1], [address2]
are not possible. To achieve this, MOV must be used in sequence:
MOV ax, [address2]
MOV [address1], ax

Usually, there is one set of opcode
Opcode
In computer science engineering, an opcode is the portion of a machine language instruction that specifies the operation to be performed. Their specification and format are laid out in the instruction set architecture of the processor in question...

s for
MOV register, [address]
MOV [address], register

There are also special MOV opcodes for accessing control register
Control register
A control register is a processor register which changes or controls the general behavior of a CPU or other digital device. Common tasks performed by control registers include interrupt control, switching the addressing mode, paging control, and coprocessor control.-CR0:The CR0 register is 32 bits...

s:
MOV ax,CR0
MOV CR0,ax
(Same for other control register
Control register
A control register is a processor register which changes or controls the general behavior of a CPU or other digital device. Common tasks performed by control registers include interrupt control, switching the addressing mode, paging control, and coprocessor control.-CR0:The CR0 register is 32 bits...

s, test register
Test register
A test register, in the Intel 80486 processor, is a register used by the processor, usually to do a self-test. Most of these registers are undocumented, and used by specialized software. The test registers were named TR3 to TR7. Regular programs don't usually require these registers to work...

s, and debug register
Debug register
On the x86 architecture, a debug register is a register used by a processor for program debugging. There are six debug registers, named DR0...DR7, with DR4 and DR5 as obsolete synonyms for DR6 and DR7...

s.)

The instructions MOVSX (move with sign extend) or MOVZX (move with zero extend)
can be used to copy data of different sizes.
To move the higher byte of the 16-bit register BX sign-extended into the 32-bit register EAX, use:
MOVSX EAX,BH
Another example, that moves the value of AL into EAX, padding it with zeros:
MOVZX EAX,AL
For example, if AL were 0x2F, EAX would be set to 0x0000002F.

However, to zero-extend a 32-bit value to a 64-bit value when running in 64-bit mode, only a regular 32-bit MOV is required, since 32-bit values are always zero-extended in 64-bit mode. If RBX contains the value 0x0123456789ABCDEF, after:
MOV EAX,EBX
register RAX will contain 0x0000000089ABCDEF.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK