I am converting 32-bit and 64-bit assembly language files from gas to MASM format, and ran across an instruction in my code that seems completely problematic. What I mean is, I see no way the assembler can know what size the operand is, whether the instruction fetches 8, 16, 32 or 64 bits from memory to perform the compare. Here is the instruction:
- cmp $0, 8(%rsp)
If the instruction had been one of the following, the assembler could have figured out the size of the memory operand to fetch and compare based upon the register:
- cmp %rax, 8(%rsp)
- cmp %eax, 8(%rsp)
- cmp %ax, 8(%rsp)
I would have thought that the instruction needs to be cmpb, cmpw, cmpl, cmpq... but no, my program assembles it fine with just cmp instruction. Unfortunately, I don't remember what this code is doing, and it is very non-obvious... so the easier way to resolve this is to know what the instruction is doing.
Anyone know? Anyone understand why this syntax (with operand size/type unspecified) is even allowed with an immediate operand?