I'm specifically talking about the intel x86 processor. For the MOV function I am very confused on when I should use byte ptr when working with immediate values. For example, mov esi, 5000 ... Would I have to include ptr in this case??? I know for this operation particularly you have to: mov byte ptr (esi), 15 .... Other examples online people say an operation like mov ax, 7 is valid. I am confused when to include the ptr when handling immediate values with mov functions as some people are writing mov functions with immediate value without using ptr like I stated above. Can someone please explain?? Thank you. BTW this is regarding intel x86.
Asked
Active
Viewed 30 times
0
-
`byte ptr` is for memory operands, not immediates. – fuz Feb 14 '21 at 11:49
-
1You only ever use `ptr` to indicate a memory operand, e.g. `mov mem, imm` such as `mov dword ptr [esi], 5000` to store `5000` to memory. And then the ptr is because of the memory destination, not the immediate source. – Peter Cordes Feb 14 '21 at 11:50
-
@PeterCordes thank you so much!! So to clarify, anytime you're using a memory operand that has an immediate source that is when you have to use such things like ptr/dword/etc ? – Safoorah Siddiqui Feb 14 '21 at 12:09
-
1Yup, otherwise the operand-size is ambiguous (with neither operand being a register to imply it). Or in MASM to override the default size of an array, e.g. to load 4 bytes from an array like `foo db 1, 2, 3, 4, 5, 6` into EAX you might need `mov eax, dword ptr [foo+1]`, because MASM tries to be helpful and would actually complain about size mismatch if you didn't override. – Peter Cordes Feb 14 '21 at 12:24
-
Not all assemblers care that much when using `mov` since the register outside the brackets usually gives the assembler enough info to choose the correct size. But, for example, if you're trying to increment some value in memory, the assembler needs to know the intended data size. So you'd type `inc byte ptr [myVariable]` for example. – puppydrum64 Dec 22 '22 at 18:11