Question:
how does one write a program in machine language from windows?
1970-01-01 00:00:00 UTC
how does one write a program in machine language from windows?
Eleven answers:
Mike R
2009-06-15 00:05:24 UTC
"the fastest 'simplest' one"

/sigh



Look, machine language isn't simple. At all. You'd be far better off learning something like C/C++ or Java. They're a lot easier to learn and generally perform just fine.
Shadow Wolf
2009-06-15 00:28:42 UTC
Some C/C++ compilers come with assemblers. You can look at those. I know DJGPP has an assembler but it hasn't been updated in a few years. The older Borland C/C++ compilers came with an assembler. Check your documentation for assembler requirements. Microsoft was giving away some versions of Masm.



Something you should know is there are two different assembly language syntaxes. There is the AT&T and the Intel syntax. They are not compatible with each other. The DJGPP and GNU compilers under Linux use the AT&T syntax primarily. Borland and Microsoft compilers and the Windows world in general used the Intel syntax. Go here for some more details on the differences.

http://en.wikipedia.org/wiki/X86_assembly_language



The rest is really easy. Any text editor can be used to create an assembly language program. If you become a really good hacker and get deep enough into disassembly of programs, eventually you may actually learn to write programs directly in machine code. It is much easier to work in assembly though. If you want to actually write Windows programs directly in assembler, then you'll also need a lot of detailed information on calling the Windows functions from assembly.



I suggest learning C/C++ rather than assembly. C when used correctly can be as efficient as assembly and is a lot easier to code in than assembly. You won't escape compilers since directly coding machine code is so tedious and time consuming that it is generally only good for small patch programs.



Shadow Wolf

30+ years and counting in computers
2009-06-15 07:43:58 UTC
You'd be writing in asm, as Wolf suggested. I'd reccomend NASM for the job, but there are dozens of assemblers out there. (YASM, MASM, SPASM ...)



Writing directly in machine code isn't a trivial task. You'd need to remember individual opcodes for instructions, which also change depending on the operands, then you need to remember how to encode the mod r/m byte for your operands, which is also a pain, and then fill in the operand, ensuring that is the right length too. You would need to be a complete crackpot to use this over assembly, since assembly is just readable aliases for the machine code, and no compilation takes place. Even writing an assembler isn't as simple as it first looks.



But as with already suggested, use a normal language and compiler, because you won't be very productive with assembly.



Edit: I'd have to disagree with Fred about the compiler being better at choosing instructions for you. If you know what you're doing this isn't the case, but at the same time, it's definitely more sane to use a compiler. (The performance difference is irrelevent)

Some compilers do an excellent job though (intel's own, for instance), but others do not. Register allocation and spilling is certainly one of the trickiest parts of compiler design, and even more so for JIT compiled code. I can't count the number of headaches I've had trying to optimise the algorithms, either sacrificing compile time, or making slower code.
?
2017-02-17 21:35:24 UTC
1
?
2016-11-01 06:34:41 UTC
How To Write Machine Code
2016-04-10 01:47:04 UTC
For the best answers, search on this site https://shorturl.im/axkvd



Computers don't read languages at all. At the fundamental level, the only thing computers understand is machine code. This machine code is a sequence of numbers: you have an instruction number (that tells the computer what to do) followed by the arguments to the function. So instruction 0 tells the computer to add two numbers. Then, it reads in the numbers and adds them. That gets annoying because you have to remember the numbers of all the instructions, and its difficult to read. So we made something called assembly. Assembly isn't really a programming language. It just maps the instruction numbers to the opcodes. So any time it sees "ADD" it replaces it with the number 0. Then, we built programming languages. You use a program known as a compiler to read in the language, understand what it's doing, and then output a sequence of machine instructions. That's what the executable is. An executable that came from C code is the exact same thing as an executable that came from Fortran Code, or C++ code, or anything else. Other languages use a more complex system. Java and .NET (C#, VB.NET, F#, managed C++, and others) don't get compiled to machine code. Instead, they are compiled to sort of an intermediate step, and there is a program called a virtual machine that converts the intermediate code into machine instructions. But you cannot run those programs without the VM on the computer. Other languages, like batch scripts, are interpreted. You have a program (such as CMD.exe) that reads in the file and turns it into machine instructions. Once again, the file itself is not an executable. You need the interpreter to run it. It's also not operating system dependent. A bash script (the shell used in Unix-based systems like Linux and Mac OS X) will also run in Windows, as long as a bash interpreter is installed. So, to summarize, you'll need to have some program that converts the instructions into machine code. Otherwise, the computer won't understand any languages at all.
?
2016-03-19 05:25:29 UTC
Programming languages, by themselves, are usually platform-independent. (For instance, C/C++ works on all major operating systems.) They have specifications (written in English or whatever) which details how the language works -- the syntax, operations, etc. However, in order to actually be able to use the language, someone has to implement a compiler to translate source code to machine code. Alternatively, someone has to write an interpreter which interprets source code source code and executes it on the spot. C/C++ uses a compiler. Perl/Python are examples of interpreted languages. You could also convert your made-up language into a known language, and then use their compiler. For instance, if you wrote a converter that translated your language into C code, then you could next use an existing C compiler to translate the code to machine code.
2015-08-14 05:48:12 UTC
This Site Might Help You.



RE:

how does one write a program in machine language from windows?

Specifics please.

I want to write something in machine language. I'm pretty much fed up with compilers and figure if i'm gonna waste time learning a language it might as well be the fastest 'simplest' one. I get that its hard.



Anyways how exactly does one go from windows to...
2014-05-24 13:55:57 UTC
Type Iczelion on the search bar and find Icztutes. Iczelion, whoever he may be, is a very good teacher and has some excellent lessons on Assembly language.

PZ
Fred W
2009-06-15 11:27:41 UTC
--- Added



You seem to think that "machine language" is something other than what it is. Here we go:



An Intel 8080 machine code to clear registers:



3e 00 11 00 00 21 00 00



(I just did that off the top of my head). Here is the same thing in Assembler:



mvi a,0

lxi b,0

lxi h,0



See? Not the same damn thing at all! (except that there is a one to one correspondence). Here is another example:



11 00 0a cd e3 ff



In assembler:



lxi b,(0 shl 8) + (10) ; row/column

call cursor



Or even



setcursor macro row,column

lxi b,(row shl 8) + (column)

call cursor

endm



setcursor 0,10



See how we are ATTEMPTING to approach a higher level? In C, we would use:



setcursor(0, 10);



Now, the Microsoft Assembler for x86 (MASM) supports PROC for procedure, MACRO, and a bunch of other stuff. It is actually *more* complicated than C!!!



And yet, it won't reorder or optimize for you. All of that legwork is left to you. As an example, I was optimizing some code (JBIG2 bi-level compression) for a client, and I wrote an "optimized" core loop in assembler. Optimized by manually scheduling and re-ordering instructions for a Pentium II processor. This process took me 3 days (for around 400 instructions).



I compiled a C implementation of the same routine using Microsoft MSVC 7, which took under a minutes. I was certain my assembler would be faster -- but I was wrong. The compiler generated ALMOST the same code, but ordered it differently, and was a few percent FASTER!



Like I said, the computer does bookkeeping better than humans.



--- Original Post

xxx1101xxxx



Writing in Machine Language is HARD. But, if you insist: sandpile.org documents the processors. The Windows SDK documents the API, and you will need documentation on the COFF (common object format) as well. I also recommend making up coding forms with address/instruction/detail on them. Write the code, and then generate the binary. There are around 1100 binary instruction formats, so I would recommend using an "assembler", but, heck, why not go straight to machine code? I wrote a FORTRAN compiler that way; consider it a right of passage.



If you really want to, MASM is available from Microsoft, as a free download (get the Microsoft C/C++ kit, and extract it from there). It comes with a "linker", so its probably getting too fancy, already. No, I recommend you do what I did -- grid up your address space, and manually allocate every byte. Since I was able to keep track of every byte in a 64k address space, I assume you can too (just use that 1/4" gridded paper, and stick a WHOLE bunch of them together -- crap, that's what I had to do). I mean "LINK.EXE" actually knows what a Windows format executable should look like! But, it's only bytes, and you CAN generate it by hand.



Seriously: for $DEITY sake! The computer is far better than humans at keeping track of such trivia. If you WANT to learn "low-level" programming, learn C. Entire OSs (drivers included) are written in it! And, by the way, "human generated" machine code is NOT (necessarily) the fastest! Instructions interact. For example:



mov eax,memory

add eax,ebx

mov memory,eax



is NOT the best ordering of instructions. It causes a delay while the "add" is completing, stalling the store back into memory. If you want the fastest codes, let a compiler take care of re-ordering the instructions for you.



Indeed, go up even higher level. Why compile, when you can use a Scheme interpreter (or Python, or Perl, or Ruby?). If you want speed AND convenience, use something like Gambit-C Scheme!



Back in the 70's up to the early 80's, I was FORCED to code in machine language and/or assembler. It was HELL. If you don't believe me, go and try it...



As to the "tools" you will need: basically, ANYTHING that will get bytes into a file will do. Why not use Microsoft Word, and write a quick macro that will open a file and deposit binary into it? That is more than we had when starting with a new machine. We had to generate the binary, transfer it into a ROM burner and make a ROM, *or* the machines had toggle switches for initial program entry. (Altair 8800). From there, you can write whatever software you want.



WTF are you doing torturing yourself? You do know that there is a very good reason that machines DON'T have toggle switch program entry anymore, right?
Samuel
2015-06-19 21:08:09 UTC
alright dude first you need an old computer with an amd k6 or 7 because all of the new computers cant do any old code, and the newer possessors by intel have unused bits and its just stupid because they are tring to make you use c or c++ but if you get an old computer you wont have that mess. and thats how far i am right now im still trying to download windows 98, but it is not hard once you get it people say that binary code is impossable to read but its not thats complete bull so baseicaly question everything that windows or intel tells you to do because they wont help they will only hurt and take your stuff


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...