Author Topic: nasm OPCODE !?  (Read 17728 times)

nobody

  • Guest
nasm OPCODE !?
« on: June 09, 2007, 10:31:13 PM »
Hello nasm people,
                   I have assembled some code which runs fine, but am at a loss to understand the following excert from the code :

1    [org 0x100]
2    [bits 16]


3    6631DB   START: XOR EBX,EBX
4      8CDB          MOV BX,DS
5    66C1E304        SHL EBX,4
6    6689D8          MOV EAX,EBX

I understand that the 66-prefix byte is due to using a 32-bit instruction after the [bits-16] command. But why on line 3 is the opcode '31' present when an xor on two 32-bit registers should generate an opcode of '33' ?
Also again on line 6.  The opcode for a 32-bit reg-reg mov instruction should generate '8B' and not '89'.    Can you enlighten me on this please ?
Regards, steve.

nobody

  • Guest
Re: nasm OPCODE !?
« Reply #1 on: June 10, 2007, 07:52:35 AM »
> But why on line 3 is the opcode '31' present when an xor on two 32-bit registers should generate an opcode of '33' ?

Why?  For registers, the encodings are functionally equivalent:

31/r  XOR r/m32,r32
33/r  XOR r32,r/m32

i.e., both can encode XOR r32,r32

> The opcode for a 32-bit reg-reg mov instruction should generate '8B' and not '89'.

Why?  For registers, the encodings are functionally equivalent:

89/r  MOV r/m32,r32
8B/r  MOV r32,r/m32

i.e., both can encode MOV r32,r32


Some instructions have a one byte size reduction if you preference the accumulator.  I've seen some people complain that NASM doesn't assemble the same byte sequences as other assemblers.  Supposedly, someone produced a MASM compatible version.  Does anyone know if there any reason, besides compatibility, to prefer '31' over '33', etc?


Rod Pemberton

nobody

  • Guest
Re: nasm OPCODE !?
« Reply #2 on: June 11, 2007, 01:42:36 PM »
> I've seen some people complain that NASM doesn't assemble
> the same byte sequences as other assemblers.

Those people should use those other assemblers then.  :-D

> Does anyone know if there any reason, besides compatibility,
> to prefer '31' over '33', etc?

Aside from watermarking code, there is absolutely none.