assembly - gcc 汇编到十六进制

标签 assembly hex objdump

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

movl 0xaaaaaaaa 0xbbbbbbbb
push 0xcccccccc
ret

现在我想获取这些指令的十六进制代码。我如何使用 cc 和/或 objdump 来完成此操作?

我试过:

objdump -S bang.s

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

最佳答案

这是我的做法。

1. Compile the assembly file.
2. Disassemble the object file (objdump -d objFile.o > objFile.asm)

在上面的例子中,它不一定是目标文件。它可以是一个可执行文件。

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

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

希望这对您有所帮助。

关于assembly - gcc 汇编到十六进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22208473/

相关文章:

c - 用于求平方根的最快汇编代码。需要解释

c++ - 弄清楚网络、十六进制和 ascii 如何交互

c++ - nm、objdump 和 pfunct 给出相互矛盾的答案来检查函数是否内联

c - 在 Mac OS X 上组装和链接 gcc 生成的程序集

linux - 使用系统调用在程序集中保存 DNS 响应

javascript - JavaScript 中 parseFloat 的第二个参数?

c - 打印某个变量的整个地址 block

我可以给 objdump 一个地址并让它反汇编包含函数吗?

linux - objdump 调整 gnu 实用程序中的 vma 偏移量

c++ - 静态大小数组的堆栈保护的预期行为是什么?