home *** CD-ROM | disk | FTP | other *** search
- From: Mike Marotta
- To: All Date: 07 Dec 91 04:27:30
- Subj: Fortune Cookie
- Conf: `PC Assembly Language'
-
- Michael E. Marotta
- 5751 Richwood #34
- Lansing, MI 48911
-
- An Efficient "Fortune Cookie" Program
-
- Using DEBUG you can write a program that can be called
- from your AUTOEXEC.BAT file to display a clever saying each time
- the computer boots. The working code in COOKIE.COM consumes a
- mere 22 bytes. The entire file fits in just over 4 Kbytes.
- COOKIE.COM selects one of sixty fortunes based on the
- value of the seconds counter of the system clock. When Function
- 2C of Interrupt 21H calls the system clock, the seconds are
- stored in the DH register. Multiplying the seconds by 46 and
- adding 120 gives the address of the fortune. This value is moved
- from the AX to the DX register because Function 09H of INT 21
- displays a string whose offset is held in DX. This interrupt is
- called twice. To save space, the carriage return (0D), line feed
- (0A) and the $ are stored in locations 118, 119 and 11A so that
- the CR LF pair is executed after the fortune is displayed. INT
- 20 halts the program with a return to DOS.
- I allowed only 70 (46H) characters per saying because the
- amount text you can enter is limited by the prompt, the E
- command, and the requisite quotation marks and dollar sign $ for
- each string.
- Before keying in the clever remarks, I zeroed out the
- working space (F for Fill) to ensure that I could easily edit the
- sayings later.
- The entire program (code and data) is saved to disk by
- setting the CX register to the size of the program, Naming it
- COOKIE.COM and Writing it.
-
- figure 1. Entering COOKIE.COM in the DEBUG environment.
-
-
- C:> debug
- -a 100
- 1607:0100 mov ah,2c
- 1607:0102 int 21
- 1607:0104 mov al,46
- 1607:0106 imul dh
- 1607:0108 add ax,120
- 1607:010B mov dx,ax
- 1607:010D mov ah,09
- 1607:011F int 21
- 1607:0111 mov dx,0118
- 1607:0114 int 21
- 1607:0116 int 20
-
- e 118
- 1607:0118 00.0d 00.0a 00.24
-
- -f 114 1500 00
- -e 120 "Beam me up Scottie, there's no intelligent life down here. $"
- -e 166 "8 + 8 = 10 $"
- -e 1ac "Hello, Dave, it's good to be working with you again. $"
-
- (and so on, in increments of 46H bytes)
-
- -e 1142 "Welcome, my son: Welcome to the machine !$"
- -r cx
- CX 0000
- :1088
- -n cookie.com
- -w
- Writing 1088 bytes
- -q
- C:>
-
- --- Maximus 2.00
- * Origin: LCC CAI BBS, Lansing MI -- (517) 483-9609 (1:159/575)