I was wondering if there was a way to set the compiler to compile my code into a .bin file which only has the 1's and 0's, no hex code as in a .exe file. I want the code to run on the processor, not the operating system. Are there any settings to set it to that in the Express edition?? Thanks in advance.
-
5You sound confused; hex is just another representation of binary. An .exe is a file that contains all the binary required to run it. What is your intention with the question you are asking? – user1167662 Apr 23 '13 at 02:28
-
To build an operating system. I want it to be as low level as possible for optimal performance. – Garrett Ratliff Apr 23 '13 at 02:36
-
2What platform do you want this to run on? Building an operating system is no simple task, and I would not try to start with an OS for a typical PC like you probably have in mind. Take this from someone who has been in the same position you are, wondering how to make a simple operating system. I learned a lot by attempting the same task using a raspberry pi as the platform, and this tutorial: http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/. – user1167662 Apr 23 '13 at 02:41
-
Thanks for the advice. I have been doing C,C++,Java for a while and wanted to make a simple OS. Thanks for the link. – Garrett Ratliff Apr 23 '13 at 02:46
-
Glad I could help, hope you enjoy the tutorial as much as I did :) (PS, There are a lot of really cool things you an do with a raspberry pi besides just that tutorial, since it sounds like you are interested in that sort of thing; you would not waste your money buying one) – user1167662 Apr 23 '13 at 02:51
-
What led you to conclude that `.exe` files contain hex? As far as I know, they don't. Are you viewing a `.exe` using a hex viewer? – Keith Thompson Apr 23 '13 at 05:50
1 Answers
There is nothing magic about a ".bin" file. The extension generally just indicates a binary file, but all files are binary. So you can create a ".bin" file by renaming the ".exe" file that your linker generates to ".bin".
I presume you won't be satisfied with that, so I'll elaborate a little further. The ".exe" file extension (at least on Windows, which I'll assume since you've added a Visual Studio-related tag) implies a binary file with a special format—a Portable Executable, or PE for short. This is the standard form of binary file used on Windows operating systems, both for executables and DLLs.
So a PE file is a binary (".bin") file, but an unknown binary file with a ".bin" extension is not necessarily a PE file. You could have taken some other binary file (like an image) and renamed it to have a ".bin" extension. It just contains a sequence of binary bits in no particular format. You won't be able to execute the file because it's not in the correct, recognized format. It's lacking the magic PE header that makes it executable. There's a reason that C build systems output PE files by default: that's the only type of file that's going to be of any use to you.
And like user1167662 says in his comment, there is nothing magical about hex code. Code in binary files can be represented in either hex or binary format. It's exactly the same information either way. Any good text editor (at least, one designed for programmers), can open and display the contents of a file using either representation (or ASCII, or decimal).
I want it to be as low level as possible for optimal performance.
There is nothing "lower level" about it, and you certainly won't get any optimized performance. PE files already contain native machine code that runs directly on your microprocessor. It's not interpreted like managed code would be. It contains a series of instructions in your processor's machine language. PE files just contain an additional header that allows them to be recognized and executed by the operating system. This has no effect on performance.
To build an operating system.
Now, that's a bit different… In particular, it's going to be a lot more difficult than writing a regular Windows application. You have a lot of work ahead of you, because you can't rely on the operating system to do anything to help you out. You'll need to get down-and-dirty with the underlying hardware that you're targeting—a developer's guide/manual for your CPU will be very useful.
And you'll have to get a different build environment. Visual Studio is not going to do you any good if you're not creating a PE file in the recognized format. Neither is Microsoft's C++ linker included with it, link.exe
. The linker doesn't support outputting "flat" binary files (i.e., those with the PE header stripped off). You're going to need a different linker. The GCC toolset can do this. There is a Windows port; it is called MinGW.
I also recommend a book on operating system development. It's too much to cover in an answer to a Stack Overflow question. And for learning purposes, I strongly suggest playing with an architecture other than Intel's x86.

- 1
- 1

- 239,200
- 50
- 490
- 574