Wednesday, 14 June 2017

Assembler and Dissassembler

LLVM provides two different representation after generating the hardware instructions. The .s file (assembly representation) and .o file ( the object file). They are just two different "IR". If we want to generate the .o file from .s file, we need to call the assembler (usually /usr/bin/as). If we want to do the opposite, we can use objdump -d (meaning disassemble)

The assembler and disassembler together can be used to modify the assembly and do some testing.

e.g. :

clang a.c -S -O2 -o a.s

do some modifications to the a.s

clang a.s -o a.out (here clang implicitly invoke the assembler to generate exe)

You can also do (equivalent to the above):

assemble:
/usr/bin/as  a.s -o a.o

clang a.o -o a.out 

To look at the assembly of .o or exe
disassemble:
objdump modified.o-d > modified.out.disassembly
objdump modified.out -d > modified.out.disassembly

No comments:

Post a Comment