UMBC CMSC 313 -- Assembly Language Segment Previous | Next


MOV Instruction

According to the IA-32 Intel Architecture Software Developer's Manual Volume 2: Instruction Set Reference, the different forms of the most commonly used data transfer instruction are (each one of these forms is a different opcode!):

MOV r/m8,r8
MOV r/m16,r16
MOV r/m32,r32
MOV r8,r/m8
MOV r16,r/m16
MOV r32,r/m32
MOV r/m16,Sreg
MOV Sreg,r/m16
MOV AL,moffs8
MOV AX,moffs16
MOV EAX,moffs32
MOV moffs8,AL
MOV moffs16,AX
MOV moffs32,EAX
MOV r8,imm8
MOV r16,imm16
MOV r32,imm32
MOV r/m8,imm8
MOV r/m16,imm16

The definition of the instruction is:

Copies the second operand (source operand) to the first operand (destination operand). The source operand can be an immediate value, general-purpose register, segment register, or memory location. Both operands must be of the same size, which can be a byte, word, or a doubleword MOV r/m32,imm32

NOTE: There is a problem with the definition of the term "word". In all of Intel documentation, it means a 16-bit value. During the Digital Logic segment of this course, it means the size of the registers, which on a Pentium is considered to be 32 bits. Intel describes the 32-bit value as a doubleword.

There are a number of specialized MOV instructions are less general. We are not going to use all of them!

C/C++

How is it done in C/C++, and how is it done it Assembly? Assuming the variable foo and bar are declared as int and that an int is a 4 byte signed integer. foo = 3; would become: mov dword [foo], 3

In the previous example, you have to make sure names knows what the size of the constant is by using the dword size specifier. The others are BYTE, WORD, QWORD, and TWORD.

There is a restriction that you can not have both the source and destination as memory locations, so

bar = foo; becomes: mov eax, [foo]
mov [bar], eax


©2004, Gary L. Burt

Previous | Next