Author Topic: same instruction different opcodes  (Read 6386 times)

Offline billium

  • Jr. Member
  • *
  • Posts: 8
same instruction different opcodes
« on: February 09, 2012, 04:17:58 PM »
Hello All

About 3 years ago I did some reverse engineering on some V40 code, made some minor modifications then reassembled using NASM:
Code: [Select]
   744                                  loc_F84A4:
   745 000004A4 FA                      cli
   746 000004A5 F7040100                test word [si], 1
   747 000004A9 7528                    jnz short loc_F84D3
   748 000004AB FB                      sti
   749 000004AC 810C0100                or word [si], 1
   750 000004B0 8B5C08                  mov bx, [si+8]
   751 000004B3 8A400A                  mov al, [bx+si+0Ah]
   752 000004B6 43                      inc bx
   753 000004B7 81E3FF00                and bx, 0FFh
   754 000004BB 895C08                  mov [si+8], bx
   755 000004BE FF4C04                  dec word [si+4]
   756 000004C1 86C4                    xchg al, ah
   757                                 
   758                                  loc_F84C3:
   759 000004C3 E4C1                    in al, 0C1h
   760
 

As can be seen in the above listing the loc_F8*** align with the generated address and the or word [si], 1 instruction gives a word for 1.

Now, I needed to do another minor mod, assembled with NASM again but noticed the loc_F8s were no longer aligned.  I then noticed the or instruction only gave a byte for 1:

Code: [Select]
   690 000004AC 830C01                  or word [si], 1

I am not modding this code so I do not know, nor need to know what it does, but I do need to keep alignment, as I do not want to go through the whole code.
Can anbody see what I am doing wrong to get the different result?  I assume it is some sort of optimisation, can I force NASM to use the first type of or listed above.  There are many of these in the whole listing.

Many

Offline billium

  • Jr. Member
  • *
  • Posts: 8
Re: same instruction different opcodes
« Reply #1 on: February 09, 2012, 06:29:42 PM »
It is o.k. you can all stop paniking for me now I found the problem. :)
It looks like -O0 is not default in NASM version 2.09.10.

Many thanks

Billy

Offline wyvern666

  • Jr. Member
  • *
  • Posts: 32
Re: same instruction different opcodes
« Reply #2 on: February 09, 2012, 08:50:52 PM »
mmmm, are you sure 2.09.10?, look this output:

Quote
>NASM -v
NASM version 2.09.10 compiled on Jul 15 2011

>NASM -h
usage: nasm [-@ response file] [-o outfile] [-f format] [-l listfile]
            [options...] [--] filename
    or nasm -v   for version info

...
    -O<digit>   optimize branch offsets
                -O0: No optimization (default)
                -O1: Minimal optimization
                -Ox: Multipass optimization (recommended)
...

Offline billium

  • Jr. Member
  • *
  • Posts: 8
Re: same instruction different opcodes
« Reply #3 on: February 10, 2012, 09:45:13 AM »
Yes I copied/pasted from the v command.
That is why I posted here instead of just using -O0, because I read it was default.
Code: [Select]
NASM version 2.09.10 compiled on Aug 18 2011
Billy


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2597
  • Country: us
Re: same instruction different opcodes
« Reply #4 on: February 14, 2012, 04:07:19 PM »
'Tis true, the help screen lies. The default is now "-Ox". Worse, the "align" directive seems broken. "align 512" works, but "align 200h" claims not to be a power of two! 0.2.10rc8 seems to have "align" fixed, but the help screen still claims "-O0" is default. Sorry 'bout that!

Best,
Frank


Offline billium

  • Jr. Member
  • *
  • Posts: 8
Re: same instruction different opcodes
« Reply #5 on: February 14, 2012, 10:22:12 PM »
Its o.k. I'll just blame you for my baldness.   :)