Compiling C for raw binary

Asked

Viewed 181 times

1

How to compile a C code for low level? (.bin, example).

I’m using IDE Code::Blocks, and the mingw compiler (I’m on Windows, but if you know for Linux the commands are almost identical).

  • What is C baico level? Ask the question of inline Assembly apart from this, it’s another matter. Here we don’t give out handouts, we only answer specific questions. If you want some information in this sense, look at the tag: http://answall.com/tags/c/info

  • You will ask the question of inline Assembly?

2 answers

5


If I understand, you want to generate a raw binary file without an OS dependent format. If this is it, it’s a very basic question for something that’s just the tip of iceberg, it’s not simple to mess with it, but all right, you can answer.

Do you already know that you won’t be able to use any function that relies on system calls? Not even indirectly. You will have to handle some things not at hand, since the compiler assumes certain conditions. It almost pays to do in Assembly even.

To compile does not change anything. To link changes. You can do this too:

cc -c main.c
objcopy -O binary main.o main.bin

Check like this:

objdump -d main.o
hexdump -C main.bin

It has to be the same.

You probably want to study it here. Especially that.

  • Excellent, thanks.... While at inline Assembly, I got content that talked about and I got it. Thanks. o/

  • 1

    But if you want to ask to leave it on record here, it would be cool, you can post the answer too.

-1

Uses gcc -S option: https://gcc.gnu.org/onlinedocs/gcc-2.95.2/gcc_2.html#SEC4

-S
Stop after the Stage of Compilation Proper; do not Assemble. The output is in the form of an Assembler code file for each non-assembler input file specified.

By default, the Assembler file name for a source file is made by replacing the suffix '.c', '.i', etc., with '.s'.

Input files that don’t require Compilation are Ignored.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.