2

The Intel® 64 and IA-32 Architectures Software Developer’s Manual Clearly shows the addressing modes for crc32 instruction in 64-bit environment:

...
CRC32 r64, r/m64
...

However, in Delphi 11 the following gets [dcc64 Error]: E2116 Invalid combination of opcode and operands in 64-bit Windows environment:

procedure crc;
asm
  crc32 r11, [r10]
end;

Is here something I regrettably miss or this is just another stupid Delphi 11 bug?!

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Zoltán Bíró
  • 346
  • 1
  • 12
  • 4
    Set the type for the second operand, `crc32 r11, qword ptr [r10]` – Brian Mar 18 '22 at 12:51
  • So you say that if there might be ambiguities in the byte size of the indirectly addressed operand mode the *Delphi* automaticallly signals a compile error? If so why the `mov [r10], 0` is still accepted, where 0 can be byte up to qword? Doesn't seem logical to me. – Zoltán Bíró Mar 18 '22 at 13:06
  • For CRC32 there is also `CRC32 reg64, reg/mem8` which means without setting the type of the memory reference there is some ambiguity as to which type is meant. For example `crc32 r11, byte ptr [r10]` is also valid. The `mov` instruction does not have this ambiguity. – Brian Mar 18 '22 at 13:34
  • It indeed has this ambiguity! `mov byte ptr [r10], 0` is equally valid as `mov qword ptr [r10], 0`. The ambiguity for `mov` is even much more dangerorus than the one from `crc32`, as a `mov` with incorrect operand size can easily overwrite data in an unwanted way. – Zoltán Bíró Mar 18 '22 at 13:41
  • 1
    A good assembler *doesn't* accept `mov [r10], 0`, because it *is* ambiguous between byte, word, dword, and qword, @Brian. NASM rejects it, with helpful error about ambiguous operand-size. A bad assembler will just pick some default which might or might not be what you had in mind! (GAS used to silently accept ambiguous operand-sizes for instructions other than `mov`, e.g. for `add`, defaulting to dword. That made zero sense; now it at least warns, unfortunately not erroring.) A generic error message like "invalid combination" is better than a silent default, but not very helpful. – Peter Cordes Mar 18 '22 at 13:44
  • @PeterCordes In this case it does mean that the Embarcadero Delphi complier is **NOT** a good assembler. Moreover, is an inconsistent one as even tie ambiguity tolerance is not the same across different instructions. Hence, the negative vote for my question is at least weird, I definitely don't deserve it. – Zoltán Bíró Mar 18 '22 at 14:01
  • Want to set @Brian's answer as the good one. How I can do it as ist's just a comment? – Zoltán Bíró Mar 18 '22 at 14:03
  • 2
    Not my vote, agreed this doesn't really deserve a downvote. And yes, unfortunately not all real-world assemblers are good. :/ NASM is one of the best, having had decades of open-source development with people improving and specializing its error messages for different corner cases. As well as carefully-chosen behaviour for corner cases. Its developers are real asm experts, not just writing an assembler as part of a compiler. – Peter Cordes Mar 18 '22 at 14:03
  • You can write up an answer yourself, putting stuff from comments into your own words. (At least the correct stuff.) You can't "accept" a comment. It's not really a duplicate, unless there's one that uses `movzx` as an example, which similarly can have different memory source sizes for a fixed register destination width. – Peter Cordes Mar 18 '22 at 14:07
  • 1
    [yasm movsx, movsxd invalid size for operand 2](https://stackoverflow.com/q/47350568) is basically the same question but for YASM/NASM syntax with movsx. I added a mention of `crc32` as another example of memory size not being implied by a register destination. Once you realize the problem is ambiguity, using `qword ptr` instead of YASM `qword` should be obvious, so I don't think anyone need to take the time to write up an answer to this question, it's sufficiently solved by a duplicate. – Peter Cordes Mar 18 '22 at 14:13

0 Answers0