translating Python to Assembler

O

over

My expertise, if any, is in assembler. I'm trying to understand Python
scripts and modules by examining them after they have been
disassembled in a Windows environment.

I'm wondering if a Python symbols file is available. In the Windows
environment, a symbol file normally has a PDB extension. It's a little
unfortunate that Python also uses PDB for its debugger. Google, for
whatever reason, wont accept queries with dots, hyphens, etc., in the
query line. For example a Google for "python.pdb" returns +python
+pdb, so I get a ridiculous number of returns referring to the python
debugger. I have mentioned this to Google several times, but I guess
logic isn't one of their strong points. :)
 
J

John Machin

My expertise, if any, is in assembler. I'm trying to understand Python
scripts and modules by examining them after they have been
disassembled in a Windows environment.

DB "Wrong way. Go back. Read the tutorials."
RET
 
J

James Matthews

The reason you were finding a Python Debugger when looking for the PDB
files is because PDB is Python DeBugger! Also why would you be looking
for a PDB file if you can read the C source!
 
L

Luis Zarrabeitia

I second Wim's opinion. Learn python as a high level language, you won't regret it.

About google, I'll give you a little gtip:

Instead of searching 'python.pdb' try the query "filetype:pdb python", or even
"python pdb" (quoted). The first one whould give you files with pdb extension
and python in the name or contents, and the second one (quoted) should return
pages with both words together, except for commas, spaces, dots, slashs, etc.

However... one of the second query results is this thread in google groups...
not a good sign.

--
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie


Quoting Wim Vander Schelden said:
Python modules and scripts are normally not even compiled, if they have
been,
its probably just the Python interpreter packaged with the scripts and
resources.

My advice is that if you want to learn Python, is that you just read a book
about
it or read only resources. Learning Python from assembler is kind of...
strange.

Not only are you skipping several generations of programming languages,
spanned
over a period of 40 years, but the approach to programming in Python is so
fundamentally different from assembler programming that there is simply no
reason
to start looking at if from this perspective.

I truly hope you enjoy the world of high end programming languages, but
treat them
as such. Looking at them in a low-level representation or for a low-level
perspective
doesn't bear much fruits.

Kind regards,

Wim
 
G

Grant Edwards

My expertise, if any, is in assembler. I'm trying to
understand Python scripts and modules by examining them after
they have been disassembled in a Windows environment.

You can't dissassemble them, since they aren't ever converted
to assembler and assembled. Python is compiled into bytecode
for a virtual machine (either the Java VM or the Python VM or
the .NET VM).
I'm wondering if a Python symbols file is available.

You're way off track.
In the Windows environment, a symbol file normally has a PDB
extension. It's a little unfortunate that Python also uses PDB
for its debugger. Google, for whatever reason, wont accept
queries with dots, hyphens, etc., in the query line. For
example a Google for "python.pdb" returns +python +pdb, so I
get a ridiculous number of returns referring to the python
debugger. I have mentioned this to Google several times, but I
guess logic isn't one of their strong points. :)

Trying to find assembly language stuff to look at is futile.
Python doesn't get compiled into assembly language.

If you want to learn Python, then read a book on Python.
 
S

Steven D'Aprano

You can't dissassemble them, since they aren't ever converted to
assembler and assembled. Python is compiled into bytecode for a virtual
machine (either the Java VM or the Python VM or the .NET VM).


There is the Python disassembler, dis, which dissassembles the bytecode
into something which might as well be "assembler" *cough* for the virtual
machine.
 
C

Christian Heimes

Wim said:
Python modules and scripts are normally not even compiled, if they have
been,
its probably just the Python interpreter packaged with the scripts and
resources.

No, that is not correct. Python code is compiled to Python byte code and
execute inside a virtual machine just like Java or C#. It's even
possible to write code with Python assembly and compile the Python
assembly into byte code.

You most certainly meant: Python code is not compiled into machine code.

Christian
 
B

Bjoern Schliessmann

Grant said:
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? :)
If you want to learn Python, then read a book on Python.

ACK.

Regards,


Björn
 
T

Tim Roberts

Bjoern Schliessmann said:
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".
 
B

Bjoern Schliessmann

Tim said:
Bjoern Schliessmann <[email protected]>

Is that a rhetorical question?

A little bit.
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".

So in the end, the program defined in the Python script _is_
compiled to the CPU's language. But never mind, it depends on how
you define "compile" in the end.

Regards,


Björn
 
C

Carl Banks

So in the end, the program defined in the Python script _is_
compiled to the CPU's language.

I would say it's compiled to an intermediate language ("bytecode"),
and then that intermediate language is interpreted.

But never mind, it depends on how
you define "compile" in the end.

If you define "compile" as "interpret", yeah.


Calr Banks
 
C

Chris Mellon

A little bit.


So in the end, the program defined in the Python script _is_
compiled to the CPU's language. But never mind, it depends on how
you define "compile" in the end.

This is true if and only if you would agree that Powerpoint
presentations, Word documents, and PNG images are likewise compiled to
machine code.
 
B

Bruno Desthuilliers

Christian Heimes a écrit :
No, that is not correct. Python code is compiled to Python byte code and
execute inside a virtual machine just like Java or C#.

I'm surprised you've not been flamed to death by now - last time I
happened to write a pretty similar thing, I got a couple nut case
accusing me of being a liar trying to spread FUD about Java vs Python
respective VMs inner working, and even some usually sensible regulars
jumping in to label my saying as "misleading"...
 
P

Paul Boddie

Christian Heimes a écrit :


I'm surprised you've not been flamed to death by now - last time I
happened to write a pretty similar thing, I got a couple nut case
accusing me of being a liar trying to spread FUD about Java vs Python
respective VMs inner working, and even some usually sensible regulars
jumping in to label my saying as "misleading"...

Well, it is important to make distinctions when people are wondering,
"If Python is 'so slow' and yet everyone tells me that the way it is
executed is 'just like Java', where does the difference in performance
come from?" Your responses seemed to focus more on waving that issue
away and leaving the whole topic in the realm of mystery. The result:
"Python is just like Java apparently, but it's slower and I don't know
why."

It's true in one sense that the statement "Python modules and scripts
are normally not even compiled" is incorrect, since modules at least
are compiled to another representation. However, if we grant the
author of that statement the benefit of his ambiguity, we can also
grant his statement a degree of tolerance by observing that modules
are not compiled to native code, which is the only experience some
people have with compilation and its results.

As was pointed out in that previous discussion, CPython instructions
are arguably less well-suited than Java instructions for translation
to CPU instructions. This alone should make people wonder about how
close CPython and the more prominent Java virtual machines are, as
well as the considerations which led the Java virtual machine
architecture to be designed in the way that it was.

Paul
 
O

over

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

ajaksu

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.


Please, tell me you're kidding...
 
A

ajaksu

On Jan 25, 11:10 pm, (e-mail address removed) wrote:
[...]

Gaah, is this what's going on?

ajaksu@Belkar:~$ cat error.txt
This is not assembler...

ajaksu@Belkar:~$ ndisasm error.txt
00000000 54 push sp
00000001 686973 push word 0x7369
00000004 206973 and [bx+di+0x73],ch
00000007 206E6F and [bp+0x6f],ch
0000000A 7420 jz 0x2c
0000000C 61 popa
0000000D 7373 jnc 0x82
0000000F 656D gs insw
00000011 626C65 bound bp,[si+0x65]
00000014 722E jc 0x44
00000016 2E db 0x2E
00000017 2E db 0x2E
00000018 0A db 0x0A

:/
 
S

Steven D'Aprano

It's even
possible to write code with Python assembly and compile the Python
assembly into byte code.

Really? How do you do that?

I thought it might be compile(), but apparently not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top