MOV Instruction
The MOV instruction moves the integer -5000h to the EAX register. The first operand (EAX) is called the destination operand, and the second operand is called the source operand.
|
|
|
MOV — Move Byte or Word
|
Usage: MOV dest, src
| Flag |
O
| D
| I
| S
| Z
| A
| P
| C
|
| Result |
|
|
|
|
|
|
|
|
Copies byte or word from the source operand to the destination operand.
|
|
Clocks |
|
| Operands |
286 |
386 |
486 |
Size Bytes |
| reg, reg |
2 |
2 |
1 |
2 |
| mem, reg |
3 |
2 |
1 |
2-4 |
| reg, mem |
5 |
4 |
1 |
2-4 |
| mem, immed |
3 |
2 |
1 |
3-6 |
| reg, immed |
2 |
2 |
1 |
2-3 |
| mem, accum |
3 |
2 |
1 |
3 |
|
... |
|
|
MOV is very flexible in its use of operands, as long as the following rules are observed:
- Both operands can not be memory operands. For the example below, move the value of
X to the value of Y:
- Both operands must be the same size.
CS, EIP, and IP registers can not be destination operands.
-
An immediate value can not be moved to a segment register.
|
|
.data
X SDWORD -5000h
Y SDWORD ?
.code
mov eax, X
mov Y, eax
mov eax, Y
call WriteHex
|
|
|
ReadSub.asm
|
COMMENT!
*
* This program reads and subtracts 32-bit hexadecimal integer from 50000h.
*
!
INCLUDE Irvine32.inc
.data
prompt1 BYTE 0Dh, 0Ah, "Calculate an Arithmetic Expression of 50000h - Y:",
0Dh, 0Ah, 0
prompt2 BYTE "Enter the value of operand Y: ", 0
prompt3 BYTE 0Dh, 0Ah, "The result is ", 0
X DWORD 50000h
Y DWORD ?
result DWORD ?
.code
main PROC
mov edx, OFFSET prompt1
call WriteString ; print prompt1
mov edx, OFFSET prompt2
call WriteString ; print prompt2
call ReadHex
mov Y, eax ; Y = eax (the input)
mov eax, X ; eax = X (50000h)
; calculate 50000h – Y
sub eax, Y ; eax = X (50000h) – Y (the input)
mov result, eax ; result = eax (X – Y)
mov edx, OFFSET prompt3
call WriteString ; print prompt3
call WriteHex ; print eax (result)
exit
main ENDP
END main
|
|
An Execution Example
|
Calculate an Arithmetic Expression of 50000h – Y:
Enter the value of operand Y: style="background-color:navy"> 4000
The result is 0004C000
|
†The white italic text with a navy background color is entered by users.
“My grandmother started walking five miles a day
when she was sixty. She’s ninety-seven now,
and we don’t know where the heck she is.
— Ellen DeGeneres
|