0

I think I am confused by the rules of this. Is it allowed to move something between a register and a memory block without specifying the pointer width? Shouldn't it be defaulted to copy the number of bytes matching the register if nothing is specified? Such as

mov eax, [ebp-08h]

Is it illegal or it simply moves the 4-byte starting at ebp-08h? And is it allowed to copy something that is shorter than the register?:

mov eax, BYTE PTR [ebp-08h]

which sends one byte at ebp-08h to the lowest byte of eax? Or it has to be a register that strictly matches the data (in this case: al)?

And when using LEA, since it only computes and copies the address value, not the content at that address, what is the point of specifying "DWORD/WORD/..."? Shouldn't addresses have a fixed width on one system (always 32/64) ?

If the the address in LEA can also be specified with a width: Then

mov eax, QWORD PTR [rbp-08h]
lea eax, QWORD PTR [rbp-08h]

The specifier of the 2nd operands are interpreted differently. In mov, QWORD PTR means the content at the address is 8 byte, while in lea, it means the ptr itself is 64bit. But isn't this redundant because rbp itself is always 64bit? Is this true about this inconsistency?

And what if in LEA the address is longer than specified: lea eax, DWORD PTR [rbp-08h] and what exactly does this do? Does it truncate the higher 4 byte of the value rbp-08??

old_timer
  • 69,149
  • 8
  • 89
  • 168
vrships
  • 1
  • 1
  • 3
    That depends on your assembler, but in most you can omit the size specifier if it can be deduced from the operands. Yes, the operands must match the size, you can't do `mov eax, byte ptr`. `lea` doesn't care what your pointer is pointing to, the size specifier is irrelevant and can be omitted usually. – Jester Jul 06 '20 at 22:58
  • As Jester days, there is no single standard x86 assembly language syntax; nasm, masm, gas, etc all have differences. Yours looks similar to masm, but you should specify exactly what assembler you are using. – Nate Eldredge Jul 06 '20 at 23:16
  • In the case of MASM, usually the operand size is only needed when the operands don't already imply a size, such as a move immediate to memory (mov byte ptr[rbx],1), or movzx (movzx rax, byte ptr[rbx]). If the memory operand is in the data section and has a label, then the label will have an implied operand size, such as `byte_array db 256 dup (?)`, but an operand size override could be used (movdqu xmm0, xmmword ptr byte_array). – rcgldr Jul 06 '20 at 23:47
  • 1
    What happened when you tried it? Did you notice the difference with and without? – old_timer Jul 07 '20 at 01:53

0 Answers0