translating Python to Assembler

over at thepond.com over at thepond.com
Fri Jan 25 20:10:26 EST 2008


On Thu, 24 Jan 2008 08:02:06 GMT, Tim Roberts <timr at probo.com> wrote:

>Bjoern Schliessmann <usenet-mail-0306.20.chr0n0ss at spamgourmet.com> wrote:
>
>>Grant Edwards wrote:
>>
>>> Trying to find assembly language stuff to look at is futile.
>>> Python doesn't get compiled into assembly language.
>>
>>So, how do processors execute Python scripts? :)
>
>Is that a rhetorical question?  Grant is quite correct; Python scripts (in
>the canonical CPython) are NOT compiled into assembly language.  Scripts
>are compiled to an intermediate language.  Processors execute Python
>scripts when the interpreter, written in a high-level language and compiled
>to assembly, interprets the intermediate language created by the Python
>"compiler".

Intel processors can only process machine language, which is
essentially binary 1's and 0's. All  a processor understands is
voltages, either 0 Volts or 5 volts on older systems, or 3.3 volts and
less on newer systems. Generally, a positive voltage is a logical 1
and 0 volts is a logical 0. There's no way for a processor to
understand any higher level language, even assembler, since it is
written with hexadecimal codes and basic instructions like MOV, JMP,
etc. The assembler compiler can convert an assembler file to a binary
executable, which the processor can understand.

If you look at the Python interpreter, Python.exe, or Pythonw, the
Windows interface, or the Python24.dll, the main library for python,
you will see they are normal 32 bit PE files. That means they are
stored on disk in codes of 1's and 0's, and decompile into assembler.
You can't decompile them into Python directly, although I'm sure
someone is trying. No compiled file can be decompiled into it's
original format easily or automatically, although there are
decompilers that will convert them to a reasonable assembler
decompilation. 

If a Python script was understood directly by the processor, no
interpreter would be necessary. Ask yourself what the interpreter is
doing. It's taking the scripting language and converting to the
language of the operating system. However, it's the processor that
dictates how programs are written, not the OS. That's why a Linux OS
will run on an Intel machine, as a Windows OS does. Both Linux and
Windows compile down to binary files, which are essentially 1's and
0's arranged in codes that are meaningful to the processor. 

Once a python py file is compiled into a pyc file, I can disassemble
it into assembler. Assembler is nothing but codes, which are
combinations of 1's and 0's. You can't read a pyc file in a hex
editor, but you can read it in a disassembler. It doesn't make a lot
of sense to me right now, but if I was trying to trace through it with
a debugger, the debugger would disassemble it into assembler, not
python. 



More information about the Python-list mailing list