[ACCEPTED]-How exactly do executables work?-instructions
Executables are binary files that are understood by 18 the operating system. The executable will 17 contain sections which have data in them. Windows 16 uses the PE format. The PE Format has a section which 15 has machine instructions. These instructions are 14 just numbers which are ordered in a sequence 13 and is understood by the CPU.
A function 12 call to MessageBox(), would be a sequence 11 of instructions which will
1) have the address 10 of the function which is in a DLL. This 9 address is put in by the compiler
2) instructions 8 to "push" the parameters onto 7 a stack
3) The actual function call
4) some 6 sort of cleanup (depends on the calling 5 convention).
Its important to remember that 4 EXE files are just specially formatted files. I 3 dont have a disassembly for you, but you 2 can try compiling your code, then open your 1 EXE in visual studio to see the disassembly.
That is a bloated question if I ever saw 25 one. BUT, I will try my best to give an 24 overview. In a binary executable there are 23 these things called "byte codes", byte codes 22 are just the hex represtation of an instruction. Commonly 21 you can "look up" byte codes and convert 20 them to Assembly instructions. For example: The 19 instruction:
mov ax, 2h
Has the byte code representation:
B8 02 00
The 18 byte codes get loaded into RAM and executed 17 by the processer as that is its "language". No 16 one sane that I know programs in byte code, it 15 would just be wayyyy to complicated. Assembly 14 is...fun enough as it is. Whenever you compile 13 a program in a higher level language it 12 has to take your code and turn it into Assembly 11 instructions, you just imagine how mangled 10 your code would look after it compiles it. Don't 9 get me wrong, compilers are great, but disassemble 8 a C++ program with IDA Pro Freeware and 7 you will see what I am talking about. That 6 is executables in a nutshell, there are 5 certainly books written on this subject. I 4 am not a Windows API expert, but someone 3 else can show you what the instruction would 2 look like for calling the Windows API "MessageBox". It 1 should only be a few lines of Assembly.
Whatever code is written (be it in C or 17 some other language) is compiled by a compiler 16 to a special sort of language called assembly 15 (well, machine code, but they're very close). Assembly 14 is a very low-level language, which the 13 CPU executes natively. Normally, you don't 12 program in assembly because it is so low-level 11 (for example, you don't want to deal with 10 pulling bits back and forth from memory).
I 9 can't say about the MessageBox
function specifically, but 8 I'd guess that it's a LOT of instructions. Think 7 about it: it has to draw the box, and style 6 it however your computer styles it, and 5 hook up an even handler so that something 4 happens when the user clicks the button, tells 3 Windows (or whatever operating system) to 2 add it to the taskbar (or dock, etc), and 1 so many other things.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.