entry: bytecode in Java and Py

This commit is contained in:
Thomas Bishop 2025-12-06 19:30:18 +00:00
parent ecc1117fae
commit 78d0147e78
2 changed files with 35 additions and 4 deletions

View file

@ -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.

View file

@ -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.