Author Topic: A difference in OP-codes from MS-DOS/Windows to Linux.  (Read 6779 times)

Offline STF92

  • Jr. Member
  • *
  • Posts: 10
A difference in OP-codes from MS-DOS/Windows to Linux.
« on: July 13, 2011, 08:47:00 AM »
Nasm 2.09.09

Hi:
Code: [Select]
REG =     0    1    2    3    4    5    6    7   
------------------------------------------------------------------------------------------
ModRM values:

             ............................................                    ................
             05  0D  15  1D  25  2D  35  3D                    [DI]
             06  0E  16  1E  26  2E  36  3E                    D16 (simple var)
              ...........................................                    .............

This is a fragment of the ModRM values table for processors 80286 onwards in the intel architecture, although with extensions for later generation processors.

For an instruction of the type Logical-AND immediate byte into EA byte, of which
and byte[int_flag],0xfe is an example, the x86 manuals give

Code: [Select]
80   /4   db
Consulting the above table, column 4,  we get

Code: [Select]
8026xxxxxxxxFE
And MASM, under MS-DOS version 5.00 corroborates:
802602D3 R FE
Also, assembling with the A command of DEBUG under windows XP, I see the same output.

However, assembling with any assembler under linux, including NASM, the output is
8025xxxxxxxxFE, as if the instruction mnemonics were and byte[DI],0xfe. In the ms-dos and windows xp (DEBUG) cases the displacement is 16 bits whereas in the linux assemblers case the displacement is 32 bits. But I do not think it has anything to do with the difference in the OP-codes.

Could somebody explain this, if it is worth it?
« Last Edit: July 13, 2011, 08:52:46 AM by STF92 »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: A difference in OP-codes from MS-DOS/Windows to Linux.
« Reply #1 on: July 13, 2011, 03:58:50 PM »
I'm not sure what you're getting at, STF92. The difference you're seeing is surely not due to the OS, but the "bitness" of the code. DEBUG is incapable, of course, but what does Masm give you if you ask for 32-bit code? Nasm, running under Linux (which shouldn't make any difference) will generate 80 26 ... if asked for 16-bit code (not suitable to actually run under Linux, of course) and 80 25 ... if asked for 32-bit code. See if this helps you at all (from the old Nasm manual - newer versions don't seem to think it's "worth it"):

http://home.myfairpoint.net/fbkotler/nasmdocc.html#section-A.2.5

Best,
Frank


Offline STF92

  • Jr. Member
  • *
  • Posts: 10
Re: A difference in OP-codes from MS-DOS/Windows to Linux.
« Reply #2 on: July 14, 2011, 06:56:53 AM »
Thanks for your kind reply. "I'm not sure what you're getting at, STF92": I think my point was made clear in post #1. The mismatch between the 8026 op-code, which I expected to appear in the assembler listing and the op-code which actually appeared caused my surprise and prompted me to post.

That section of the old nasm manual makes it clear. I had consulted the Intel Architecture Software Developer's Manual, 1999. In the 2nd volume the are three double entry tables of the type shown in my first post: 16-bit Addressing Forms with the ModR/M Byte, 32-bit Addressing Forms with the ModR/M Bye and 32-bit Addressing Forms with the SIB Byte. I only saw the first one, which is the same as that printed in the 80286 manual, a hard copy of which I own from long ago.

Of course I had read all this at a certain time in the past, but I had quite forgotten. My fault and I am sorry. Good for the old Nasm manual. It is clearly explained there too. Regards.
« Last Edit: July 14, 2011, 07:00:22 AM by STF92 »