3

I have the following assembly code:

global _start
section .text
_start:

add byte [eax], al

After compiling and linking, I try to see the opcode:

$ objdump -d eax.o

eax.o:     file format elf32-i386


Disassembly of section .text:

00000000 <_start>:
        ...
$

Why do I get a null opcode?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198

1 Answers1

7

This instruction:

add byte [eax], al

Is encoded as the two byte ADD instruction 0x00 0x00:

Opcode    Instruction     Op/En   64-bit Mode Compat/Leg Mode Description
00 /r     ADD r/m8, r8    MR      Valid       Valid           Add r8 to r/m8.

OBJDUMP by default will print blocks of repeated zeros as .... To change this behavior try using the -z option as described in the manual:

-z --disassemble-zeroes

Normally the disassembly output will skip blocks of zeroes. This option directs the disassembler to disassemble those blocks, just like any other data.

Your command could look like this:

objdump -z -d eax.o 

The output should look something like:

Disassembly of section .text:

00000000 <_start>:
   0:   00 00                   add    %al,(%eax)
Michael Petch
  • 46,082
  • 8
  • 107
  • 198