DEV Community

Discussion on: When do you ever need assembly?

Collapse
 
connellpaxton profile image
connell-paxton • Edited

Just as a heads up, you forgot a newline for the c++ one,
it would be best to write it like:

#include <iostream>
int main() {
    std::cout << "Hello World" << std::endl;
}

Also it is worth noting that the Java snippets you
showed actually doesn't translate to the assembly,

Heres why:

Java is run on something called the "JVM" (Java Virtual Machine)
The JVM interprets byte code.
In a normal (compiled) language the compilation pipeline looks something like this:

Source Code
|        |       | compiler
|        |    IR (internal Representation)
|        |       |
|    Object File
|        |  linker
Executable

(there are compilers that are "one-pass" such as tcc which skip the two intermediate states)

In Java, it goes from source into bytecode

Source Code
   |
Byte Code

Our executable from the compilation pipe is run like this:

+---------------+
|  Executable   |
+---------------+
| CPU | Kernel  |
+-----+---------+

(its kinda hard to show this, but essentially the kernel runs on the CPU, but doesn't interprete the executable, instead it loads it into memory and responds to any interrupts)

But in the Java example, that goes one level Higher:

+---------------+
|    ByteCode   |
+---------------+
| Java Runtime  |
+---------------+
| CPU | Kernel  |
+-----+---------+

Where the Java Runtime is an executable that interprets the bytecode