PeekoIntroduction The idea of this BASIC simulation program is to give the complete beginner an idea of how a microprocessor works in terms of data processing and movement. In particular it demonstrates that any given byte of data in the processor's memory could be
Once the PEEKO - Computer and all its features have been mastered it is quite an easy step to write machine code programs in 6502 code, opening up a whole new range of fast - action applications for the ATOMPEEKO - Computer Monitor
When PEEKO is RUN the user enters the ‘monitor’ of the PEEKO - computer. The monitor commands are single keystrokes:
The ATOM’s usual cursor controls can be used to move the cursor around.
What do microprocessors do?
Each instruction has a name of three or four letters called the ‘mnemonic’ which describes what the instruction does.
The standard PEEKO - computor instruction set is:
A ‘program’ consists of a sequence of instructions which the processor executes, instruction by instruction, starting from the lowest address until it reaches a BRK instruction. The ‘jump’ instructions are designed to make the processor leave its normal sequence of execution, and fetch its next instruction from some other specified address.
Programming the PEEKO - Computer
The following section illustrates the use of the PF.EKO computer’s instructions. Most of the instructions will be introduced by means ef a demonstration program. Each program will be shown as a series of mnemonics and their assembled code, and in most cases a printout of the screen.
First type in the code starting at location 00. Notice how each instruction is ‘built - up’ on the line below ‘RUN’ on the screen. Next enter the two digits to be added at locations 40 and 41 - use the cursor controls to get the cursor there.
Example 2 - Add 2 two - digit numbersThis adds the numbers in 40, 41 and 42, 43 and puts the result in 44, 45, 46.
This program contains one new instruction this is LDA @ which loads the accumulator immediately with the next byte in the program - in this case 0.
Problem 1Using LDA. STA, ADC, CLC and LDA@ write a program that will add the numbers in locations 40, 41 and 42 storing the two digit result in 43 and 44.
Example 3 - Countdown program
The following program will subtract one from location 40 each time it goes round a continuous loop. (N.b. 0 - 1 = 9)
This program introduces two new instructions. DEC subtracts one from the specified memory location
By typing F instead of space to run the program PEEKO will execute the program without stopping after each instruction.
By single stepping through this it will be noticed that when location 41 gets to 0 the zero flag changes from 0 to 1. The zero flag is set whenever an arithmetic instruction gives a zero result, and to 0 otherwise. The JNE instruction is similar to JMP except that the jump only occurs if the previous result was not equal to zero. This causes the program to count down to zero.
The INC instruction is similar to DEC except that it adds one to the following address. It also will set the zero flag if the result is zero, my replacing DEC (code 5) with INC code 6) in the previous program and setting 40 and 41 to 0 the program can be made to count up to (1)00.
Write a program that will count from 99 to 0 and back up to (1)00 in a continuous loop.
The instructions discussed so far form the standard instruction set. In addition to these there are 10 alternative instructions which can replace any of the standard instructions. The (i) command in the PEEKO Computer will ask for the number of the instruction to be replaced and the number of the instruction that will take its place. This ability to change the instruction set makes the PEEKO - computer very adaptable and able to be programmed for many tasks despite its limited program size. Most of this secondary set can be explained very easily as they are similar to those in the standard set
The last two extra instructions are an indirect load and store. These are more complex than the others so will be dealt with in greater depth in example 6,
Calculates 40, 41 - 42, 43 with the result in 44, 45. A carry of 1 indicates no overflow. If the carry is 0 then 42, 43 was greater than 40, 41 and hence there is a negative result.
Write a program to multiply two single - digit numbers by successive addition.
Example 6 - Indirect addressing
Instruction set changes:1 LDA (
2 STA ( This program uses indirect addressing. If locations 40 and 41 were: 0 2
and location 20 was: 8
then LDA ( 40 ) would load the accumulator from location 20 (as 40, 41 contains 20) and would therefore be loaded with 8.
By running this short program you will be able to see how indirect addressing can be used to move the contents of one address to another address, in this case from 30 to 20.
Example 7 — Copying a 10—digit tableThe program for this example is supplied on cassette, as the file COPY, and can be loaded into the PEEKO - computer using the < command.
Instruction set changes:1 LDA (
2 STA (
This example shows how indirect addressing can easily be used to access a table of data. The program will copy a lime of data, starting at the location pointed to by 40, 41, to the location pointed to by 42, 43. Locations 20 to 29 should contain the data to be copied to 30 to 39.
Example 8 - Add two lines of data
This program is supplied on cassette as the file ADD. Instruction set changes:1 LDA (
2 STA (
The program will add two lines of data in the memory together, and store the result. As space is limited in the PEEKO computer the program actually adds up two lines within the program itself.
This program again uses indirect addressing extensively.
Example 9 - Finding a factor of a numberThis program is supplied on cassette as the file FACTOR.
Instruction set changes:
The program finds the highest factor less than 10 of the 2 digit number in 48, 49.
Put the number to be factorised in 48, 49.
Program the PEEKO - computer to divide a 2 digit number by a single digit. This will certainly need SBC and SEC and could also need some other instructions. Take the factor program as an example.
Input and Output Ports
These two ports, at locations 98 and 99 in the PEEKO computer, correspond to the A and B ports of the 6522 VIA chip which can be fitted inside the ATOM. The input port reads in the bottom 4 hits of port A, putting the data in PEEKO location 98. If the Input is larger than 10 it is cut to one digit and the carry flag is set to 1. The output port outputs the data to port B.
Answers to Problems
This proqram will count up and down locations 40 and 41. You will probably notice that it does not stop at 00 when counting down, but when it decrements from ten (i.e. 12 11 10 00 01 02 . You should be able to correct this when you have found out about the carry flag and its related conditional jumps later.
This multiplies the contents of 40 and 41 puttinq the result in 42 and 43.
Problem 4instruction set changes:
This divides the contents of 44 and 45 by the contents of 46, leaving the result in 47, 48 and 49 are used in the calculation.