translating Python to Assembler

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Jan 27 04:44:49 EST 2008


On Sun, 27 Jan 2008 08:58:01 +0000, over wrote:

> On Fri, 25 Jan 2008 17:44:07 -0800 (PST), ajaksu <ajaksu at gmail.com>
> wrote:
> 
>>On Jan 25, 11:36 pm, ajaksu <aja... at gmail.com> wrote:
>>> On Jan 25, 11:10 pm, o... at thepond.com wrote:
>>[...]
>>
>>Gaah, is this what's going on?
>>
>>ajaksu at Belkar:~$ cat error.txt
>>This is not assembler...
>>
>>ajaksu at 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
>>
>>:/
> 
> not sure what you're saying. Sure looks like assembler to me. Take the
> '54   push sp'. The 54 is an assembler opcode for push and the sp is the
> stack pointer, on which it is operating.


Deary deary me...

Have a close look again at the actual contents of the file:

$ cat error.txt
This is not assembler...


If you run the text "This is not assembler..." through a disassembler, it 
will obediently disassemble the bytes "This is not assembler..." into a 
bunch of assembler opcodes. Unfortunately, although the individual 
opcodes are "assembly", the whole set of them together is nonsense. 
You'll see that it is nonsense the moment you try to execute the supposed 
assembly code.

It would be a fascinating exercise to try to generate a set of bytes 
which could be interpreted as both valid assembly code *and* valid 
English text simultaneously. For interest, here you will find one quine 
(program which prints its own source code) which is simultaneously valid 
in C and TCL, and another which is valid in C and Lisp:

http://www.uwm.edu/~chruska/recursive/selfish.html



-- 
Steven



More information about the Python-list mailing list