Thursday, June 27, 2013

Fortune Cookie in Hex Code

Twenty years ago, a friend of mine with two satellite dishes to the Chicago Board of Trade and the Chicago Mercantile Exchange had a problem. His IBM-PC/ATs, running the “Windows” interface for MS-DOS, and programmed in Basic, could not properly translate data.  The trading floors identified futures contracts by codes representing commodity and date.  Most troublesome was “26” because ASCII code 26, control-Z, looked like “End of file” to his computers. 

I had him lock me in his office on Friday and let me out on Sunday morning.  We actually worked together, ate breakfast and lunch, but overnight, I was alone with the computers and Peter Norton’s books on IBM-PC Assembler.  Working in Debug, after re-keying versions of the same code over and over, I said to myself, “I wish I had an editor” and I heard the voice of Obi-Wan Kenobi: ”Beware the dark side of the Force.” 

The project was successful. 

Afterward, I wrote a “Fortune Cookie” program for myself.  It is an old hack. On boot-up, the computer displays a random good-luck saying. I chose 60 of them and called the seconds counter of the system clock to point to one.  I wrote it in hex in Debug. 

B4 2C
CD 21
B0 46
F6 EE
05 20 01
89 C2
B4 09
CD 21
BA 18 01
CD 21
CD 20

Debug has an Assemble command to display a more English-like translation of the hex codes. Each of the sayings was limited to 80 characters with 40 more spaces for some margin and to create a buffer offset.

B4 2C        MOV AH,2C       Get the clock
CD 21        INT 21          execute
B0 46        MOV AL,46       Get the seconds
F6 EE        IMUL DH         multiply the DH by the seconds   
05 20 01     ADD AX, 0120    add 120 to that
89 C2        MOV DX,AX       put that number in the DX register
B4 09        MOV AH,09       display to screen
CD 21        INT 21          execute
BA 18 01     MOV DX, 0118    end of line
CD 21        INT 21          execute
CD 20        INT 20          quit

Negotiate to the Command Prompt. Enter DEBUG.
The command "d" is for Display memory.
The ? Question Mark brings up all available commands.
These are some of the 60 sayings:

Beam me up, Scotty: there's no intelligent life down here $
8 + 8 = 10 $
4 + 4 = 10 $
5 + 5 = 0Ah $
5 + 5 = &12 $
Daisy, Daisy, gove  m   y  r   ans er  ru  $
Hello, Dave, it's good to be working with you again! $
TRON to user: Send me a disk. $  
In the beginning was the Word $    
If A is A, how can X = X + 1? $ 
A program is a selective recreation of reality...$   
... according to the psycho-epistemology of the programmer$ 
I am alive and I have rights!$ 






No comments:

Post a Comment