A computer runs instructions coded in binary (machine code). The available instructions usually involve registers, such as:
– Put the number 53 in the D register
– Add the contents of the A register and the C register, and store the result in the A register
– Store the contents of the E register in memory location 46
– Load the contents of memory location 30 into the B register
This all depends heavily on what CPU you’re talking about. Different manufacturers and different CPU models have different instructions available, how they’re coded in binary, what registers are available, what the registers are called, and so on.
The companies that make CPU’s usually write a (several hundred pages long) manual that tells you all of this information, and they usually put such manuals online for anyone to download a copy for free. (They have incentive to do this: You need to buy the company’s physical product — the CPU they sell — to make practical use of the information in the manual. And if you want this information, you’re a programmer writing a program for their CPU, which means the existence of your program is going to make their CPU more valuable for all of their customers.)
Assembly language is a human readable notation that’s (mostly) a 1-for-1 translation of the machine code of some specific CPU.
Here’s an example:
– Machine code: `10010100`
– Assembly language: `sub a,h`
Both mean “Take the value of the A register and subtract the value of the H register, then store the result in the A register.”
The Machine Code is completely impossible to interpret (unless you’ve memorized the manual), but you can much more easily train yourself to understand Assembly Language. That’s the main benefit of using assembly language.
Every CPU has its own machine code, and therefore its own assembly language.
You can convert machine code to assembly language and vice versa with nothing more than your brain, pencil and paper. You just need to look up how the instructions are coded in the manual.
It’s possible to write programs this way, but extremely tedious. If you have a computer, you would probably much rather have a computer program do the translating for you. This program is called an *assembler* (if it translates from instructions to machine code) or a *disassembler* (if it translates machine code to instructions).
Latest Answers