As the question states,
What's the difference between (for example) mov eax, 0
and mov eax, dword 0
?
I've been using cmp statements, and I can't catch the difference. Is one an address and the other a numerical value?
As the question states,
What's the difference between (for example) mov eax, 0
and mov eax, dword 0
?
I've been using cmp statements, and I can't catch the difference. Is one an address and the other a numerical value?
As stated, no difference for the MOV instruction. For CMP, you would have difference between
CMP memory address of a qword,a 32 bit immediate
is different from
CMP memory address of a qword,an 8 bit immediate
as the comparison will be done after a sign extension, and hence, with a smaller dimension immediate number, expecially when its a negative number, some caution is advised.
Have fun programming...
It does not make a difference with a register since the name of the register already tells the assembler "how big" the data item (in this case, 0
) is:
mov eax, dword 0 ; move a 4-byte 0 into eax
mov eax, 0 ; move a 0 into eax (eax is 4 bytes, so move 4 bytes)
However, there are cases where you might want to be able to specify how large the value is since there's a choice. In x86 32-bit assembly, the following would push a 4-byte 0
value on the stack:
push 0 ; push 4-byte 0 onto the stack
If you wanted to push a 2-byte 0
value, you would use:
push word 0
If you wanted to be explicit so it's clear for the 4-byte immediate push, you could use the dword
:
push dword 0
If you want to move an immediate value to memory, the size specifier becomes necessary because the assembler doesn't know how large the data item is otherwise. For example, consider the following code in nasm
assembly:
section .bss
num resb 4
...
section .text
...
mov [num], 0
This will generate an error:
error: operation size not specified
So you need to specify the size, say, 4-bytes:
mov [num], dword 0
They are exactly the same thing, it's just assembler syntax.
As a side note, xor eax, eax
is generally preferred since it generates a two byte instruction which is much smaller.