For this C source code:
int add(int a, int b) { return a + b; }
, the Watcom C Compiler for 8086 (wcc -s -ms -os -0 prog.c
) generates the following machine code (hex): 01 D0 C3
, disassembling to add ax, dx
(01 D0
) + ret
(C3
).
For this assembly source code:
PUBLIC add_
EXTRN _small_code_:BYTE
_TEXT SEGMENT BYTE PUBLIC USE16 'CODE'
add_: add ax, dx
ret
_TEXT ENDS
END
, the Watcom Assembler (WASM, wasm -ms -0 prog.wasm
) generates the following machine code (hex): 03 C2 C3
, disassembling to add ax, dx
(03 C2
) + ret
(C3
).
Thus they generate a different binary encoding of the same 8086 assembly instruction add ax, dx
.
FYI If I implement the the function in Watcom C inline assembly, then the machine code output will be the same as with WASM.
A collection of different instruction encodings:
add ax, dx
. wcc:01 D0
; wasm:03 C2
.mov bx, ax
. wcc:89 C3
; wasm:8B D8
.add ax, byte 9
. wcc:05 09 00
; wasm:83 C0 09
.
How can I make the Watcom C compiler (for C code) and WASM generate the instructions with the same binary encoding? Is there a command-line flag or some other configuration option for either? I wasn't able to find any.
The reason why I need it is that I'd like to reproduce an executable program file written in Watcom C by writing WASM source only, and I want the final output be bit-by-bit identical to the original.