I have always thought, and maybe someone here can correct or confirm this, that languages like C, python, java, etc have assembly as their foundation. Meaning that most languages get interpreted at some point into assembly in order for it to run.
Thus, all of that assembly (above), is the basis for “print” for all the other languages.
python is an interpreted language. The python code that you write is a script... a text document. But the python interpreter that reads your code is written in C.
The C compiler that created the interpreter converted C code to "machine code" aka binary code.
I suppose you could read the compiled binary as assembly... maybe, for debugging purposes. I don't believe the people writing the python executable files are writing anything in assembly.
(edit)
The only people I know who are writing assembly code for modern purposes are writing drivers for hardware devices.
The bytecode that CPython compiles Python source to is essentially the assembly/machine language for the virtual stack machine also implemented by CPython.
What's shown in that fragment is the user-side. 'svc' calls into the OS, or whatever passes for that, then we don't know exactly what happens. There could still be a huge amount of machinery involved before it appears on some display.
However, there can also be many layers of abstraction before it gets to that OS interface.
Since Python has been mentioned, this is what happens with an interpreted language of my own when someone writes this and then says 'run':
print "Hello"
First, an internal compiler turns it into a series of bytecode instructions. These are in binary, but if dumped as text, it would be these:
Let's concentrate on that 'print_nf' call. This bytecode is interpreted, and that instruction is handled here:
when kcallhost then
sp := callhostfunction(pc.hostindex, sp)
steppc
That routine calls into the interpreter (the 'host') and there is a lot of code to dispatch to that particular routine (finding its address and using the right call-code with the correct arguments).
But eventually it ends up in `print_nf' which includes these two lines:
The first line converts the object to a string (here it is already a string, but this is dynamic code - it could be anything, and the string can still need format controls).
The second line sends it to the output. That is another lot of complexity, but eventually it gets here:
case outdev
when std_io then
printf("%.*s", n, s)
This is where my language implementation (the language used to write the interpreter in, which is another one of mine) hands to an external library.
Although it runs under Windows, it chooses to uses the C library, which is bundled with Windows, to do I/O. Because it is simpler than directly calling WinAPI (Windows doesn't have usable systems calls like the example).
Anyway, nowhere here has assembly been used: the interpreted language generates binary bytecode, and the systems language generates binary native code.
Inside the C library will also be binary code (the library source was likely written in C, but we don't know, and it doesn't matter).
Assembly could optionally be used as compiler output, and I use it to dump the code I generate when I test my compiler. But in production there is no need, and it is rarely written directly. (My interpreter uses about 20 lines of inline assembly, to implement critical parts of an FFI for external libraries, as it is not practical in a HLL.)
4
u/Major-Hooters 2d ago edited 1h ago
I have always thought, and maybe someone here can correct or confirm this, that languages like C, python, java, etc have assembly as their foundation. Meaning that most languages get interpreted at some point into assembly in order for it to run.
Thus, all of that assembly (above), is the basis for “print” for all the other languages.