home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / zsys / znode-12 / a / ebc-3.lbr / ASCII.AZC / ASCII.ASC
Encoding:
Text File  |  1993-06-12  |  4.5 KB  |  102 lines

  1. !@@))T]))$D)%Lb.!---></w#p#s#].
  2.  
  3.      This is so weird that I couldn't help sending it in. This file is 
  4. simultaneously editable and printable as a text file, and executable 
  5. as a CP/M program (.COM) file. Thanks to that silly looking first line!
  6.  
  7.      Many disks have "README" files for info, comments, demos, etc.  
  8. You use the CP/M command "TYPE README" to display them on the screen.  
  9. I created a bunch of them to show off one of my programs, but got 
  10. tired of using TYPE every time. So I thought, "Is there a way to make 
  11. them into .COM files, so they could be executed as programs?" That 
  12. way, all I'd have to type is "README <return>."
  13.  
  14.      Naturally, there are lots of complicated ways to do this. You 
  15. could write a program to TYPE a file, muck around inside CP/M to 
  16. shorten or eliminate the need for the TYPE command, etc. But most of 
  17. these solutions are more trouble than they're worth.
  18.  
  19.      What if we just rename a text file README.COM? CP/M can't tell 
  20. the difference between text and program files: it just blindly loads 
  21. anything called ".COM" into memory, and executes it.
  22.  
  23.      "Execute" is right. If you try this with a text file, the system 
  24. will almost certainly die. That's because CP/M tries to use the text 
  25. characters as 8080 opcodes. Sensible-looking text becomes a nonsense 
  26. program. But what if I choose ASCII characters that just happen to 
  27. form a valid program? Now the text looks like nonsense, but the CPU 
  28. can run it as a program!
  29.  
  30.      The gibberish at the top of this listing is the result. It's 
  31. really a program that types all of the following text, until it finds 
  32. a "dollar" sign. Just use your word processor to put it at the 
  33. beginning of any text file, rename the file "anything.COM" and you 
  34. have an executable program!
  35.  
  36.      Writing it was rather restrictive. I wanted the "program" to use 
  37. only printable ASCII characters: no control codes or characters with 
  38. the 8th bit set. Examine the 8080 instruction set, and you'll see 
  39. you've got SHLD, LHLD, DAA, CMA, CMC, STC, HLT, all the MOV opcodes, 
  40. and some of the MVI, INR, DCR, INX, DCX, LXI and DAD instructions. But 
  41. it leaves out all JMP, CALL, RET, PUSH, POP, math and logical 
  42. instructions. Here it is in assembly language:
  43.  
  44.  addr   hex byte ASCII        instruction    comments
  45.  ----   -------- -----          -----------     ---------------------------
  46.  
  47.                         ;    ascii.asm
  48.                     ;       Lee Hart 11/26/90
  49.  
  50.              cr    equ 0dh
  51.              lf     equ 0ah
  52.                 
  53.  0100                   org 100h    ; load this program at 0100h
  54.                 
  55.  0100  21 40 40   !@@         lxi h,'@@'
  56.  0103  29         )        dad h
  57.  0104  29         )            dad h        ; "0" and "1" w/o control codes
  58.  0105  54         T        mov d,h        ;   D=1        
  59.  0106  5D         ]        mov e,l        ;   E=0
  60.  0107  29         )        dad h
  61.  0108  29         )        dad h
  62.  0109  24     <dollar>      inr h        ; create 5
  63.  010A  44         D         mov b,h        ;   B=5
  64.  010B  29         )        dad h
  65.  010C  25         %        dcr h        ; create 9
  66.  010D  4C         L        mov c,h        ;   C=9 (BDOS "type string")
  67.  010E  62         b        mov h,d
  68.  010F  2E 21      .!        mvi l,'!'
  69.  0111  2D         -        dcr l
  70.  0112  2D         -        dcr l
  71.  0113  2D         -        dcr l        ; HL=011Eh (addr of JMP opcode)
  72.  0114  3E 3C      ><        mvi a,'<'
  73.  0116  2F         /        cma        ; A="JMP" opcode 
  74.  0117  77         w        mov m,a        ; write "JMP xxxx"
  75.  0118  23         #        inx h
  76.  0119  70         p         mov m,b        ; write "JMP xx05"
  77.  011A  23         #        inx h
  78.  011B  73         s        mov m,e        ; write "JMP 0005"
  79.  011C  23         #        inx h
  80.  011D  5D         ]        mov e,l        ; DE=0121h (points to 1st char)
  81.  011E  2E 0D 0A   .<CR><LF>    db  '.',cr,lf    ; end of line, gets changed to
  82.       (C3 05 00)               (jmp 0005)     ;  jump to BDOS "type string" 
  83.  0121                        db  'Normal ASCII text goes here, ends in'
  84.                                 db  '<dollar>' 
  85.                            end
  86.  
  87.      That's it! Working out programs like this is a little like 
  88. putting together a jigsaw puzzle. I wonder if there are any other uses 
  89. for this method. Can we eliminate the "dollar sign" restriction? Is it 
  90. possible to write a line that is both executable, and readable (self- 
  91. documenting) when printed? Can it be done on an MSDOS system? How 
  92. about other CPUs? Let's see what you can do!
  93.  
  94.      copyright 11/26/90 by:  Lee Hart
  95.                              323 West 19th Street
  96.                              Holland, MI 49423
  97.  
  98.                              phone 616-396-5085 
  99.  
  100.  
  101. $
  102.