14

I started a project to get a better understanding on how to compile a game for Windows 3.x. I tried to set up the build workflow so that it produce the byte-exact clone of a great open sourced Win16 game named Hyperoid. It took some time to get a working build for Windows 3.0 which I finally managed. However, no matter how I played with the compiler and linker options, I was not able to produce a similar EXE in some aspects.

One of them is related to stack handling. I see it in the disassembly that while the original EXE does push CONSTANT instructions, the rebuilt one usually put the constant to the AX register and does a push ax.

Original:

push 02FC
push 0000
push ds

New:

mov ax, 02FC
push ds
push ax
sub ax, ax
push ax

No matter how I played with the CL options, I was not able to change this behavior.

Is there a way to set up the Microsoft C 6.0 compiler to make it prefer constant push instructions over doing the same indirectly using registers?

(More details are in the project link above.)

2
  • 10
    PUSH immediate is a 286 instruction. Is the compiler currently set to produce 286 code, or 8086/8088 code?
    – Justme
    Sep 8 at 21:19
  • Thanks a lot! I was certain that /G2 option do not solve this issue but it did! I must be missed it when I set it previously. Sep 8 at 22:15
17

The compiler needs to be configured to allow the usage of 286 opcodes with the /G2 option.

2
  • 1
    push-immediate (and shift/rotate-immediate, and imul-immediate) were actually new in 186. See ulukai.org/ecm/insref.htm and search for 186. But 80186 didn't get much use in desktops, so I guess MS C doesn't have a 186 option? If so, then yeah the lowest CPU-feature level to include those instructions would be 286. Sep 10 at 2:14
  • As Peter Cordes said, these instruction were added in the 186. They are also implemented in the NEC V20/V30 processors. So some XT class machines can make use of them. This said, I checked and there was a /G1 option in MS-C 5.1, 6 and version 7. We used it as our products we built were 80188/80186 based (Am186EM also). Sep 10 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.