← Signals & codes

A machine code study edition

English ↔ Machine code

A Dream Within a Dream · x86-64 bytes for Linux

Edition: complete · a working 814-byte program, tested on Linux, that prints the whole poem

Underneath every screen, a poem is only numbers. This edition shows Poe's words as the bytes a computer stores, then as a complete program in x86-64 machine code: 814 bytes that, run on a Linux computer, print all 24 lines and quit. Eight instructions do the work. Step through them on the right and watch the registers change.

Run it, one instruction at a time

Ready at 00400078

$ ./poem
814bytes in the whole program, headers included
8instructions, 33 bytes of code
661bytes of poem, newlines included
3bytes for each dash, the only character outside ASCII

Part one / The poem

The poem, line by line, as bytes

Each line of Poe's poem as the UTF-8 bytes a computer stores, in hexadecimal. Switch to binary to see the ones and zeros. Select a line number for notes.

LineEnglish · sourceBytes
Take this kiss upon the brow! 54 61 6B 65 20 74 68 69 73 20 6B 69 73 73 20 75 70 6F 6E 20 74 68 65 20 62 72 6F 77 21
And, in parting from you now, 41 6E 64 2C 20 69 6E 20 70 61 72 74 69 6E 67 20 66 72 6F 6D 20 79 6F 75 20 6E 6F 77 2C
Thus much let me avow — 54 68 75 73 20 6D 75 63 68 20 6C 65 74 20 6D 65 20 61 76 6F 77 20 E2 80 94
You are not wrong, who deem 59 6F 75 20 61 72 65 20 6E 6F 74 20 77 72 6F 6E 67 2C 20 77 68 6F 20 64 65 65 6D
That my days have been a dream; 54 68 61 74 20 6D 79 20 64 61 79 73 20 68 61 76 65 20 62 65 65 6E 20 61 20 64 72 65 61 6D 3B
Yet if hope has flown away 59 65 74 20 69 66 20 68 6F 70 65 20 68 61 73 20 66 6C 6F 77 6E 20 61 77 61 79
In a night, or in a day, 49 6E 20 61 20 6E 69 67 68 74 2C 20 6F 72 20 69 6E 20 61 20 64 61 79 2C
In a vision, or in none, 49 6E 20 61 20 76 69 73 69 6F 6E 2C 20 6F 72 20 69 6E 20 6E 6F 6E 65 2C
Is it therefore the less gone? 49 73 20 69 74 20 74 68 65 72 65 66 6F 72 65 20 74 68 65 20 6C 65 73 73 20 67 6F 6E 65 3F
All that we see or seem 41 6C 6C 20 74 68 61 74 20 77 65 20 73 65 65 20 6F 72 20 73 65 65 6D
Is but a dream within a dream. 49 73 20 62 75 74 20 61 20 64 72 65 61 6D 20 77 69 74 68 69 6E 20 61 20 64 72 65 61 6D 2E
I stand amid the roar 49 20 73 74 61 6E 64 20 61 6D 69 64 20 74 68 65 20 72 6F 61 72
Of a surf-tormented shore, 4F 66 20 61 20 73 75 72 66 2D 74 6F 72 6D 65 6E 74 65 64 20 73 68 6F 72 65 2C
And I hold within my hand 41 6E 64 20 49 20 68 6F 6C 64 20 77 69 74 68 69 6E 20 6D 79 20 68 61 6E 64
Grains of the golden sand — 47 72 61 69 6E 73 20 6F 66 20 74 68 65 20 67 6F 6C 64 65 6E 20 73 61 6E 64 20 E2 80 94
How few! yet how they creep 48 6F 77 20 66 65 77 21 20 79 65 74 20 68 6F 77 20 74 68 65 79 20 63 72 65 65 70
Through my fingers to the deep, 54 68 72 6F 75 67 68 20 6D 79 20 66 69 6E 67 65 72 73 20 74 6F 20 74 68 65 20 64 65 65 70 2C
While I weep — while I weep! 57 68 69 6C 65 20 49 20 77 65 65 70 20 E2 80 94 20 77 68 69 6C 65 20 49 20 77 65 65 70 21
O God! Can I not grasp 4F 20 47 6F 64 21 20 43 61 6E 20 49 20 6E 6F 74 20 67 72 61 73 70
Them with a tighter clasp? 54 68 65 6D 20 77 69 74 68 20 61 20 74 69 67 68 74 65 72 20 63 6C 61 73 70 3F
O God! can I not save 4F 20 47 6F 64 21 20 63 61 6E 20 49 20 6E 6F 74 20 73 61 76 65
One from the pitiless wave? 4F 6E 65 20 66 72 6F 6D 20 74 68 65 20 70 69 74 69 6C 65 73 73 20 77 61 76 65 3F
Is all that we see or seem 49 73 20 61 6C 6C 20 74 68 61 74 20 77 65 20 73 65 65 20 6F 72 20 73 65 65 6D
But a dream within a dream? 42 75 74 20 61 20 64 72 65 61 6D 20 77 69 74 68 69 6E 20 61 20 64 72 65 61 6D 3F

Part two / The program

Eight instructions

The program is an ELF file, the format Linux runs. A 120-byte header tells the system where to load it. Then come the 33 bytes of code below, then the 661 bytes of the poem.

AddressBytesAssemblyWhat it does
00400078B8 01 00 00 00mov eax, 1system call 1 is write
0040007dBF 01 00 00 00mov edi, 1file 1 is the screen (standard output)
0040008248 8D 35 10 00 00 00lea rsi, [rip+16]point at the poem's bytes
00400089BA 95 02 00 00mov edx, 661how many bytes to write
0040008e0F 05syscallask the kernel to write the poem
00400090B8 3C 00 00 00mov eax, 60system call 60 is exit
0040009531 FFxor edi, ediexit status 0: all went well
004000970F 05syscallask the kernel to end the program
See every byte of the program (814 bytes)
0000  7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00   .ELF............
0010  02 00 3e 00 01 00 00 00 78 00 40 00 00 00 00 00   ..>.....x.@.....
0020  40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   @...............
0030  00 00 00 00 40 00 38 00 01 00 00 00 00 00 00 00   ....@.8.........
0040  01 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00   ................
0050  00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 00   ..@.......@.....
0060  2e 03 00 00 00 00 00 00 2e 03 00 00 00 00 00 00   ................
0070  00 10 00 00 00 00 00 00 b8 01 00 00 00 bf 01 00   ................
0080  00 00 48 8d 35 10 00 00 00 ba 95 02 00 00 0f 05   ..H.5...........
0090  b8 3c 00 00 00 31 ff 0f 05 54 61 6b 65 20 74 68   .<...1...Take th
00a0  69 73 20 6b 69 73 73 20 75 70 6f 6e 20 74 68 65   is kiss upon the
00b0  20 62 72 6f 77 21 0a 41 6e 64 2c 20 69 6e 20 70    brow!.And, in p
00c0  61 72 74 69 6e 67 20 66 72 6f 6d 20 79 6f 75 20   arting from you 
00d0  6e 6f 77 2c 0a 54 68 75 73 20 6d 75 63 68 20 6c   now,.Thus much l
00e0  65 74 20 6d 65 20 61 76 6f 77 20 e2 80 94 0a 59   et me avow ....Y
00f0  6f 75 20 61 72 65 20 6e 6f 74 20 77 72 6f 6e 67   ou are not wrong
0100  2c 20 77 68 6f 20 64 65 65 6d 0a 54 68 61 74 20   , who deem.That 
0110  6d 79 20 64 61 79 73 20 68 61 76 65 20 62 65 65   my days have bee
0120  6e 20 61 20 64 72 65 61 6d 3b 0a 59 65 74 20 69   n a dream;.Yet i
0130  66 20 68 6f 70 65 20 68 61 73 20 66 6c 6f 77 6e   f hope has flown
0140  20 61 77 61 79 0a 49 6e 20 61 20 6e 69 67 68 74    away.In a night
0150  2c 20 6f 72 20 69 6e 20 61 20 64 61 79 2c 0a 49   , or in a day,.I
0160  6e 20 61 20 76 69 73 69 6f 6e 2c 20 6f 72 20 69   n a vision, or i
0170  6e 20 6e 6f 6e 65 2c 0a 49 73 20 69 74 20 74 68   n none,.Is it th
0180  65 72 65 66 6f 72 65 20 74 68 65 20 6c 65 73 73   erefore the less
0190  20 67 6f 6e 65 3f 0a 41 6c 6c 20 74 68 61 74 20    gone?.All that 
01a0  77 65 20 73 65 65 20 6f 72 20 73 65 65 6d 0a 49   we see or seem.I
01b0  73 20 62 75 74 20 61 20 64 72 65 61 6d 20 77 69   s but a dream wi
01c0  74 68 69 6e 20 61 20 64 72 65 61 6d 2e 0a 0a 49   thin a dream...I
01d0  20 73 74 61 6e 64 20 61 6d 69 64 20 74 68 65 20    stand amid the 
01e0  72 6f 61 72 0a 4f 66 20 61 20 73 75 72 66 2d 74   roar.Of a surf-t
01f0  6f 72 6d 65 6e 74 65 64 20 73 68 6f 72 65 2c 0a   ormented shore,.
0200  41 6e 64 20 49 20 68 6f 6c 64 20 77 69 74 68 69   And I hold withi
0210  6e 20 6d 79 20 68 61 6e 64 0a 47 72 61 69 6e 73   n my hand.Grains
0220  20 6f 66 20 74 68 65 20 67 6f 6c 64 65 6e 20 73    of the golden s
0230  61 6e 64 20 e2 80 94 0a 48 6f 77 20 66 65 77 21   and ....How few!
0240  20 79 65 74 20 68 6f 77 20 74 68 65 79 20 63 72    yet how they cr
0250  65 65 70 0a 54 68 72 6f 75 67 68 20 6d 79 20 66   eep.Through my f
0260  69 6e 67 65 72 73 20 74 6f 20 74 68 65 20 64 65   ingers to the de
0270  65 70 2c 0a 57 68 69 6c 65 20 49 20 77 65 65 70   ep,.While I weep
0280  20 e2 80 94 20 77 68 69 6c 65 20 49 20 77 65 65    ... while I wee
0290  70 21 0a 4f 20 47 6f 64 21 20 43 61 6e 20 49 20   p!.O God! Can I 
02a0  6e 6f 74 20 67 72 61 73 70 0a 54 68 65 6d 20 77   not grasp.Them w
02b0  69 74 68 20 61 20 74 69 67 68 74 65 72 20 63 6c   ith a tighter cl
02c0  61 73 70 3f 0a 4f 20 47 6f 64 21 20 63 61 6e 20   asp?.O God! can 
02d0  49 20 6e 6f 74 20 73 61 76 65 0a 4f 6e 65 20 66   I not save.One f
02e0  72 6f 6d 20 74 68 65 20 70 69 74 69 6c 65 73 73   rom the pitiless
02f0  20 77 61 76 65 3f 0a 49 73 20 61 6c 6c 20 74 68    wave?.Is all th
0300  61 74 20 77 65 20 73 65 65 20 6f 72 20 73 65 65   at we see or see
0310  6d 0a 42 75 74 20 61 20 64 72 65 61 6d 20 77 69   m.But a dream wi
0320  74 68 69 6e 20 61 20 64 72 65 61 6d 3f 0a         thin a dream?.

To run it on a Linux x86-64 computer: copy the hex, save it as poem.hex, then run xxd -r -p poem.hex > poem && chmod +x poem && ./poem.

Letters as bytes

The 32 letters the poem uses

Every letter in the poem with its byte in hexadecimal and binary. Capitals and small letters differ by one bit: 20 in hex, 32 in decimal.

Select a letter.

Practice

Read the byte

A byte from the poem is shown in hex. Pick the letter it stores.

0 of 0 correct

Practice with every word

Every word of the poem

All 85 different words in Poe's poem, in the order they first appear, as bytes. Decode them, then reveal the word.

Hex → English

How to decode

  1. Small letters run from 61 (a) to 7A (z).
  2. Capitals run from 41 (A) to 5A (Z).
  3. Count up from the start: 64 is d, 72 is r, 65 is e.
  4. Reveal the word and check.

Background

From letters to numbers

ASCII, 1963

The American Standard Code for Information Interchange gave each English letter, digit and mark a number from 0 to 127. Every plain letter of Poe's poem is still stored that way.

UTF-8, 1992

Ken Thompson and Rob Pike designed UTF-8 so the rest of the world's characters could share the same bytes. Poe's dash needs three of them.

x86-64, 2003

AMD extended Intel's x86 processors to 64 bits, with the syscall instruction this program uses to ask the system to write and to exit.