Popular Electronics
SEPTEMBER 1976
[37] [38] [39] [40]
[Part 1] [Part 2] [Part 3] [Part 4]

Fig. 5. Circuit to provide outputs used for testing

In a similar manner, you can program bursts of pulses, variable-interval pulse trains, etc. You can even write a program where a list of bytes specifies a sequence of different tones to make a programmable music box.

The following two programs are "games" that demonstrate how the COSMAC instructions can be used. No added I/O circuits are required to run these programs.

Load the following sequence:

Step   M     Bytes   Comment
1 0000 E1 1-->X
2 0001 F8 0F A1 0F-->R1.0
3 0004 64 MX-->display; X + 1
4 0005 3F 05 Wait for INPUT switch to be depressed
5 0007 6C Switch byte --> MX,D
6 0008 F8 0A F7 0A-->D; D-MX-->D
7 000B 51 64 D-->M1; MX-->display; X + 1
8 000D 30 0D 00 Stop; 00

Set both the LOAD and MP switches to off then flip RUN to on. Have someone select any digit between 1 and 9 multiply by 10, add the original digit. Set the binary code for the least significant digit of the final answer into switches 3, 2, 1, and 0, and place the other input switches in the down position. When you depress the INPUT switch, the computer will display the unknown digit.

This program illustrates how to set a memory byte into the output display with a 6C instruction. Note the use of R1 as a memory pointer and the use of the binary subtract instruction in step 6.

The following program makes the computer "think" of a byte, which you must guess in no more than seven tries:

Step   M     Bytes   Comment
1 0000 8A AB RA, 0-->RB.0 = secret byte
2 0002 F8 AA A3 AA-->R3.0 = memory pointer
3 0005 53 E3 D-->M3; 3-->X
4 0007 F8 07 A4 07-->R4.0 = number of turns
5 000A 64 23 M3-->display; 3 + 1; 3 - 1
6 000C 2A 3F 0C RA + 1 until INPUT is depressed
7 000F 37 0F Wait for INPUT to be released
8 0011 6C 8B Switch byte-->M3; RB.0-->D
9 0013 F5 33 1A M3-D-->D; Go to step 12 if M3 > RB.0
10 0016 F8 01 01-->D
11 0018 30 22 Go to step 16 (show D)
12 001A 3A 20 Go to step 15 if D = 00
13 001C 53 64 D-->M3; M3-->display; 3 + 1
14 001E 30 1E Stop loop
15 0020 F8 10 10-->D
16 0022 53 64 23 D-->M3-->display; 3 + 1; 3 - 1
17 0025 24 84 R4-1, R4.0-->D (turn counter)
18 0027 3A 0C Go to step 6 if D = 00
19 0029 8B 7B RB.0-->D; 1-->Q
20 002B 30 1C Go to step 13 (show D and stop)

Place both the MP and LOAD switches in the off position after toggling the program. When you start the program by operating RUN; AA is displayed. Now, try to guess what byte the computer has selected by setting the eight INPUT switches and depressing the main INPUT switch. If 00 is displayed you guessed correctly; if 01 is displayed, your guess is too low; if 10 is displayed, your guess is too high. You lose after seven wrong tries, at which point, the computer turns on its QLED and the displays indicate the hidden byte. To try again, set RUN to off and then on.

The subtract instruction in step 9 sets an arithmetic overflow flag (DF) if MX is equal to or greater than D. The COSMAC instruction manual covers a detailed explanation of the use of this overflow flag in arithmetic and shift operations.

In Closing. Now that you have some familiarity with programming for the Elf, look through your back issues of POPULAR ELECTRONICS for some challenging programs to write. Try the "Logidex" game in the November 1973 issue, "Tug-of-War" game in February 1975, "Electronic Dice" in July 1975, and the "Executive Digital Temper Countdowner" in December 1975. These are just a few of the many electronic games you can program instead of building.

  HEX NUMBER SYSTEM
Decimal Binary Hex
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F


[37] [38] [39] [40]
[Part 1] [Part 2] [Part 3] [Part 4]
40 POPULAR ELECTRONICS