Sign in to follow this  

I' ve written some machine code: how do I execute it?

This topic is 4662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I,ve written this machine code: 01010001010110101001001001000100110100010010101010010010101001010011011001010101010 How do I make the processor run it? Will it make something cool? EDIT: seriously, is there a way of executing it without using a compiler? [Edited by - The Najdorf on March 8, 2005 11:53:08 PM]

Share this post


Link to post
Share on other sites
No, sorry, that was meant to be a bit ironic (wasnt it funny? I guess not since my rating dropped, people here lack humor, lol)

But the question is serious. If I really wanted to execute this stuff, isnt there a way without coding it in assembly then compiling it?

Share this post


Link to post
Share on other sites
Quote:
Original post by The Najdorf
But the question is serious. If I really wanted to execute this stuff, isnt there a way without coding it in assembly then compiling it?


Convert it into hex code then type it into DEBUG?

Share this post


Link to post
Share on other sites
Quote:
Original post by benryves
Quote:
Original post by The Najdorf
But the question is serious. If I really wanted to execute this stuff, isnt there a way without coding it in assembly then compiling it?


Convert it into hex code then type it into DEBUG?


To clarify, reach DEBUG by running the command prompt and typing in DEBUG.

Share this post


Link to post
Share on other sites
Hey, thx.

I just tried the .com extension, then also the .exe extension, and it works! I mean, it gives an error, but it works! Actually I dont know if it anything with the bits I gave him. Anyone has a sequence of 1 and 0 that actually does something if we change the extension?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by The Najdorf
No, sorry, that was meant to be a bit ironic (wasnt it funny? I guess not since my rating dropped, people here lack humor, lol)

But the question is serious. If I really wanted to execute this stuff, isnt there a way without coding it in assembly then compiling it?



Hexedit an EXE file ???


I think you can get TASM Turbo assembler (Borlands) somewhere on the web for free.


Sorry, but you still dont come across as serious.


Long ago you could put hex code into a file and execute it (that was in the Z80 days), but why anyone would want to enter it that way now (instead of as ASM) ?????

Share this post


Link to post
Share on other sites
A 64 byte tunnel demo:

101100000001001111110101010000101100110100010000011
010000000000010100000000001111111011111100011010000
000000000111111000000100010001110011110111011101000
000110011011000000011001101111000000100110111110001
111100101101100000100000000010000111000001110011000
111000001110111110000011111011000110010000011000111
101011100100101101100111001001011101011110100011011
110110000011101100111111010110110000011110011011111
000001111101111101000110000000001101100111110011110
101101001000100001100100001111010101011101011110010
10

Share this post


Link to post
Share on other sites
Its more a question of "is it *theoretically* possible to write a text file with only zeros and ones, then change the extension in .exe and make it do something?"

Of course this has no practical use in programming anything, it just would be cool

Share this post


Link to post
Share on other sites
Quote:
Original post by The Najdorf
Its more a question of "is it *theoretically* possible to write a text file with only zeros and ones, then change the extension in .exe and make it do something?"

Of course this has no practical use in programming anything, it just would be cool


No, a normal executable as Windows knows it has a special PE Header. You'll need to write the PE Header from the top of your head before adding any executable code.

Toolmaker

Share this post


Link to post
Share on other sites
Quote:
Original post by Toolmaker
No, a normal executable as Windows knows it has a special PE Header. You'll need to write the PE Header from the top of your head before adding any executable code.
Toolmaker


Ok, but if I knew the right PE header in binary form I could? I mean the question is "does there exist a sequence of 1s and 0s such that saved in a text file, and changed the extension, it does *something*?"

Share this post


Link to post
Share on other sites
Quote:
Original post by The Najdorf
Ok, but if I knew the right PE header in 0101 form I could?


Yes. I remember a while back how you could create a very simple .com executable (7 bytes) just by typing in the sequence. However, 0's and 1's were not used, but rather the ascii characters alt + num. I have long lost that link though.

Share this post


Link to post
Share on other sites
You know, you can't save some text representing a binary number to a file and expect anything to happen. It's just text, it isn't actual binary data. You need a hex editor for that kind of thing.

Share this post


Link to post
Share on other sites
Thx...

I found out that if I have an "exe", I can somewhat open it as a .txt file. But if I save it, then I cant get it back to work the in the .exe form... there seems to be some information loss...

Instead, if I open it in a hex editor, I see the actual machine code, right? just that it's not in binary but in "hex"...

Does any body know what happens when a .txt file is converted into an .exe and viceversa?

Oh... I think I got it! You cant really use a text editor because it does not have a 1-1 relation with bytes! Ascii encoding might encode two different bits in the same character, so there is no way to go back!

Share this post


Link to post
Share on other sites
Text files are usually encoded as ASCII. Each byte represents a character or has a special meaning. See here.

The problem is that there isn't an ASCII code for every possible value a byte can hold, and most of the special codes will get translated or removed by your text editor, and in the process breaks your executable.

Share this post


Link to post
Share on other sites
I don't think text files normally support all the nessicary bit combinations. Also, some hex editors will show you the hex and binary. Why do you want to know this, anyway?

Share this post


Link to post
Share on other sites
Here's a (more) serious explanation.

Assuming ASCII characters and big-endian binary, a text file full of ones and zeroes would actually be a sequence of 00110000 and 00110001 (I think). That's because 00110000 binary is 48 in decimal, which is the code for the "0" character in ASCII encoding. Binary is simply base 2. Decimal, what most people are used to working with, is base 10. Also used are octal (base 8) and hexadecimal (base 16), primarily because they make it easier to read machine code.

Basically, that's as much machine code as opening a jpg file in notepad is a text file; as far as a human is concerned, the letters are "garbage" because jpg viewers interpret the binary data as image data, but notepad interprets it as a sequence of 8-bit character codes (for example).

Executable binary is a sequence of numbers representing basic commands. Imagine there's a list of numbered instructions somewhere, each number corresponding to a different action - that's what's happening here. There are also data values in there, such as memory addresses and literal values. And in the same way "100576" can be interpreted as either 1, 0, 0, 5, 7, 6 or 10, 05, 76 or 100, 576 or 100576 there is a set way, defined by the particular computer, of defining how many binary digits each number actually is (so that you can tell where one number ends and the next begins).

Almost nobody writes in binary. At the lowest level, people write in assembly language which is pretty much binary level commands except instead of having to write strings of 0 and 1 you write short instructions. When you want to run that, you run it through a program that converts the instructions into their binary form. So rather than write 00000001 to represent instruction one, you might write PUSH, which then gets converted into 00000001 by the compiler.

People rarely write in assembly language, however. Most modern languages are much higher level, and get converted into machine code by programs called compilers.

Share this post


Link to post
Share on other sites
Love the post, Skorpion. It got me thinking - how was Assembly language produced in the first place? Ultimately, someone must've gone to the binary level to program this stuff. Is it firmware or software? I think my brain is having a meltdown... :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Neo Genesis10
Love the post, Skorpion. It got me thinking - how was Assembly language produced in the first place?


Originally programming was indeed done with machine code - the programs, however, were generally of a far simpler nature - to do anything even remotely complex demands better tools for the job, and assembly fills that need perfectly. You may have noticed that each assembly language is specific to a certain processor - this is because each assembly instruction is directly equivalent to an instruction that can be carried out by the processor. See this article at Wikipedia for more information.

Share this post


Link to post
Share on other sites
Quote:
Original post by Neo Genesis10
Love the post, Skorpion. It got me thinking - how was Assembly language produced in the first place? Ultimately, someone must've gone to the binary level to program this stuff. Is it firmware or software? I think my brain is having a meltdown... :)


Ever heard for the term "bootstrapping"?

If not, search web a little or go straight to wikipedia...
I don't want to discover what it means, because searching for its IT meaning will surely lead to some laugh aside :-)))

Share this post


Link to post
Share on other sites
Yeah, on the very first machines instructions were entered manually by flipping switches to set bits. And you could see what was in the registers by the relevant lights lighting up (and watch their contents change - so slow were the early machines that it was possible to get meaningful information out of this!)

And then there's how the really early machines didn't use base two to store data, but instead Binary Coded Decimal. BCD counts the way most people count on their fingers - each finger represents one more number. Ie, 0000000001 is one, 0000000011 is two, 0000000111 is three and so on. Incredibly wasteful.

The corrolary to that is that you can practically count up to 255 on your fingers if you use them as proper bits rather than binary coded decimal. If you have advanced enough control over your fingers that you don't need to hold them down with your thumbs you could go as high as 1023 :)

Share this post


Link to post
Share on other sites
If you want to understand bootstrapping, read the following article:

Programming in Extreme Conditions


If you want to see cool machine code, nothing beats the "Hello Polyglots" program. It's raw machine code, so you just run it as a .COM program and it prints the words "Hello Polyglots". But if you open it up in a text editor you'll notice that it's also a source code at the same time, and that it'll compile into another program that does the same thing if you compile it using a C compiler. Or a Pascal compiler. Or a Fortran compiler. Or COBOL. It's also an assembly source, so you can run it through an assembler to get the same program. Also, it's a shell script. On top of all that, the exact same code is a PostScript document which happens to say "Hello Polyglots".

You have to see it to believe it. I'll see it I can find it somewhere.

Share this post


Link to post
Share on other sites

This topic is 4662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this