From 78d0147e7870904509ee3c8294c60eaf9b65c342 Mon Sep 17 00:00:00 2001 From: thomasabishop Date: Sat, 6 Dec 2025 19:30:18 +0000 Subject: [PATCH] entry: bytecode in Java and Py --- zk/C_compilation_process.md | 26 ++++++++++++++++--- ...nce_between_bytecode_in_Python_and_Java.md | 13 ++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 zk/Difference_between_bytecode_in_Python_and_Java.md diff --git a/zk/C_compilation_process.md b/zk/C_compilation_process.md index 26bb847..16fd0a3 100644 --- a/zk/C_compilation_process.md +++ b/zk/C_compilation_process.md @@ -31,6 +31,11 @@ just run the following in your source directory: gcc main.c ``` +> `gcc` stands for GNU C compiler. Actually `gcc` is a driver that orchestrates +> muliple tools: `cc1`, the actual C-to-assembly compiler; `as` the assembler +> (assembly to object file); and `ld` the linker (linking the object files to +> the executable) + This generates: ``` @@ -147,10 +152,10 @@ main: ## Assembly The assembly language code is converted into machine code. The output is an -**object file** (`.o`) which containes the machine code but is not yet -executable because it is not yet linked to the functions and variables that come -from imported code. Your object file is not yet combined with the object files -of the libraries and resources you have used. +**object file** (`.o`) which contains the machine code but is not yet executable +because it is not yet linked to the functions and variables that come from +imported code. Your object file is not yet combined with the object files of the +libraries and resources you have used. Create just the object file with: @@ -201,3 +206,16 @@ To break this down: In the final stage the object files are combined, resolving all the references between them. The result of this stage will be the `a.out` file mentioned earlier. + +## Different architectures + +By default `gcc` will compile to whichever architecture it is being run on. + +As I am using Linux x86-64, I get x86 machine code. + +It is possible - although not trivial - to compile to different architectures +which use different [instruction set](./Instruction_set_architectures.md'). +Instructions sets other than the native machine you are running `gcc` on. This +is known as **cross-compiling**. + +You might do this for ARM, say, and it would result in an ARM64 object file. diff --git a/zk/Difference_between_bytecode_in_Python_and_Java.md b/zk/Difference_between_bytecode_in_Python_and_Java.md new file mode 100644 index 0000000..a697406 --- /dev/null +++ b/zk/Difference_between_bytecode_in_Python_and_Java.md @@ -0,0 +1,13 @@ +--- +tags: + - python + - java +--- + +# Difference between bytecode in Python and Java + +Java bytecode is the distribution format - you compile source to `.class` files +and ship those to run on the JVM. [Python bytecode](./Python_interpreter.md) is +an internal caching mechanism - you ship `.py` source files and Python compiles +them to bytecode (`.pyc`) behind the scenes to speed up subsequent runs. Java +bytecode is the end product; Python bytecode is an implementation detail.