문제

For a lab, I need to know the hex instructions for assembly that I wrote. For example I have bang.s:

movl 0xaaaaaaaa 0xbbbbbbbb
push 0xcccccccc
ret

Now I want to get the hex code for these instructions. How can I use cc and/or objdump to accomplish this?

I’ve tried:

objdump -S bang.s

but I get "File format not recognized"

도움이 되었습니까?

해결책

Here's what I do.

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

In the above example, it does not have to be an object file. It could be an executable file.

Sometimes, I just need to know the byte sequence for or two instructions. In that case, I use the following.

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

Hope this helps.

다른 팁

You'll need to compile(assemble) your .s file first, then run objdump on the resulting .o file.

cc or gcc normally knows how to build assembly files, so:

cc -c bang.s
objdump -d bang.o

(Ofcourse, your dump.s must be valid assembly so you can build it, what you posted here isn't)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top