What is assembly language useful for?
I'd say:
- On a modern machine, understanding at least roughly how assembly / machine instructions* work helps you understand how some code you wrote in a compiled language such as C will be translated. For example, your typical C program is structured into various functions you've written yourself, library functions etc., but assembly is just a linear list of instructions; understanding how one is translated to the other will give you a deeper understanding of what you are actually telling the processor to do when you write your code.
- You could use it to program small 8 or 16-bit microcontrollers; however, nowadays there are C compilers for most microcontrollers.
If your goal is to just get a deeper understanding of how compilations and processors work, I actually wouldn't recommend trying to learn modern x86 - the list of instructions has grown ludicrously long. So unless you have some specific reason for needing to know x86 assembly, like you're trying to debug something at that level, you're looking at very specific optimizations, etc., I'd suggest looking at a much simpler microcontroller, such as a Microchip 8-bit PIC, or for example the Atmel ATmega328 (now owned by Microchip as well). The latter is the basis of the Arduino Uno, it's got an instruction setPDF that's not too huge.
Modern hardware has grown pretty complex, which is why learning the concepts on a simpler embedded system is IMHO helpful: How a processor stores its instructions, fetches them, executes them, reading and writing from/to RAM to do so, interrupts, various buses, low-level "peripherals" (like UART controllers), and so on. All of these concepts translate (more or less) to modern machines, except that they are much more complex there. But the basic building blocks of how a CPU communicates with the rest of the hardware in the system are the same.
* Note: Many people use the term "assembly" interchangeably with "machine instructions", and in many cases this is true, assembly is often just a textual 1-to-1 representation of the actual binary instructions the processor will directly execute. But to translate that textual representation into a binary format requires a translator program, and often these add a few features that actually mean that the "assembly" is not exactly the same as the machine instructions. But they're close enough that this distinction often doesn't matter.
How could it relate to Perl?
Perl is several steps away from assembly. The perl interpreter, which parses your Perl code into an intermediate representation and executes that, is itself written in C, which of course is compiled to machine instructions. So it's not like Perl code is directly translated to machine code - perl is an interpreter.
From your node here:
If assembly is fundamental, and machine code is the most fundamental, why would I have to download a program to run it? I do not want to download a program to be able to run it. There should be a way to access the processor directly (possibly through terminal) where I could write "000 101 100 ..." and have it output "101 001" (these numbers do not mean anything real)
The reason it's not that simple is that on a modern machine there are tons of of intermediate steps and layers. Take the "Hello, World" examples from this Introduction to UNIX assembly programming or this NASM Tutorial:
- You need to edit and store the textual assembly program, which requires pretty much all components of the computer and OS (on modern machines and modern OSes, trying to learn to input binary assembly would be a gargantuan task).
- You need to install the program that will take your textual assembly program and translate it to binary representation (e.g. GNU Assembler or NASM, or others for Windows), plus the step of linking.
- Something as seemingly simple as running a binary is already a pretty complex topic: The OS needs to find the binary on the hard disk (a complex interaction in itself), load that into RAM, and ask the processor to run that; the processor then needs to fetch the instructions it is to run. (Compare this to a small microcontroller, where the program memory and RAM are contained entirely on the same chip and are directly accessible to the CPU.)
- You need to consider that your assembly program can't "just take" something from the command line or standard input and "just output" something - all of these tasks require you to interact with the operating system, which provides and abstracts these I/O services. Your suggestion of "access[ing] the processor directly" will not really work due to security restrictions of the OS and processor. (If you wanted something as simple as you seem to be asking about, then you could consider something like the Arduino Button Tutorial as the basis for how to actually do really raw I/O with a processor - maybe wish for an Arduino Starter Kit for Christmas? ;-) )
- Once your assembly program has been compiled to a binary, then yes, you don't necessarily need to download anything other than the binary itself, however, that binary will be specific to the processor architecture, OS, and libraries it was compiled for. (If your goal is to write code that gets compiled down to binary machine instructions, then there are much better ways to do so than assembly, such as C, which is still very close to the hardware and machine code, but much nicer to code in relative to assembly.)
It's all these layers that make your question pretty broad and hard to answer better without knowing more about why you're asking - I could suggest you could get a degree in Computer Engineering, then you'd learn about all of the above topics, but perhaps you're looking for something more specific?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.