- Copies data from source operand to destination operand
MOV destination, source
- Cannot copy data from smaller to larger operand. For example if you are going to copy 16-bit data to a 32-bit register, set first the 32-bit register to 0 and use its lower 16-bit part.
.data
count WORD 1 ; 16-bit value
.code
mov ecx,0 ; 32-bit register
mov cx,count ; lower 16-bit part
- But if you use immediate operands (no data labels) and you copy a smaller to a larger operand, it will work. The upper bits of destination will be cleared out (equal to 0).
.code
mov eax,0ffh
; eax = 0x000000ff
- If the source operand is a data label, it copies data from that memory location to the destination operand. To copy only the memory address (and not the data), use
offset
operator.
mov eax,offset myVal ; copies memory address 0x00B8102B to eax
mov eax,myVal ; copies data contained in 0x00B8102B to eax
mov eax,[myVal] ; same as above
- If the source operand is a register and contains a memory address, you must dereference it if you want to get the actual data.
mov esi,offset myVal ; copies memory address 0x00B8102B to esi
mov eax,esi ; copies memory address 0x00B8102B to eax
mov ecx,[esi] ; copies data located in memory address 0x00B8102B to ecx
MOVZX (MOV with zero-extended)
- Allows directly moving smaller operand to larger operand by adding 0’s on remaining part (like a padding)
.data
byteVal BYTE 10001111b ; byte is 8 bits
.code
movzx ax, byteVal. ; ax is 16-bit
- This can only be used on the following type of operands
- If higher bits of destination register has contents, those will be overwritten by 0.
MOVSX (MOV with sign-extended)
- Similar to
MOVZX
- The destination operand MSB is set to the MSB of the source operand
.data
byetVal BYTE 10001111b
.code
movsx ax, byteVal
No comments:
Post a Comment