open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
982 stars 160 forks source link

wasm produces two different opcodes for two similar instructions. #50

Open beketata opened 10 years ago

beketata commented 10 years ago

There are two simalar assembler instructions:  cmp   ax, word ptr 12h  cmp   ax, word ptr 1212h

Generated code expects to be as follow:  3D 12 00 - CMP Immediate (word) with accumulator  3D 12 12 - CMP Immediate (word) with accumulator

But for some reason wasm produces two different opcodes:  83 F8 12 - CMP Immediate (byte) with register  3D 12 12 - CMP Immediate (word) with accumulator

jmalak commented 10 years ago

WASM do instruction encoding selection in dependency on operands. In first case immediate operand is byte value that WASM select some suitable instruction encoding In second case operand is word that encoding can be different from first case. Difference is more visible for 32-bit cmp eax,dword ptr 12h cmp eax,dword ptr 1212h cmp eax,dword ptr 121212h

0000 83 F8 12 cmp eax,0x00000012 0003 3D 12 12 00 00 cmp eax,0x00001212 0008 3D 12 12 12 00 cmp eax,0x00121212

beketata commented 10 years ago

For the next two lines it's acceptable behaviour: cmp   ax, 12h cmp   ax, 1212h but explicitly size derectives as BYTE PTR, WORD PTR or DWORD PTR are not a suggestions, there are "forced" rules.

P.S. MASM behaviour in this case depends on operands size declaration. WORD PTR produces "3D XX XX" code as expected.

jmalak commented 10 years ago

I am not sure if wasm has some option to suppress encoding optimization, it is default behaviour. Anyway I will review wasm to fix it.