The MOV instruction
Copy the second operand into the first operand.
Format of the MOV instruction
| Instruction | Description |
|---|---|
| MOV reg/mem8, reg8 | Copy reg8 into reg/mem8. |
| MOV reg/mem16, reg16 | Copy reg16 into reg/mem16. |
| MOV reg8, reg/mem8 | Copy reg/mem8 into reg8. |
| MOV reg16, reg/mem16 | Copy reg/mem16 into reg16. |
| MOV AX, moffs16 | Copy a word from (seg:offset) into AX. |
| MOV moffs8, AL | Copy AL into (seg:offset). |
| MOV moffs16, AX | Copy AX into (seg:offset). |
| MOV reg8, imm8 | Copy imm8 into reg8. |
| MOV reg16, imm16 | Copy imm16 into reg16. |
| MOV reg/mem8, imm8 | Copy imm8 into reg/mem8. |
| MOV reg/mem16, imm16 | Copy imm16 into reg/mem16. |
Copies the second operand into the first operand. The source operand can be an immediate value, a general-purpose register, a segment register or a memory location; the destination can be a general-purpose register, a segment register or a memory location. Both operands must be of the same size, which can be a byte or a word.
Instruction mov cannot be used to load the cs register. An attempt to do so results in an invalid opcode exception (#UD). To load the cs register, use the far jmp, call or ret.
Usage example
title .model small .stack 100h code segment public ; Start of the code segment assume cs:code ; Start of the main procedure main proc mov ax, 35 ; Copy the decimal value 35 into the ax register mov bx, 1234h ; Copy the hexadecimal value 1234 into the bx register mov cx, 00010011b ; Copy the binary value 00010011 into the cx register mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Second example: loading the address of a string
The example demonstrates the use of seg:offset to load the address of a string and display it on the screen. There are 3 variants with the same result. You choose which one to use.
title .model small .stack 100h data segment public ; Start of the data segment string db "Hello", 0Ah, 0Dh, 24h data ends ; End of the data segment code segment public ; Start of the code segment assume ds:data, cs:code ; Start of the main procedure main proc mov ax, seg data ; Get the data segment address and store it in ax mov ds, ax ; Pass the data segment address from ax to ds mov ah, 09h ; Copy the string output function number into ah mov dx, offset string ; Load the address of the variable string into dx (ds by default) int 21h ; Call the interrupt mov ah, 09h ; Copy the string output function number into ah mov dx, offset ds:string ; Load the address of the variable string into ds:dx int 21h ; Call the interrupt mov ah, 09h ; Copy the string output function number into ah mov dx, offset ds:[string] ; Load the address of the variable string into ds:dx int 21h ; Call the interrupt mov ax, 4C00h ; Copy the termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".