Search code examples
cassemblygnu-assembler

Uncertain about some instructions in disassembly of data section


I wrote the following assembly program and I am unsure about the meaning of some of the compiled instructions, and the syntax in which it is presented by objdump.

Compiled with gcc version 4.4.3, linux kernel version 2.6.32-21

hello.S:

.global _start
.global main

.section .text

_start:
    call main

    movl $1, %eax
    movl $0, %ebx
    int $0x80

main:
    // Print "Hello World" to the screen
    movl $4, %eax
    movl $1, %ebx
    movl $hello, %ecx
    movl $13, %edx
    int $0x80

    // Exit programme with return value 0
    movl $1, %eax
    movl $0, %ebx
    int $0x80

.section .data
    hello: .string "Hello world!\n"

And compiled with command

gcc -nostdlib hello.S -o hello

Generates the following instructions, in particular under the .data section: gs, insb, and outsl; What is the purpose of these instructions?

Disassembly of section .data:

080490ec <hello>:
 80490ec:   48                      dec    %eax
 80490ed:   65                      gs
 80490ee:   6c                      insb   (%dx),%es:(%edi)
 80490ef:   6c                      insb   (%dx),%es:(%edi)
 80490f0:   6f                      outsl  %ds:(%esi),(%dx)
 80490f1:   20 77 6f                and    %dh,0x6f(%edi)
 80490f4:   72 6c                   jb     8049162 <_end+0x66>
 80490f6:   64 21 0a                and    %ecx,%fs:(%edx)

Also, syntax such as %ds:(%esi),(%dx) - what does this mean?


Solution

  • In order to not get inapt disassembly of section .data, don't use objdump option

    • -D, --disassemble-all Display assembler contents of all sections

    but rather

    • -d, --disassemble Display assembler contents of executable sections

    and in addition

    • -s, --full-contents Display the full contents of all sections requested

    to get a dump of the data:

    Contents of section .data:
     80490a8 48656c6c 6f20776f 726c6421 0a00      Hello world!..