linux - Why does the Solaris assembler generate different machine code than the GNU assembler here? -


i wrote little assembly file amd64. code not important question.

        .globl fib  fib:    mov %edi,%ecx         xor %eax,%eax         jrcxz 1f         lea 1(%rax),%ebx  0:      add %rbx,%rax         xchg %rax,%rbx         loop 0b  1:      ret 

then proceeded assemble , disassemble on both solaris , linux.

solaris

$ -o y.o -xarch=amd64 -v y.s                             as: sun compiler common 12.1 sunos_i386 patch 141858-04 2009/12/08 $ dis y.o                                                   disassembly y.o   section .text     0x0:                    8b cf              movl   %edi,%ecx     0x2:                    33 c0              xorl   %eax,%eax     0x4:                    e3 0a              jcxz   +0xa      <0x10>     0x6:                    8d 58 01           leal   0x1(%rax),%ebx     0x9:                    48 03 c3           addq   %rbx,%rax     0xc:                    48 93              xchgq  %rbx,%rax     0xe:                    e2 f9              loop   -0x7      <0x9>     0x10:                   c3                 ret     

linux

$ --64 -o y.o -v y.s gnu assembler version 2.22.90 (x86_64-linux-gnu) using bfd version (gnu binutils ubuntu) 2.22.90.20120924 $ objdump -d y.o  y.o:     file format elf64-x86-64   disassembly of section .text:  0000000000000000 <fib>:    0:   89 f9                   mov    %edi,%ecx    2:   31 c0                   xor    %eax,%eax    4:   e3 0a                   jrcxz  10 <fib+0x10>    6:   8d 58 01                lea    0x1(%rax),%ebx    9:   48 01 d8                add    %rbx,%rax    c:   48 93                   xchg   %rax,%rbx    e:   e2 f9                   loop   9 <fib+0x9>   10:   c3                      retq    

how comes generated machine code different? sun generates 8b cf mov %edi,%ecx while gas generates 89 f9 same instruction. because of various ways encode same instruction under x86 or these 2 encodings have particular difference?

some x86 instructions have multiple encodings same thing. in particular, instruction acts on 2 registers can have registers swapped , direction bit in instruction reversed.

which 1 given assembler/compiler picks depends on tool authors chose.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -