gcc汇编到十六进制

mha*_*190 1 assembly hex objdump

对于实验室,我需要知道我写的汇编的十六进制指令.例如,我有bang.s:

movl 0xaaaaaaaa 0xbbbbbbbb
push 0xcccccccc
ret
Run Code Online (Sandbox Code Playgroud)

现在我想得到这些指令的十六进制代码.我该如何使用cc和/或objdump完成此操作?

我试过了:

objdump -S bang.s
Run Code Online (Sandbox Code Playgroud)

但我得到"文件格式无法识别"

Spa*_*rky 5

这就是我的工作.

1. Compile the assembly file.
2. Disassemble the object file (objdump -d objFile.o > objFile.asm)
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,它不必是目标文件.它可能是一个可执行文件.

有时,我只需要知道字节序列或两条指令.在那种情况下,我使用以下内容.

1. In my .bashrc file (Linux), add the lines ...

opcode32() {
  echo $* > tmp.S && gcc -c tmp.S -o tmp.o && objdump -d tmp.o
  rm -f tmp.o tmp.S
}

2. From the command line, use opcode32 'instruction'.  For example ...
       opcode32 'pushl %ecx'
   This yields the following output ...

tmp.o:     file format elf32-i386


Disassembly of section .text:

00000000 <.text>:
   0:   51                      push   %ecx
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.