in reply to Assembly language
I like Perl, because it allows me to write programs that run on both Linux and Windows. And I am right now transitioning from using Windows to Linux. What better way to become familiar with Linux than to learn how to program Linux! It's like having a foot in the door. The cool thing about Perl is that if you are a perl programmer, you have full control over DOS, Linux, Windows, OSX, and you can also be a backend developer! Just have to learn ONE language. That's all.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Assembly language
by marto (Cardinal) on Dec 14, 2019 at 18:45 UTC | |
"If you write an assembly program for Linux, it won't run on DOS or Windows. So, even if the program is designed to do a very simple task such as calculate the value of PI. No file access needed. No internet access needed. No libraries have to be loaded. Just do a bunch of calculations and print the result to the screen. This assembly program will be fast, but it will only run on one specific OS. If you want it to run on just about any computer, then you should write it in Perl" Yet more fundamentally flawed advice, given your recent postings I'm not sure if you are just trolling. Update: your home node states "The very first programming language I learned was QBASIC when I was 12 years old. Then I was taught C and x86 assembly", how this can link up with your claims above is beyond me. | [reply] |
by harangzsolt33 (Deacon) on Dec 15, 2019 at 05:08 UTC | |
The interesting thing about this particular asm code is that it will only run on 64-bit Intel and AMD microprocessors. It will not run on a 32-bit CPU. And it will not run on ARM, SPARC, or old iMac processors! On the other hand, the print "Hello World"; perl equivalent of this program is not bound to one particular architecture or one particular OS. It would run on any CPU and any OS. To further prove my point, if you would run an assembler to convert this asm text code to an obj file and then link the obj into exe file, it would result in a Windows executable. If you tried to run it in Linux, it wouldn't run (without wine). If you tried to execute it on an Apple MacBook Pro, it wouldn't run. It wouldn't run even if you included it in your perl script inline. This code is not only machine specific, but it is OS specific. That's what I meant. It's a fact. Try it if you don't believe me. A simple print "Hello World" perl script will run on any computer, but once you insert asm code into your perl script as inline assembly, chances are you have limited your perl script to one particular processor and one particular OS! Now, your perl script is no longer compatible with 90% of other computers out there. But if you omit the inline assembly code, then it will run on other computers.
| [reply] [d/l] |
by haukex (Archbishop) on Dec 15, 2019 at 11:54 UTC | |
This code is not only machine specific, but it is OS specific. Yes, you're right about that code being specific to an architecture and OS. However, I think the quibble here is that it's very different from what you originally said: Assembly language is machine-specific, while perl is designed to run on any platform. If you write an assembly program for Linux, it won't run on DOS or Windows. Stated so generally, that's not correct: some assembly programs can be run on multiple OSes. And I think "machine-specific" is too vague, as that could also be interpreted to mean that assembly code is specific to one particular computer; the Wikipedia quote you gave here is much more accurate. And some of your argumentation unfortunately goes against itself, like here: ... it would result in a Windows executable. If you tried to run it in Linux, it wouldn't run (without wine). Wine Is Not an Emulator, and there's also the Windows Subsystem for Linux, which you may not have known about, but both these examples contradict your statement "... if you try to execute a Linux program in DOS or vice versa, it won't even load, because the OS does not recognize it as a valid executable." Yes, a compatibility layer is needed, but the assembly is executed natively. I also have to say I think you're muddying things between the concepts of ABI, assembly language, and actual binary processor instructions. Another example: in this node you suggest that adding assembly to Perl will make it less portable, which is of course true across processor architectures, and it's true when comparing a Perl program with assembly to one without assembly. But in the same paragraph you mention portability across OSes, and here I'd say that using inline assembly in Perl can actually make the assembly more portable than the same assembly code without Perl. The same is true for assembly embedded in C code, which most if not all C compilers support. Take your initial example: So, even if the program is designed to do a very simple task such as calculate the value of PI. No file access needed. No internet access needed. No libraries have to be loaded. Just do a bunch of calculations and print the result to the screen. The only thing in that whole program that is OS-specific is the output part. If all the assembly had to do was return that value in memory to Perl instead, and Perl does the printing, then suddenly you have portability across all OSes on the same processor architecture (that Perl runs on; another point you gloss over in your various posts). See the example in the synopsis of Inline::ASM, for example. Don't get me wrong, when it comes to 80386 assembly, I think you know your stuff. Rereading your posts here, I also understand the points you were trying to make. Here you said "You know what I am talking about," and yes, we know what you're talking about. But remember that this is all taken in the context of helping newcomers: making over-generalized statements, sometimes conflicting and/or inaccurate ones, can muddy the waters and cause confusion, and potentially be more damaging than helpful. I would suggest being more careful with the language you use to explain things. | [reply] |
by harangzsolt33 (Deacon) on Dec 15, 2019 at 15:51 UTC | |
by Anonymous Monk on Dec 15, 2019 at 19:20 UTC | |
by Anonymous Monk on Dec 15, 2019 at 12:41 UTC | |
| [reply] |
|
Re^2: Assembly language
by stevieb (Canon) on Dec 14, 2019 at 18:33 UTC | |
"Perl has very little to do with assembly language" This is wrong as well. *All* high-level languages are compiled into assembly/machine code to be understood by the processor(s). "If you want it to run on just about any computer, then you should write it in Perl. If your goal is speed, then write it in assembly." If you want to run something on any computer, use any language that can compile into machine code for the specific CPU architecture you're targeting. If your goal is speed, write it in a compiled language (eg. C) instead of a scripting language. If your goal is to write something that is so low-level that there isn't a compilation routine to do accurate translation, write it in assembly. | [reply] |
|
Re^2: Assembly language
by LanX (Saint) on Dec 14, 2019 at 18:25 UTC | |
That's plain wrong. Both operating systems can run on the same CPU.
Cheers Rolf
| [reply] |
by harangzsolt33 (Deacon) on Dec 14, 2019 at 18:54 UTC | |
That's plain wrong. No, it's not wrong. (Please re-read what I wrote, and then read what you wrote. We're talking about two different things. You totally I mean TOTALLY misunderstood my statement! And you're responding to a statement that I never meant to write.) DOS programs call INT 21h. In Windows programs, there's the Windows API, and Linux has its own service libraries. The way the EXE headers are written in Windows is totally incompatible with Linux headers. And if you try to execute a Linux program in DOS or vice versa, it won't even load, because the OS does not recognize it as a valid executable. You know what I am talking about, so don't pretend that this isn't true. | [reply] |
by marto (Cardinal) on Dec 14, 2019 at 19:00 UTC | |
| [reply] | |
by harangzsolt33 (Deacon) on Dec 14, 2019 at 19:27 UTC | |
by LanX (Saint) on Dec 15, 2019 at 13:58 UTC | |
by LanX (Saint) on Dec 15, 2019 at 03:24 UTC | |
The way how the result of an assembler is bound to needed libraries to create an OS specific executable is irrelevant. Anything else compiling to machine like C or Pascal needs this step too. I can even include the same ASM code inside Perl code via Inline::ASM and start it under different OS, as long as it's the same CPU. > Please re-read what I wrote, I did.
Cheers Rolf
| [reply] |
|
Re^2: Assembly language
by SkinBlues (Acolyte) on Dec 14, 2019 at 18:33 UTC | |
| [reply] |
by stevieb (Canon) on Dec 14, 2019 at 18:35 UTC | |
It's definitely fundamental. Assembly is machine code, the lowest level code a computer processor can understand directly. It's the foundation of all high(er) level programming languages, including scripting languages such as Perl. | [reply] |
by davido (Cardinal) on Dec 15, 2019 at 05:37 UTC | |
Assembly is not machine code. It doesn't help newcomers to this stuff to blur the distinction. Assembly is a symbolic language that has a very close to 1:1 mapping with machine instructions, though not exactly 1:1. But it provides named constants, named registers, named machine instructions, labels, memory addressing strategies, and a lot more that are not native to machine code. Assembly language is a human readable language, and cannot be run natively on the CPU any more than native machine instructions can be read by a human (without at very least first converting them to an unambiguous printable encoding such as hex -- but even then, good luck with that for anything that isn't super trivial. Assembly is useful as a teaching aid, or for programming very small systems that don't have C compilers available. It might be useful for hand-optimizing tight sections of C code. But on modern computer hardware, the need for hand-optimizing code at the Assembly level is quickly vanishing. I enjoyed learning 6502 Assembly. On the one hand it was a big pain. But on the other, it was fascinating. But even in the 80s, it was just about the slowest way to get anything done. I think that if someone wants to learn assembly, they should do it. They'll gain an appreciation for the fundamentals. But nobody's going to write a REST microservice in it. ;) To the OP: The days of being able to just input raw machine instructions for the CPU to execute ended with computers with switchboard face panels like the Altair 8800. And even then, it was hard enough that people would mostly just key in a short bootloader, and use it to pull down the actual program, written in a less tedious way. Nowadays, when you're typing at the Linux command line you are typing within a piece of software (the shell), and it doesn't expose the CPU directly, at least not easily. The shell doesn't understand 011101011101000101001010100001010111110101010000000101010101011011010110101. Dave | [reply] |
by LanX (Saint) on Dec 16, 2019 at 17:30 UTC | |
by harangzsolt33 (Deacon) on Dec 14, 2019 at 19:03 UTC | |
My understanding is that assembly language is a more simpler, fundamental language than languages like Perl and Javascript. Is that right? How could I write a program in assembly language? Yes, assembly is the most fundamental level. To write assembly programs, you need a compiler ((correction: you need an assembler)) that translates your human readable text file into binary code that runs on either DOS, Windows, Linux, OSX, or the boot sector. You need to pick a platform first. Each of these environments requires your program to work slightly differently, so you can't just write an assembly program that will work on all computers and all platforms. That's what I meant earlier when I said it is machine specific and OS specific. There are different processors. 64-bit processors use different assembly instructions than 32-bit processors. Cell phones use different instructions. There are various processors, and you have to decide which one you want to study first. I studied the Intel 80386 processor myself, and I wrote programs for DOS and the boot sector. And in order to do that, you have to download a program called A86.COM. To write Windows assembly programs, you can download FASM.EXE or something similar. In Linux, I am not sure what you would use. I encourage you to ask more questions. Do more research.. Until then, here is a simple assembly program which I wrote for DOS (16-bit):
Now, here is the same program in Perl. See, how shorter and simpler this is?:
| [reply] [d/l] [select] |
by marto (Cardinal) on Dec 14, 2019 at 19:09 UTC | |
"you need a compiler" not true, you need an assembler, not a compiler, this isn't how this works. ”Cell phones use different instructions." That would depend on the CPU they used. Few are x86, most are ARM. | [reply] |
by SkinBlues (Acolyte) on Dec 14, 2019 at 19:28 UTC | |
| [reply] |
by karlgoethebier (Abbot) on Dec 15, 2019 at 13:19 UTC | |
by GrandFather (Saint) on Dec 16, 2019 at 05:33 UTC | |
| |
by harangzsolt33 (Deacon) on Dec 14, 2019 at 19:38 UTC | |
by haukex (Archbishop) on Dec 14, 2019 at 21:09 UTC | |
by marto (Cardinal) on Dec 14, 2019 at 19:55 UTC | |
| |