How do compilers write to .exe files, and what do they write to them?

I want to program a simple assembly language compiler for the experience, but I don't know what compilers write to the .exe files they create. I'm pretty sure it writes 8 digit binary numbers, but I don't know which numbers do what. Any help would be appreciated, thanks.
I'm not entirely sure what you're asking. You can find binary character maps online if you want, but when you say
write to the .exe files
I think maybe you're confused about the nature of a .exe file.
I mean machine code. According to Wikipedia, the following two lines are equivalent:

10110000 01100001

And

MOV AL, 61h

Both of these mean to store the integer 97 in AL, I think.
.exe file mostly contains your program translated into machine language. To get some understanding of what machine language is, you'll have to look into http://en.wikipedia.org/wiki/Assembly_language
Last edited on
That's what I'm currently reading. I couldn't find much in that page about what assembly languages get compiled to, though.

These are translated by an assembler to a stream of executable instructions that can be loaded into memory and executed.


I'm asking what these executable instructions are, sorry if my question was too vague.
Last edited on
I should elaborate. If a program can be expressed in a list of independent instructions from some fixed set, surely you can assign a number for each of them. You can think of machine language as a numeric representation of assembly (though it's really the other way around). To see how to convert from one to another, you could take a look at http://www.intel.com/content/dam/doc/manual/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf
Also, you can't just write a program in binary (1's and 0's). The system bus does not work that way.
But isn't that what compilers do? They compile the source files into object files, then link them into an executable. Aren't executable files lists of binary commands?
I assume Computergeek was thinking about something else (whatever that could be)..
You can surely write a program yourself, using a hex editor. Note that exe contains things other than executable code. .com files are the most simple executable format. They only contain the code. If you want to play around with that, get yourself an assembler, such as http://flatassembler.net/ , and a hex editor.
Oh, I think I know what Computergeek01 was talking about. You can't write a program in 1's and 0's because they are characters and take up one byte, not one bit.
Last edited on
Just to add on, back in the old days, the way to make your scores whatever super high is to use hex editor to open up some binary files and go to some file byte offset and amend the value inside. At least it works in Koei games back in the 80's :P
Topic archived. No new replies allowed.