News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to disable MASM optimizations?

Started by pacman286, July 29, 2006, 07:10:51 PM

Previous topic - Next topic

pacman286

I have an old DOS COM program that I am trying to modify.  I've run the disassembled output through MASM and compared the old and new versions.  MASM is making optimizations to the code that is changing the size of the program and throwing off the address offsets.  As an example, the instruction "mov ax, word ptr [si+30h]" originally is 8B 84 30 00, with a word-sized displacement.  However, when MASM reassembles the program, it optimizes the instruction to 8B 44 30, with a byte-sized displacement.  I've searched unsuccessfully for a way to override this.  I would prefer not to have to go through and replace all of the offsets with labels for the few changes I need to make.  If anyone has an answer, I would greatly appreciate it!

japheth


I'm afraid you're out of luck if you no longer have the old masm version the source once was compiled with (btw, even old masm 5.1 from 1988 does this "optimization", so this must have been a really ancient version). I guess MS regarded this change as a bugfix, not an assembler optimization.

hutch--

pacman,

If the original COM file still runs OK, try a direct disassembly of it as it will give you the instructions that are doing the work. A DOS com file is far easier to disassemble in most instances and the code generated can often be easily converted back to buildable assembler source code.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MichaelW

pacman,

I could not find any way to force MASM to use a word-size displacement, but you are free to encode the instruction manually as:

db 8Bh,84h,30h,00h



eschew obfuscation

pacman286

Thanks for the responses!  What I am trying to do is to modify a hardware initialization routine for a controller card and want to keep the file size identical so that I would not have to go through the entire listing looking for these "optimizations."  However it seems that that is what I am going to have to do.  I'm sure the original program was not written in assembly language and the original compiler must not have been that intelligent.  I wonder if there is a way to accomplish this with a macro?

japheth

> I wonder if there is a way to accomplish this with a macro?

you can define an external:



externdef NULL:abs

        .CODE

        mov ax,[si+30h+NULL]
        ret


using externals, masm has no choice but to use the "long" version of the opcode.

of course, you must then also provide another module which contains:


    public NULL
NULL equ 0h





MichaelW

eschew obfuscation