How to view machine code?

半世苍凉 提交于 2020-01-30 10:57:44

问题


I've written a program in assembly (at&t syntax) and I want to see how the machine code looks. This is how I get executable code:

as -g -o p1.o p1.s --32 -gstabs
ld -o p1 p1.o -m elf_i386

回答1:


Assuming that you are on a Linux or BSD platform (based on the fact that you're using as), you might want to try objdump.

objdump -d <binary file> will disassemble the object file, showing you machine code hex bytes on the left and the disassembled matching assembly mnemonics on the right. Here's an example:

$ objdump -d factorial

factorial:     file format elf64-x86-64

Disassembly of section .init:

00000000004003f0 :
  4003f0:   48 83 ec 08             sub    $0x8,%rsp
  4003f4:   e8 73 00 00 00          callq  40046c
  ..
Disassembly of section .plt:

0000000000400408 :
  400408:   ff 35 e2 0b 20 00       pushq  0x200be2(%rip)        # 600ff0
  40040e:   ff 25 e4 0b 20 00       jmpq   *0x200be4(%rip)        # 600ff8
  400414:   0f 1f 40 00             nopl   0x0(%rax)

objdump is a part of the binutils package on Linux platforms.



来源:https://stackoverflow.com/questions/36900387/how-to-view-machine-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!