MACHINE CODE SIMULATION

by

ANTHONY GOODHEW

A Master's by Course Dissertation submitted in partial fulfilment of the requirements for the award of a degree of MSc in Computer Education of Loughborough University of Technology, January 1988.

Supervisor: Dr H W F English

Dept. Engineering Mathematics LUT

(Cl Anthony Goodhew 1988 ABSTRACT

The teaching of machine architecture and low level languages at all stages of computer studies education has presented certain difficulties since the subject first became examinable in schools. These include the lack of training of teaching staff, suitable low-level languages and specialist computing hardware.

One approach is to make the students' normal computer simulate the actions of a simpler machine which can only be programmed with a low level language which has been specially designed to demonstrate the necessary features which are to be taught. The histories of several such simulations are analysed and the specification for a new simulation, for 'A' level Computer Science candidates, is developed and carried through the stages of programming, testing and educational trials.

The new simulation allows the student to program in machine code or in an assembly language and demonstrates the connection between the two with an assembler. When the student's program is executed, at a speed controlled by the student, the simulation shows graphically the internal movements of data between registers in the Central Processing Unit while a commentary appears in the upper window to aid the understanding of the fetch-execute cycle.

A series of student exercises are provided to gently lead the student through the various features of the simulation. These include arithmetic, control of loops, different addressing modes and subroutines. Acknowledgements

I am pleased to acknowledge the assistance given in testing this program by Patrick Doel, Michael Ginns, Duncan Robson, Jane Horton, Mark Twells and Alan Howe.

I am also very grateful for the advice provided by my supervisor Dr H English.

Declaration

I declare that this dissertation is entirely my own work. Contents

Abstract Acknowledgements Declaration Chapter 1 Introduction 1 Chapter 2 Review of existing software 4 Chapter 3 ENGINE- a simple computer simulation 11 3.1 The history of ENGINE 11 3.2 The user interface 18 3.3 Using the simulation 18 3.4 Using ENGINE 24 Chapter 4 The development of SIMPLE 26 4.1 The development method 28 4.2 The user interface 31 4.3 Screen display 34 4.4 The storage of the user"s program 40 4.5 The assembler 42 4.6 Procedures and functions in SIMPLE 43 4.7 Procedures and functions in ASSEMBL 47 Chapter 5 Using SIMPLE and the results of testing 48 5.1 Testing the SIMPLE package 50 Chapter 6 Conclusions SS Bibliography 57 Appendices 60 1 Documentation for ENGINE 62 2 Teachers" notes for SIMPLE 74 3 Students' documentation for SIMPLE 93 4 Testers' report form 105 5 Listing of SIMPLE 109 6 Listing of ASSEMBL 133 7 Listing of MAKfi 17 142 8 Listing of MAKhe18 144 Chapter 1 - Introduction

The teaching of processor architecture and low-level languages poses difficulties both at GCSE and 'A' level. These include a lack of training and experience of staff, the provision of suitable computing facilities and the choice of a suitable language.

Few schools and colleges have sufficient funds to be able to buy special hardware for the teaching of this part of the syllabus so they have to make good use of the available hardware. In many cases this is either 380Z or 480Z computers from RML or BBC computers from Acorn. These contain either Z80 or 6502 processors. Learning to program these devices requires a thorough understanding of the facilities they offer and would take far longer than can usually be devoted to this section of the syllabus. Few teachers would feel capable of undertaking such teaching but if taught any learning would probably have been too specific to the device being used than was intended by the examination syllabus.

An additional problem when using the processor of such a computer is that it is very easy to crash the whole system by a simple error in programming while learning the language.

One approach to overcome these problems is to design a model computer incorporating the necessary features and leaving out others which are not needed at the level being taught. The main arguments in favour of this approach through a model are:

1) A model computer enables the topics of processor architecture, machine language and assembly language to be given an integrated treatment.

2) The design of all three topics can be pitched at the appropriate level for the capabilities of the students who are to use the simulated computer.

PAGE 1 3) The simulated machine can be representative of a range of several actual computers rather than tightly tied to one in particular.

4) Additional educational facilities can be added to the model. 5) Avoidance of the difficulties and complications of real machine code programming by the use of idealised conditions.

6) Overcoming the extra cost of the purchase of additional specialised hardware.

7) The usually over-rapid execution of a machine code program can be controlled allowing insights into processes within the model.

8) Safety nets many be built into the simulation to prevent total system crashes and offer commentaries and diagnostic information as educational aids.

9) Control the level of complexity is possible. The level of difficulty can be incremented slowly.

With care the possible disadvantages of simulations can be minimised. These disadvantages are:-

1) Over-simplification to an unacceptable level.

2) Provision of a false perception of reality.

3) The curtailment of real experience of the topic.

T O'Shea ~ J Self (1983), P Bishop (1982) in his chapter in Microcomputers in Education, edited by C Smith (1982), S Dunn and V Morgan (1987) and A Keller (1987) all provide more detail on the educational uses of simulations.

PAGE 2 The chapters which follow outline several attempts at providing such simulations. Some were devised for younger students in the 14 to 16 age range and are further from reality than those intended for older students, aged 16 to 19, studying for an 'A' level in Computer Science. Later chapters and appendices outline the development of a new simulation, SIMPLE, designed to be of use to these older students.

PAGE 3 Chapter 2 Review of existing software

At least seven different machine code simulators have been used in British schools. These include:-

CG319 from the City and Guilds of London Institute

BMC from the Advisory Unit for Computer Based Education in Hatfield

CESIL from Computer Education in Schools

ENGINE from the North Cambridgeshire Computer Education Group

PEEKO-COMPUTER from Acornsoft

IMC-2 by Peter Bishop.

AMC by Peter Bishop.

They vary greatly in their original purpose, level of complexity, target group and the host machines on which they may be executed.

CG319

The Revised Mnemonic Code (1968) was a development from an earlier code published in 1964. It defined a low-level code to be used for the teaching of programming for the Certificate in Computer Programming and Information Processing of the City and Guilds of London Institute. This course, coded 319, was widely taught in technical colleges at the time. The participating colleges where expected to provide a simulation of the defined machine on the equipment available within the institution. At this time many such colleges were equipped with IBM 1130 computers with paper-tape or punched card input/output and a printer. The minimum hardware requirement

PAGE 4 was a single reader and punch for input/output and a suitable CPU. Such machines often had very little memory, typically 8K words, and the simulator was often written in Fortran or Algol. It was with such a simulator that I was first introduced to programming on a short course for mathematics teachers in 1968.

The aim of the simulator was to provide a common language across the country for the purpose of the examinations regardless of the hardware available within the colleges. This meant that students from all over the country could sit the same examination papers and be set language specific questions. It was designed for students aged from 16 to 21.

At this time computers were very expensive items of equipment for technical colleges. To overcome the shortage of funds money was transferred from schools' budgets and the colleges were expected to provide computing resources for local schools. In fulfilling these conditions the colleges were expected to provide computer training for the local teachers and then to provide processing of programs produced by school pupils. Many technical colleges began by putting on courses in CG319. In many LEAs CG319 soon became the major teaching language for school aged students. Gradually support materials were developed to aid this teaching and CG319 language specific questions were added to CSE examinations. Examination course-work programming was carried out in CG319.

The mnemonic language provided a very wide mixture of instructions. These ranged from simple arithmetic instructions such as ADD, SUB, MLT and DIV, to functions provided as instructions such as SIN, COS and EXP. Nine different jump instructions were provided, including JSR to implement subroutines. LOP even controlled program loops automatically. Direct, immediate and indexed addressing are available but only 1000 store locations were provided.

The simulation worked in floating-point denary arithmetic and

PAGE 5 was able to provide easily understood answers. It was easier to use than the high level languages available in the early seventies, it gave some insight into the Tetch execute cycle and machine architecture and many versions provided the optional trace facility.

The use of CG319 continued until the machines on which the simulations were executed were replaced by more powerful computers oTfering more suitable high level language implementations.

BMC (Beginner's Mini Computer)

The Beginner's Mini Computer was 'invented at the OfTley Conference in March 1977. It was felt that a teaching aid, both simpler and more modern than the currently used BBCX simulation, was desirable for teaching machine architecture and low level languages.' (J H Gordon, 1982)

The BMC is very diTferent from CG319 because it is a real machine, "M6812l12l based" or "Z8121 based", which can be loaned by schools in HertTordshire. It has also been simulated on the DEC-112l and PDP11/7121 computers at HatTield Polytechnic and on RML 38121Z micro computers. On the real machine systems sOTtware is supplied in ROM and includes an assembler Tor the Hertfordshire Assembler Language (HAL) and Tour library routines to provide input/output in decimal, the output of characters and a new line Tacility. It was designed to provide a Tull range of machine instructions Tor CSE, '0' level and "A' level students. The low numbered function codes are suitable Tor CSE students to avoid the diTficulty of lIunexplained ll codes.

BMC is a 16-bit machine using absolute, indirect and indexed addressing to access the full 64K of available memory.

Instructions are typed in using mnemonic instructions with

PAGE 6 numeric operands. The assembler does not support symbolic variable names or labels for jump addresses.

Later 380Z versions of the simulation have a 'glass-top' facility to display the contents of specified registers while a student program is executed. The simulation is command driven using the normal Hertfordshire user interface. See K Alexander and D Blanchard (1985 pp 27-28). The available commands are:- HELP, COMMANDS, GLASS, FINISH, GO, SPEED, BINARY, OCTAL, PAUSE, VALUES, DISPLAY, REMOVE and EXPLAIN.

CESIL

The Computer Education in Schools Instructional Language is used as the initial teaching language in the ICL Computer Education in Schools series of of Computer Studies texts.

Monson, Sewell ~ Vickers (1978 and 1979) These were produced for CSE and '0' level students. This low level language, simulated on a wide range of computers, works in integers with the following instructions:- LOAD, STORE, ADD, SUBTRACT, MULTIPLY, DIVIDE, IN, OUT LINE, PRINT, JINEG, JIZERO, JUMP and HALT. It supports symbolic variable names, immediate addressing and labels for jumps. The students' documentation in the text makes reference to the accumulator and store locations but it is not possible for the student to obtain the internal format of instructions. The intention was to provide a simple programming language before moving on to BASIC rather than aid the teaching of machine architecture.

ENGINE

Engine was written by me for the North Cambridgeshire Computer Education Group as a teaching aid for machine architecture and the fetch/execute cycle. It was originally written for the Commodore PET and Ohio Scientific C1E computers. At a later stage it was ported into the BBC computer. Full details of its development are given in chapter 3.

PAGE 7 PEEKO-COMPUTER

This simulation by Tim Dobson was developed from an original program by Paul Beverley and is published by Acornsoft for the BBC computer. It main aim 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 (a) a coded instruction, (b) part of the address of some other part of memory, or (c) some actual data which is used in the course of the program.' T Dobson (1982)

The set of instructions is limited to ten at a time but may be picked from a list of twenty available instructions. (This has the unfortunate effect of changing the internal code representing an instruction.) All instructions are related to those of the 6502 microprocessor and the documentation suggests that '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.' T Dobson (1982)

The simulation allows numerically coded instructions to be entered by the user and then executed, optionally by single stepping. As instructions are executed the display shows the contents of the accumulator, the current instruction and the contents of the carry and zero status bits and the position of the program counter.

IMC-2 (Introductory Model Computer)

The IMC-2 Simulation System was written by Peter Bishop and is published by Edward Arnold. It is available for both 380Z and BBC computers. It simulates an 8-bit computer and was developed to aid the teaching of Computer Studies at CSE and '0' level. 'It enables the user to enter and edit an IMC-2 assembly language program, or retrieve one from a disk file. The program can then be assembled, displayed on the screen,

PAGE 8 printed and run. An animated diagram of the IMC-2 shows exactly what is happening while a program is running.' P Bishop (1986)

The program is command driven and provides the following commands:- CLEAR, INPUT, GET, INSERT, DELETE, LIST, PRINT, ASSEMBLE, DISPLAY, ALTER, RUN, SAVE and DONE.

The assembler allows symbolic variables and jump labels.

AMC (A-level Model Computer)

This simulation, also by Peter Bishop, was first described in 1982. P Bishop (1982) Its target students are 'A' level Computer Scientists. Although a 16-bit simulation it is very similar to his 8-bit IMC-2 simulation but has 56 implemented instructions. The accumulator, index register and stack pointer are addressable. Four addressing modes are implemented, immediate, absolute, indirect and indexed.

The AMC is used in Advanced Computing Science, P Bishop (1987), as the example for the teaching of machine architecture.

The existing simulation software ranges from denary implementations with extended arithmetic instructions such as GC319, ENGINE and CESIL which were designed for students from about 14 years upwards through the nearer to reality IMC-2 and BMC for the same age group to the complicated 'A' level simulation of AMC.

If a new simulation was to be developed it was important to include the best features of the existing software and add extra features. After consideration of the current 'A' level syllabi I found that the low level language features required fall into the following categories:-

PAGE 9 Instructions: Mnemonic codes, relationship between assembly and machine instructions and subroutines.

Addressing: Symbolic addressing, addressing modes: immediate, absolute, indirect and indexed.

Operations: Fetch and store, logical, arithmetic, shift and jump.

Input/output: Input and output.

I decided that the simulation should not be more involved or difficult than was necessary to cover these topics but should include a 'glass-top' to allow viewing of the contents of the registers while executing a user program. It should show the movement of data within the processor and should provide comments on the progress of the execution. Speed variation and single stepping (executing the program one instruction at a time) should be included. It must also run on BBC computers, all that is available in my college.

PAGE 10 Chapter 3 - ENGINE - a simple computer simulation

3.1 THE HISTORY OF ENGINE

When I moved to the Cambridgeshire Fens in 1971 I found that CG319 and FORTRAN IV were the languages in use in Cambridgeshire schools. Both languages had received considerable support in the form of courses for teachers and the free availability of printed support materials for both staff and students. Pupil's programs were processed at the Cambridgeshire College of Arts and Technology (CCAT) on and IBM 1130 computer. (A postal punching service from coding sheets was provided for schools without teletypes and modems.) Many schools were making extensive use of CG319 as FORTRAN was found to be rather difficult for some students developing coursework for a CSE in computer Studies. When the IBM 1130 at CCAT was replaced by a more powerful, time-sharing computer a new CG319 simulator was quickly made available from another higher education college. (The City and Guild's 319 Certificate in Computer Programming and Information Processing was very popular at this time and many FE and HE colleges provided tutition.)

With the arrival of time-shared BASIC the use of CG319 as the main language for CSE coursework declined but may schools retained its use for a short period of the two year course to aid the teaching of machine architecture, the fetch/execute cycle and to provide experience of low level languages.

When the computer system at CCAT was again replaced no CG319 simulator for the new machine was easily available as the City and Guilds of London Institute had withdrawn the 319 certificate. At about the same time many schools were beginning to purchase micro-computers - mainly cassette based Commodore PETs and Ohio Scientific CIE computers with 8K or 16K of memory.

PAGE 11 A group of school micro-computer users was formed with the aim of developing a new Mode 3 CSE examination in Computer Studies. Discussion on the teaching of those areas of the syllabus for which CG319 had been found to be so useful resulted in the formulation of a specification for a new simulator program:

1 The program should run on the microcomputers available within the schools of the North Cambridgeshire CSE mode 3 Computer Studies group.

2 The program should use denary internal codes and addresses.

3 Programs should consist of mnemonic instructions which are checked for errors on entry.

4 The four floating-point arithmetic operations (+-*/) should be available so that real solutions could be obtained.

5 Character manipulation should be supported.

6 Control of output should be supported.

7 Indexed addressing should be supported.

8 Subroutines should be supported.

9 A trace facility should be available to aid the debugging of programs.

10 Program listings showing internal codes should be available.

11 A memory editor facility would be useful for program debugging.

PAGE 12 After prolonged discussion a language consisting of a subset of CG319 was found to be suitable with the following facilities:

DIRECTIVES

(STORE n) sets the program pointer to a location in store for program entry.

(EXECUTE n) begins execution of a program at location n.

Only the initial letter following the first bracket is checked allowing short form directives of the type (S 25) and (E 20) to be used.

CONSTANTS

These must be preceded by a + or - for numeric constants and by = for character constants. Constants may be placed from location 10 upwards.

INSTRUCTION FORMAT

Instructions consist of an operation code, three upper-case letters, with an operand made up of an address in denary and an optional modifier - an index register - indicated by A after the address. i.e. ADD 34 more generally 000 aAi

In the following definitions A is the accumulator and (A) indicates the contents of the accumulator, a is an address in the store, (a) is the contents of that store, i is an index register and (i) is the contents of the register:

PAGE 13 DATA MOVEMENT OPERATIONS

LDA aAi Load accumulator from store location specified. A:=(a+(i»

STA aAi Store a copy of the contents of accumulator in specified location. a+(i):=(A)

ARITHMETIC OPERATIONS

ADD aAi Add the contents of specified location to contents of accumulator A:=(A)+(a+(i»

SUB aAi Subtract the contents of specified location from contents of accumulator A:=(A)-(a+(i»

MLT aAi Multiply the contents of accumulator by contents of specified location. A:=(A)*(a+(i»

DIV aAi Divide the contents of accumulator by contents of specified location. A:=(A)/(a+(i»

INPUT/OUTPUT OPERATIONS

RNA Read number into accumulator. Prompt is #

WNA Write number in accumulator.

WNL n Write n new lines.

WSS n Write n spaces (if n=0 skip to next column.)

PAGE 14 RCH Read character into accumulator. ASCII value of character left in accumulator. Prompt is C

WCH Write character from accumulator. (ASCII code conversion used.)

JUMP INSTRUCTIONS

JUN aAi Jump unconditionally to location specified.

JEQ aAi Jump if accumulator contents =0

JLT aAi Jump if accumulator contents <0

JSR aAi Jump to subroutine at specified location after having saved return address in location 2. Loc2 =(SCR) (Return from subroutine with JUN 0 A 2)

TERMINATOR STP Stop execution of program

SPECIAL LOCATIONS IN ENGINE

o Protected zero (STA 0 is invalid) 1 Accumulator 2 subroutine return address 3 to 9 index registers 10 upwards may hold instructions, data or constants.

INDEX REGISTERS

Indexed addressing is carried out by modifying the instruction address i.e. ADD 99A3 The effective address will be found by adding the contents of location 3 to 99.

The CG319 instructions thought not to be necessary for the new

PAGE 15 simulator were the extra jumps (JNE, JGE, JLE and JGR) , the mathematical functions (SQT, EXP, LGN, SIN, COS, ARC [arctanl and ENT [entier - like INTl) , the device allocation instructions (ARD and AWR to access different peripherals), the loop instruction (LOP), the conversion instructions (CNN and CNC [conversions between numbers and charactersl) and the block data handling instructions (ACB [access blockl, BSP [backspacel and RWD [rewindl). The main purpose of the new simulator was to help students understand the problems of low level code programming and BASIC could be used for data processing.

I undertook to write the simulator in BASIC and to prepare versions which would execute in both Commodore and Ohio Scientific machines.

The 8K BASICs available in these machines were very primitive. Procedures, user defined functions, WHILE and REPEAT loops were not supported. Necessary speed was only obtained by putting the most used and time dependent subroutines early in the program. The variable identifiers were limited to a single letter or letter and a digit and graphics (of a sort) were only possible by PEEKing and POKEing the screen memory with graphic characters. Some computers being limited to 8K RAM and the necessity of storing the user's instructions within this restricted space posed a further problem. Little room was available for involved input routines or extensive code to increase robustness.

The programs were written, tested and used extensively by schools within North Cambridgeshire. The full development cycle was possible with feedback from schools using the program being used to correct deficiencies and add extra features.

After the first year of use feedback from the group suggested that the program had been useful in fulfilling its aim of aiding the teaching of machine architecture. We had reports

PAGE 16 that a group at the Advisory Unit for Computer Based Education in Hatfield, using 380Z computers, had developed a simulator called BMC which allowed the user to view the values in certain registers while the simulation was in operation. (They had called it a 'glass-topped' version.) I decided to improve the ENGINE simulator for use on the Ohio computers available in my school to offer the same facility. Instead of using the whole screen for input/output this was restricted to a smaller window in the bottom left two thirds of the screen. A few lines at the top could then be used to provide a commentary on the stages of the fetch/execute cycle while the contents of the most important registers or memory locations could be displayed in a column at the right of the screen. The glass-top trace was made available as an alternative to the debugging trace. It greatly slowed down the execution of the user's program (Speed setting could be varied) but was found to be of considerable help in the understanding of the fetch/execute cycle and indexed addressing.

When BBC computers came available in the schools within the CSE Computer Studies group I was asked to provide a version of the simulator for this machine. Since the previous program had been widely used for some time it was believed to be bug free. A total rewrite of the program in BBC Basic would have taken more time than I could really devote to the task and might well have introduced new bugs into the program. I decided to port the program from the Ohio into the BBC via the serial ports that both machines had available and then make just those modifications necessary to the code to enable it to run in the BBC. The conversion and initial testing took just one weekend and was soon in use throughout the group. The code is still very much as it was in the original version, and relies very much on IFs, GOT Os and numbered subroutines some in apparently strange places, for speed.

I have been using the program with students in CSE, 'O'level, 16+ and GCSE classes for several years to help teach the fetch/execute cycle and to obtain experience of low level

PAGE 17 code. The use of denary addresses, internal operation codes and floating-point arithmetic makes it very useful for this age group. 3.2 THE USER INTERFACE

The program uses a series of menus to provide access to the various facilities. Single key presses are all that are need to select items from the menus and the keys used are often mnemonically coded so that the first letter of the required action is used, such as 'P' for printing and 'C' for change the program. Invalid key presses are ignored.

Although little action has been taken to add extra robustness to the BBC version I have not found this to be a problem. If the students are determined to crash the program this is always possible but the majority of students use the program with normal care and experience few problems in this area. They quickly learn the actions of the various menu items and concentrate on given problems using the software as a tool to their learning.

3.3 USING THE SIMULATION

On running the simulator the ENGINE title appears and the size of memory simulated is displayed (110 locations in this version). The user is asked for a program title. This can be just a simple program name but can also include the author's name. This string of characters will be printed out at the top of printed runs and listings and the name is useful if printers are shared between several users. (Typing 'DISK-IN' as the title takes the user directly to the disc 110 prompt so that a saved program may be loaded.)

A ? prompt appears after the number 10. This means that the simulator is ready to receive an instruction for location 10. At this point the user can type in a mnemonic instruction, a constant (preceded by +, - or =) or a directive to change the

PAGE 18 EXECUTE I/O instruction **************************** ENGdeMo * SCR 23 Executing froM 22 * IR ft 3 * 42QQQQ -11 * OR ft 5 * 42 (RNA) * AR * Q * ACC * -11 * Loc. 11 * 21 * TEST FLAG * location. The user types in a suitable response, an instruction, a (STORE n) directive or a constant and the location pointer increments to the next location. Invalid responses are not accepted and a short error message appears. Once a program has been entered the directive (EXECUTE n) is issued. The n is the location of the first instruction to be executed. Pressing ! or ESCAPE while entering a program takes the user directly to the main program menu.

The execution of the user program begins with the Trace? prompt. If the user replies with a 'Y' then the type of trace required is requested. The 'FETCH/EXECUTE' trace is obtained by pressing 'F' or 'E' and the 'RECORD' trace selected with 'R'. The former executes the program at a user selected speed, even the fastest of which is much slower than an untraced run, while displaying registers within the machine through a 'glass-top'. Its main function is to aid the understanding of the fetch/execute cycle. (A screen dump of the 'glass-top' display is shown on the opposite page.) A record trace displays the changes to locations and registers within the computer during the run and can be useful in debugging programs.

At the end of a run the user is presented with a menu allowing programs to be saved or loaded from disc, allowing the printer to be switched on or off, allowing a location in memory to the edited, a listing of the program obtained, the entry of a new program or end of the simulation. The menu is shown on page 21. (The final option is not a total disaster if pressed by accident as 'GOTO 1000' typed immediately will return the user to the main menu with the internal user code intact.)

PAGE 19 SAMPLE RUN

BBC ENGINE

MNEMONIC CODE SIMULATOR.

Number of storage locations is 110

Program title ?Eval x A 2-7x+1 when x)=0

10 ?(STORE 20) 20 ?+1 21 ?+7 22 ?RNA 23 ?JLT 34 24 ?STA 10 25 ?MLT 21 26 ?STA 11 27 ?LDA 10 28 ?MLT 10 29 ?SUB 11 30 ?ADD 20 31 ?WNA 32 ?WNL 2 33 ?JUN 22 34 ?STP 35 ?(EXE 22)

Trace ? N

PAGE 20 Eval x A 2-7x+l when x)=0

Executing from 22

# 7 1

# 8 9

# 5 -9

# -2

STOP at 34

Tap SPACE for menu

MENU ====

Press:

L for LIST

R for RUN

C for CHANGE program.

P for Printer ON.

N for NEW program.

F when Finished.

D for Disk 110.

PAGE 21 ? L

Eval x A 2-7x+1 when x>=0

LIST

Tap SPACE to continue

Loc. Instr. Contents

1 -2 10 5 11 35 # 20 1 21 7 22 RNA 420000 23 JLT 34 250340 24 STA 10 160100 25 MLT 21 40210 26 STA 11 160110 27 LDA 10 10100 28 MLT 10 40100 29 SUB 11 30110 30 ADD 20 20200 31 WNA 430000 32 WNL 2 460020 33 JUN 22 200220 34 STP 500000

Executes from 22

End of list

Tap SPACE for menu.

PAGE 22 (Second run from MENU)

Trace ? Y Type: Fetch/Execute or Record (R Pressed)

Eval xA2-7x+1 when x >=111

Executing from 22 # 4

22 421111111110 aCc= 4 EA= 0

23 2511134111 SCR=24 acc= 4 F

24 16011110 loc10= 4 EA=10

25 411121111 acc=2B EA=21

26 160110 loc11=2B EA=l1

27 11111111111 acc= 4 EA=10

2B 411111110 acc=16 EA=1111

29 3011111 acc=-12 EA=l1

3111 21112111111 acc=-11 EA=20 -11

33 21110220 SCR=22 acc=-11 # -5

22 420111111111 acc=-5 EA= 0

23 250340 SCR=34 acc=-5 T

STOP at 34

PAGE 23 3.4 USING ENGINE

I normally use the program when I am teaching machine architecture, machine code and low level languages. I explain the effects of the various instructions which are available to the class and we develop a program to evaluate a simple formula, such as 3a+7b-2, as a class exercise. Discussion takes place on wher'e the program, constants and variables will go in memory, how they will appear in memory and how the program can store a term already evaluated for later use. The program is then entered and executed without tracing to see if it produces the expected result. The record trace is then used to check what happens to the data as it is processed and finally the fetch/execute trace is used to follow how the machine moves from one instruction to,the next using the sequence control register. I show that memory contains just numbers which can be interpreted as numbers, instructions or even characters.

After the students have tried a similar task on their own we move on to loops and decisions with the limited tests available to the programmer in this language. The students are then set the task of making the computer count up or down between two values input as data.

An example answer is given on the next page with comments.

PAGE 24 (S 2121> +1 Constant for counting on RNA STA 6121 first and counter RNA STA 61 last LOA 6121 WNA print counter WNL 1 new line ADD 2121 add 1 to counter STA 6121 store counter SUB 61 finished? JLT 25 loop back if neg JEQ 25 loop back if zero STP (E 21>

The final session deals with 'real machine code' and the difficulties of addresses and operation codes in binary, limited arithmetic instructions and dealing with negative numbers. Students readily appreciate the need for an assembler program and the extra facilities which may be provided such as error checking, and symbolic variable names.

ENGINE retains many of the original instructions and concepts of the original CG319 code but its use has undergone a drastic change. No longer is it used as a programming language to solve problems but as an aid to understanding of how computers work. In the age range of 14 to 16 it still has a place even within the new GCSE syllabuses. Its usefulness with older students studying for 'A' level Computer Science is limited. Such students need a simulator which uses binary rather than denary numbers internally and a 'glass-top' revealing more details of the internal registers and the passage of data between them. To over come these needs SIMPLE was developed.

Educational documentation for ENGINE appears in appendix 1.

PAGE 25 CHAPTER 4 - The development of SIMPLE

Previous arguments have developed the need for a more sophisticated program to fulfil the needs of students in the 16 to 19 age group who are learning about machine architecture, the fetch/execute cycle, machine code, assembly code and assemblers. Consideration of these needs and discussion with colleagues gave rise to the following aims for such a program.

Educational aims:

1. To enable students to execute low-level language programs so that they can have first hand experience of this type of programming and so develop a greater understanding of the difficulties involved.

2. To provide a means of demonstrating different addressing methods and to provide experiences of their use.

3. To provide a demonstration of what happens within the the CPU while a program is being executed. To demonstrate the FETCH/EXECUTE cycle and the functions of the various registers within the CPU.

4. To demonstrate the usefulness of subroutines and illustrate one simple method of their implementation.

5. To demonstrate the facilities provided by an ASSEMBLER and provide practice in its use. To illustrate the usefulness of an assembler in the preparation of machine code programs.

Target students

This package was originally designed for 'A' level Computer Science students (16 - 19 years) who have written programs in

PAGE 26 a high-level language and are studying the section of the syllabus on machine architecture. Its use is to augment the study of a suitable text and to provide experience of programming at lower levels - using assembler and machine code.

PAGE 27 4.1 THE DEVELOPMENT METHOD

As a first step to the development of such a program I looked at the texts being used by my students to see if the pseudo machine code used there for examples was suitable for simulation. CS French (1984) uses more than one pseudo code and the major example supports the use of an index register in its addressing methods but gives no method of putting values into the register. Five different jump instructions are provided but no shift instructions.

I wanted the simulation to provide a wider range of instruction types and to allow several different addressing methods to be used. The internal representation of instructions needed to be kept simple, so that students could quickly understand the instruction set and that it should not be radically different from that developed in their text so as to avoid confusion. After a considerable number of attempts I settled on five different instruction types:-

a) Arithmetic b) Logical c) Load and store d) Input and output e) Control or branch

with five different addressing methods

a) Immediate b) Direct c) Indirect d) Indexed e) Indirect-indexed

The slight differences from the students' normal text would provide the pupils with the necessary experience of different

PAGE 28 instruction sets which are often encountered in examination work. Here a new instruction set is defined in the examination paper for use in a particular question.

Instruction set for SIMPLE

FUNCTI ON CODE MNEMONIC ACTION Dec. Oct. Basic Bit 11 =0 =1 0 00 HLT Halt processor I 01 LDA Load ace. from memory 2 02 STA Store (acc) in memory 3 03 TRG TAX TXA Transfer X:=(acc) or acc:=(X) 4 04 ADD Add (mem) to (acc) 5 05 ADN Add number to (acc) 6 06 SUB Subtract (mem) from ( ace) 7 07 DCR DCA DCX Decrement (acc) or (X) 8 10 AND Logical AND (mem) with (acc) 9 11 ORA Logical OR (mem) with (ac c) 10 12 LSH LSL LSR Logical sh i ft of (acc) I eftlri ght 11 13 ASH ASL ASR Arith. shi ft of (acc) 1 eftlri ght 12 14 lOP INP OUT Input/output via ace. 13 15 JUN Jump unconditional 14 16 JZR Jump if ( ace) is zero 15 17 JNG Jump if (acc) is negative

The internal format of the 16-bit instructions would be:­ OOOOIXAAAAAAAAAA where 0000 is the four bit basic operation code ( i. e. 12I1121121=ADD> I is the indirect bit X is the index bit AAAAAAAAAA is the operand, usually an address.

Full details of each instruction are provided in the appendix.

PAGE 29 Numbers are stored as 2's complement 16-bit numbers.

Making the HLT instruction have the operation code 0000 was intentional as small positive numbers accidentally placed in the middle of a program would be interpreted as a HLT command bringing the execution quickly to an end.

Once the decisions on the instruction set had been taken it was necessary to begin work on the design of the program. Important considerations here were the design of the user interface, the facilities to be provided and the major problem of getting the program into the small memory of a BBC computer.

PAGE 30 4.2 THE USER INTERFACE

The student has to communicate with the simulation and the simulation has to feedback information to the student. This two way communication can be undertaken in two basically different forms.

The first method is to use a series of menus offering choices to the student at different points in the program. The menus can differ if some decisions have already been taken by the student. For example the menus in ENGINE change if the printer option has been set on or off. (See page 21.) A menu driven user interface has some advantages:-

a) Reduced options are available to the student. Only those options which are possible because of previous actions need be offered. This reduces the effort on the part of the student in deciding what to do next and gives a feeling of confidence during the initial stages of using the package as he/she is not overwhelmed with apparently possible options.

b) Single key entry of choice is quick and simple.

However, there are some drawbacks with a menu driven system.

a) It is often necessary to repeat a series of menus to repeat an action or to change just one parameter. This can become boring and distracting to the student.

b) There can be a lack of flexibility in the use of the software if a particular series of operations have not been foreseen and catered for by the program designer.

PAGE 31 The alternative is to use a command driven system. This gives the following advantages:-

a) All facilities are available to the user at all times. This includes some routes through the available facilities not thought of by the program designer.

b) Extensive help facilities can be provided which the user can call up at any time, often without disturbing the current state of the program and leaving the display intact. (This is possible on some systems with plenty of memory such as the Apple Macintosh or with a machine supporting the GEM environment. The BBC does not have sufficient memory to do this with internal memory and disc storage of the screen data would be very slow.)

The main disadvantages of the command driven system are:-

a) The user new to a particular program can be overwhelmed with the available choice provided at the command prompt.

b) Time can be wasted getting to know the commands available before use is made of the facilities provided.

Since this simUlation program is to be used by students studying for 'A' level Computer Science it can be assumed that they should already have some knowledge and experience of command driven software and are suffiCiently computer literate to be able to quickly use the help facilities provided within the system.

PAGE 32 Once the decision to make the program command driven had been taken it was necessary to compile the list of commands which were to be made available. These can be divided into two main groups:-

al Those to do with actually running the simulation. ASSEMBLE, DISASSEMBLE, EDIT, EXECUTE, LOAD and SAVE fall into this category.

bl Those providing help and information backup to the system. COMMANDS, FINISH, HELP, SPEED, VALUES, EXPLAIN and * are included here.

Only the first three letters of the command are needed for it to be correctly identified. This can speed up the entry of commands.

PAGE 33 ,.

-** Message window **-

STR ItfPlJT I I '-1-1 _--,1 1r=-=8=[)=R_-,I.·.·..· .•. ·.·.·.·.·.·.·.·.·.·tr=...:::.C=R_-, L...... ,,..:..::.8:=C C::.-.:....,I.:, I!

- P • 1 i 11 G:4l1 j j i I ! 'l:!:.!.r' i OUTPUT :! X ! I i 1 I ... 1 ! L "':"::'---'--, j i L...... 1 I I i l '····i::::::::::::::::JI~i··~I·ww····r·! M[)R I r"'I' . I !! MRR L----.----II L .. II....._,....---' ttlEMORY i .·.·.·.·.·.·.·.·.·.·.··.·.·.·.·.·1 1· .. ·············..·..············.1

-** COMMand & help window **- 4.3 SCREEN DISPLAY

The design of the screen layout was the next task to be undertaken. It was decided to split the display area into three separate windows.

The lower window was to be the command window with ':' used as the command prompt. (This has long been adopted by the AUCBE in Hatfield as their command prompt and my students would be familiar with software from AUCBE. It appeared to add an unnecessary confusion to change the prompt character.) The <:> key would also be used as a system interrupt signal to break into the current action with less disruption than pressing the key. The <:> will abort any line being entered and interrupt execution of a user program. Other actions are usually so rapid that the interruption facility was thought to be unnecessary beyond aborting any built in delays which might be present. HELP messages would also be displayed in this lower window so that the rest of the display would not be disturbed. Four screen lines would be needed for the help messages if they were kept quite short.

Message window - 4 lines

Graphics window

Command + Help window - 4 lines

PAGE 34 The upper window would be used for any necessary input of information for the simulation and for the display of a commentary while executing a student program in the simulation. Four screen lines were calculated to be sufficient for this task.

The large central window would be the graphical display area showing the internal registers of the simulated machine. Colours for the display and the size of the characters used are very important. Three different sizes of characters are available on the BBC computer providing 20, 40 or 80 characters per line. The largest characters are too large to be read easily and do not allow enough information to be shown on the screen at one time. The smallest characters allow a great deal of information to be displayed but on a colour monitor are very difficult to read. With the 80 character per line character size only two colours are available, one background and the other foreground. This meant that the 40 character per line character size would be the best size and is provided in three different ways.

Mode 7 is the teletext mode allowing the full range of colours, taking up very little of the available memory in a standard machine but not allowing true graphiCS, only the divided character blocks. This mode was considered for some time as it held the advantage of allowing the program to be run on a standard BBC computer. The main problem was found to be that of providing boxes to designate the registers and the representation of movement along lines joining the register boxes to indicate the passage of data from one register to another. The boxes and lines would be large and the more complicated programming needed to implement the required graphics in mode 7 would add greatly to the program length and slow down the simulation too much. It was finally decided to use the mode 1 screen with its four available colours and fast, simple graphics for the display.

PAGE 35 Mode 4 uses 10K of memory and has 40 characters per line but only has two colours available. This would not be enough for graphics window so mode 4 was rejected.

The four default colours available in mode 1 are black, red, yellow and white. Red on a black background is very dim and difficult to read especially on a monochrome screen. Although a less intense colour was needed to show data buses not carrying data it was found that blue was better for this task than red. Yellow, of middle intensity, was ideal for drawing the register boxes and for showing data buses carrying data between registers. Blue and yellow are complementary colours which helps make the change from yellow to blue and back again stand out even more. White would be used for the main text and contents of registers.

The main problem with mode 1 is that it uses 20K of memory to support the screen display. The decision to adopt the mode 1 display meant that it would not be possible to run this simulation on a standard BBC computer. Shadow RAM would be needed to support the screen so that sufficient memory would remain for the program, which was expected to be quite long. BBC B+128K and MASTER computers have suitable shadow RAM and several of the computers at my college have been upgraded with Solidisk sideways RAM boards which support shadow screens.

The registers to be displayed were then selected. A choice then had to be made about the base to be used to display the contents of the registers within the boxes. Binary would make the recognition of instructions quite simple and would be ideal when watching the action of shift instructions but identification of addresses might be difficult. The 16-bit numbers would make the boxes representing the registers rather long. Denary display would not allow instructions to be recognised easily nor the action of shifts to be noticed. Octal and hexadecimal would provide a compact display. Octal

PAGE 36 was eventually decided upon because it was found to be more easily understood and converted to denary than hexadecimal.

Various arrangements of the registers within the display window were tried and the necessary data bus lines drawn until an uncluttered display was produced.

It was thought that the conversion to octal as each register was updated on screen might slow down the simulation so a short 6502 machine code routine was written to carry out this task. It is assembled at the beginning of the program rather than loaded from a disc file as the memory maps of the various machines are different making the latter and preferred approach too complicated. I Birnbaum (1982), W Barden (1977) and J Ferguson & T Shaw (1983) were useful texts on programming in 6502 machine code.

Memory constraints where known to be a problem even when using shadow SCreen RAM. To help save valuable memory it was decided to store essential data for the HELP messages and screen display on data files. The former would be on a random access file so that the displays late in the file could be accessed at the same speed as those at the start. The screen data would be read into arrays at the beginning of the program and so be instantly available whenever required but not held in duplicate in DATA statements wasting memory.

As memory requirements were still likely to be a problem the assembler was to be written as a separate program which could be executed on its own or called from the main simulation as required. A return route to the main program from the assembler would also be provided.

At this stage the robustness of the program was considered. The users would be computer literate and would understand the need not to press the key. The key was trapped and the documentation pointed out that the <:> interrupt route would be more useful. The input routines were

PAGE 37 designed with great care to over come possible problems with data entry. INPUT and GET statements were excluded from the main program and all inputs requiring specific values were obtained from the input procedures (PROCin and PROCin2) with the following features:-

The CAPS LOCK is forced on at the beginning of the routine with *FX202,32.

The input buffer is flushed at the start of the routine with *FX 21,0.

The position of the start of the input field on the screen is recorded.

Characters are obtained from the keyboard with GET$, even if numeric values were expected/required, to prevent type errors.

Each character is checked to make sure it is in upper case, in case the CAPS LOCK has been turned off, and corrected if necessary.

Control characters are ignored.

If the <:> key is pressed the input is cleared and the routine restarted.

If is pressed a check is made to ensure that a character has been entered before it is deleted. This prevents the repeated pressing of the delete key from destroying the screen display.

will only terminate the input routine if at least one valid character has been entered. This prevents system errors in other parts of the program such as attempting a open a file with a null file-name.

PAGE 3R The string supplied by the input routine is converted to a number if necessary using the GETNUMB procedure which allows numbers to be in any of four bases, binary if starting with 7., octal if starting with @, hexadecimal if starting with & or $, or denary. Only positive denary numbers are allowed and negative numbers have to be entered in 16-bit 2's complement. Invalid numbers generate an error message and entry is requested again.

Pressing gives the user the opportunity of ending the program or re-starting the simulation.

930 DEFPROCin 940 *FX202,32 950 LOCALp,ch$,ch 960 in$= .... :p=POS:*FX21,0 970 REPEAT 980 ch$=GET$: ch=ASC (ch$) 990 IF ch>96 THEN ch=ch AND&DF 1000 IF ch<32 OR ch>127 THEN 1050 1010 IFch>96 AND ch<123 THEN ch$=CHR$(ch-32) 1020 IFch$=":" THEN CLS:PRINT":";:GOT0960 1030 IF POS>p OR ch<>95 THEN PRINTch$; 1040 IF ch=95 AND LEN(in$»0 THEN in$=LEFT$(in$,LEN(in$)-l) ELSE IF ch<>95 in$=in$+CHR$(ch) 1050 UNTIL ASC(ch$)=13 AND LEN(in$)>0 1060 VDU26 107121 ENDPROC

PAGE 39 4.4 THE STORAGE OF THE USER'S PROGRAM

Memory had to be found for the student's lb-bit machine-code program. At least 4K bytes would been needed to allow the lb-bit program to have access to memory outside the direct addressing range. Various places were considered.

a) An array in normal memory. This was rejected at once as being too wasteful of valuable memory.

b) Storage of the user's machine code program in a random access disc file was considered next. This would be possible but there would be timing differences as the program passed over disc sector boundaries which might not be acceptable.

c) Use another bank of sideways RAM (SWRAM). This would provide lbK bytes or BK of lb-bit words which was more than enough. It would be quickly accessible at the same speed for all locations and left the maximum amount of normal memory for the program.

SWRAM was the chosen solution but this brought in a series of additional problems. Even the standard Acorn machines with SWRAM were different internally with RAM available in different banks. Solidisk was different again and had the addition problem of a different operating system providing access to the SWRAM banks. It was necessary for the program to identify which machine it was running in and then to use the correct method of accessing SWRAM in the correct RAM bank in that machine. The machine identification can be carried out by identification of the operating system by a call to &FFF4 (OSBYTE) with A'l.=0 and X'l.=l (equivalent to *FX0). This is carried out by the function FNos, listed on the following page.

PAGE 40 332111 DEFFNos 333111 REM Find 05 to identify machine 334111 REM 0=051.111: 1=051.2 2=052.0 335111 A%=0:X%=1 3360 =(U5R(&FFF4) AND&FF00)DIV&100

PAGE 41 4.5 THE ASSEMBLER PROGRAM

An assembler needs a text ~ile containing the source program as data. Since most school BBC computers are fitted with a word processor chip, the students could be expected to be familiar with the ~itted system so it was decided to make use o~ this firmware to provide the source ~ile. (EDWORD is not really suitable as it stores its text backwards and this needs converting before it can be used. WORDWISE, WORDW I SE-PLUS , VIEW and INTER-WORD have all been tried successfully but the last two have to have the default rulers adjusted so that there is no le~t-hand margin.) The output is then spooled to the disc rather than saved.

For simplicity a ~ixed format o~ three ~ields for the source

~ile was decided on, without comments. Since students would only be using the simulator for a short time these restrictions would help keep the assembler as simple as possible and so help to reduce mistakes due to typing errors. Comments could be kept on the form the program was written on before being keyed.

The format is LLLLLL OOOIX operand. The labels can be up to six characters in length starting in position 1, the operation mnemonic must begin in position 8 and the operand, label or number, in position 14.

It is a two pass assembler with the ~irst pass just used to resolve the labels. The pseudo operation codes VAR and CON are used to de~ine the locations of variables and constants.

The same input routine is used as in the main simulator program.

PAGE 42 4.6 PROCEDURES AND FUNCTIONS IN SIMPLE

The large number of procedures and functions making up this program and the calling of one procedure by several other procedures or functions means that a diagram showing the calls is very complicated and difficult to follow. This is especially so when the diagram is typed on A4 paper.) To overcome this problem I have grouped the procedures and functions into their appropriate levels. and for each one I have listed the procedures they call. with the level of the called routine. This allows an easy check to be made that no routine calls one at a higher, or equal level.

LEVEL 0 Procedures called Main program init(1) title(1) comin(l) inside(4)

LEVEL 1 init FNos(2) mcode(2) title exp2(3) comin in(2) star (2) twin(7) values(2) comds(2) exe(2) dis(2) edit(2) exp(2) speed (2) load(2) save (2) help(2) cwin(7)

LEVEL 2 FNos none mcode none star oscli(4) inside(4) cwin(7) dis firstlast(3) FNpull(5) octY.(7) decode(4) inside(4) cwin(7) values twin(7) comds twin(7) in none edit twin(7) in2(4) getnumb(4) delay(6) unpack (3) mes(6) push (3) exp exp2(3) inside(4) speed twin(7) in2(4) getnumb(4) delay(6) load twin(7) delay(6) push (4) cwin(7) save twin(7) firstlast(3) FNpull(5) cwin(7)

PAGE 43 help nohelp (3) exe twin(7) mes(6) in2(4) getnumb(4) delay(6) intrpt(3) trac:k(5) FNpull(5) wrtreg(6) trav(6) dec:ode(4) indirec:t(3) index(3) hlt(3) Ida(3) sta(3) trg(3) add(3) adn(3) sub(3) dc:r(3) and(3) ora(3) Ish(3) ash(3) iop(3) jun(3) jun(3) jzr(3) jng(3)

LEVEL 3 firstlast twin(7) in2(4) getnumb(4) delay(6) unpac:k FNpull(5) oc:tl.(7) binout(4) dec:ode(4) exp2 none nohelp none intrpt twin(7) mes(6) delay(6) indirec:t mes(6) doubletrac:k(4) fetc:hin(4) index mes(6) delay(6) wrtreg(6) hIt mes(6) lda mes(6) doubletrac:k(4) fetc:hit(4) trac:k(5) status (4) FNc:omp(4) delay(6) sta mes(6) doubletrac:k(4) trac:k(5) trav(6) push (4) twin(7) trg mes(6) trac:k(5) FNc:omp(4) status(4) add mes(6) doubletrac:k(4) fetc:hit(4) FNc:omp(4) trac:k(5) adn mes(6) FNc:omp(4) wrtreg(6) delay(6) status(4) sub mes(6) doubletrac:k(4) fetc:hit(4) FNc:omp(4) trav(6) status (4) dc:r mes(6) FNc:omp(4) wrtreg(6) status(4) inrange(5) and mes(6) doubletrac:k(4) fetc:hit(4) FNc:omp(4) trac:k(5) status(4) ora mes(6) doubletrac:k(4) fetc:hit(4) FNc:omp(4) trac:k(5) status(4) Ish FNc:omp(4) mes(6) delay(6) wrtreg(6) status(4) ash FNc:omp(4) mes(6) delay(6) wrtreg(6) status (4) iop twin(7) in2(4) getnumb(4) delay(6) wrtreg(6) mes(6) trac:k(5) status(4) jun mes(6) adrtosc:r(4) delay(6) twin(7)

PAGE 44 jzr mes(6) adrtoscr(4) delay(6) twin(7) jng mes(6) adrtoscr(4) delay(6) twin(7)

LEVEL 4 inside box (5) binout none push oscli(5) decode extra(5) getnumber oct(5) hex(5) bib(5) dec(5) in2 none fetchit mes(6) track(5) FNpull(5) wrtreg(6) FNcomp none doubletrack trav(6) wrtreg(6) status wrtstat (5) adrtoscr mes(6) track(5)

LEVEL 5 box none oscli none extra none oct none hex none dec none bin none FNpull none wrtstat none track trav(6) wrtreg(6) delay(6) inrange twin(7)

LEVEL 6 mes cwin wrtreg none tray xline(7) yline(7) delay none

PAGE 45 LEVEL 7 cwin none twin none oc:t'l. none xline none yline none

PAGE 46 PROCEDURES AND FUNCTIONS IN ASSEMBL

LEVEL '" Procedures called Main program init(1) in2(1) cat(1) pass1(1) pass2(1)

LEVEL 1 init none in2 none cat none pass1 line(2) scrset(2) find(2) FNchop(2) label1(2) label2(2) getnumb(3) pass2 line(2) scrset(2) find(2) FNlookup(2) binout(2) getnumb(3)

LEVEL 2 line none scrset getnumb(3) FNchop none find none FNlookup none binout none label1 none label2 none

LEVEL 3 getnumb oct(4) hex(4) bin(4) dec(4)

LEVEL 4 hex none bin none oct none dec none

Full listings of the programs forming the simulator appear in the appendices.

p~r,1= 47 Chapter 5 - Using SIMPLE and the results of testing

If any educational program is to be used effectively the user must have access to information giving full details of the system. Such documentation often has to be divided into two, slightly overlapping, parts. The teacher needs to know the educational aims of the package, the target group of students, the necessary hardware, user documentation and a guide to a least one suggested method of using the package. The student needs full user documentation and possibly a series of guided examples or exercises.

The documentation for SIMPLE was developed using this model. The teachers' notes, which appear in full in appendix 2, consist of the following sections:

1. Educational aims 2. Target students 3. Necessary hardware 4. Description of the simulation 5. Full details of the instruction set 6. Full details of the commands 7. Description of the assembler and its use

The students' guide, shown in full in the appendix, consists of a series of exercises and details of the instruction set and commands.

Four student exercises are provided. It was expected that each exercise would take about two hours of practical programming time. The exercises cover the following topics:

PAGE 48 1. Introduction to the system.

The instruction set in both binary machine code and mnemonics. The names of the registers used in the simulation and their purposes. Using the commands. The EDIT command for entry of a machine code program. Using the DISASSEMBLER - a program which translates machine code back to mnemonic code. Saving a machine code program. Execution of a machine code program at different speeds.

2. Using the Assembler.

Writing a program in assembler. Producing the source file with a word processor. Using Labels and loops in a program. Using the assembler to produce the object code file. Loading and executing the object file. A comparison of the source file with a disassembly listing of a program.

3. Different addressing methods.

Direct, immediate, indexed and indirect addressing and their uses. Exercises the the use of each addressing method.

4. Using subroutines

The method employed in SIMPLE and and exercise in its use.

PAGE 49 Although the documentation supplied to the students is the same as that supplied to the teacher it is not expected that students will be able to work through the work sheets without help from the teacher. Various methods of working can be employed by the teacher depending on many factors including:

Normal methods of working practical sessions in the institution. The length of practical sessions. Whether the simulation is being used for initial teaching of the topic or for revision purposes. Amount of suitable hardware available to the group.

Such decisions should be made by the teacher and not proscribed by the software provider.

5.1 TESTING THE SIMPLE PACKAGE

As SIMPLE was being developed each command was tested as it was completed by the programmer. Such testing can only give a rough indication that the command functioned correctly because it could-be expected that the writer would known how the command was supposed to work and would supply parameters in the correct order and within suitable ranges. Once the whole simulation appeared to be working correctly I gave it to a group of willing sixth formers in my college who are competent a-bit machine code programmers in 6502 code. I asked them follow the technical documentation as supplied to the teacherand use the simulation to produce a few programs of their own. I told they that I was particularly interested in the details of any bugs they found and asked for suggestions for improvements.

This group where working on an earlier version of the program than is listed in appendix 5 and appears on the disc and they made the suggestion of the single step execution mode, SPEED 0. Another student suggested an improvement to the input routine. Although the CAPS LOCK was turned on at the beginning

PAGE 50 of an input sequence it was possible to the turn it off during the routine. He suggested that all alphabetic entries be checked that they were in upper case and be forced into upper case if not.

No major bugs were discovered at this stage.

The third stage of testing is far the hardest, especially when the package involved is for the 'A' level student. Fewer schools teach the subject and have fewer students at the right stage of development to make use of the package. Institutions which might make use of the package may not be at the correct point in their teaching to be able to include the package at short notice in their teaching, while others may have taught the topic earlier.

After an extensive search for colleagues who would trial the package in schools or colleges I found six who where willing to try the material. I produced a questionnaire, given in full in the appendix, to high-light my areas of concern over the package. Participating institutions were issued with a disc containing the software for both ENGINE and SIMPLE, text files of all the documentation (for the production of extra copies if needed), printed copies of the the notes for teachers, and exercises/notes for students. These were distributed at the beginning of October with a request that the questionnaire be returned in the middle of November. Telephone numbers and addresses for my home and school where provided for contact in case of problems or difficulty. All the teachers involved in the trial were told of my own deadline with this project and appeared quite willing to participate.

I knew that to test the package thoroughly would be quite time consuming but I had been assured that this posed no problem.

None of the schools contacted me with a problem and at the beginning of November I rang each of the schools in turn to see how the trial was proceeding. Three teachers stated that

PAGE 51 'pressure of work' had so far prevented them in making a start on the trial and that they thought they would be unable to provide any information before the end of the year. The others had just looked over the documenation and/or checked that it would load on their equipment but had not made further progress. I emphasised the urgency of the situation and of my deadline and they agreed 'to get something off to you as soon as possible'.

The replies arrived in the middle of December after a further round of requests.

Only one of the trial institutions had used the material as suggested with a group new to the topic at 'A' level. They others had used it for revision with 'A' level students or as in introduction with GCSE students.

The useful feedback from the trial institutions consisted of the following:-

1. No major bugs were found. The only programming problem reported was by a user with a network and second processor. He was unable to make use of the HELP facility on the newtwork because the help messages are held in a random access file. (This was for speed of access as explained earlier.) A Network version of the program with the help messages held in a serially accessed file would be easy to produce but would be slower. The second processor is not needed and should be turned off. This needs to be added to the teachers' documentation in the hardware section.

2. Suggested improvements included a quick reference guide and the inclusion of a simple text editor for the production of the source file. Both useful ideas to be included in the next development round.

PAGE 52 3. It would appear that the teachers involved in the trial relied heavily on the student material and provided little direct teaching about the simulator. They expected to students to pick up both how to use the package and the knowledge about the topic with little help from the teacher. This is asking rather too much of the students. It would appear that a class demonstration of the package to show the facilities to be used is necessary before letting the students attempt the exercises.

Some confusion was reported by teachers who used the package for revision. The confusion arose over the names used for the registers. Since several of the teachers used their own notes/handouts when originally teaching the topic modification appears to be a simple matter. I still feel that 'A' level students will need to be prepared for slightly different instruction sets and register names before sitting their final examination.

4. Students at the GCSE level found the simulation too difficult. as was expected. Perhaps they would have been better employed in making use of ENGINE. which was also supplied.

5. The results of the trial indicate that teachers seldom read the documentation provided carefully enough. Many of the points raised in the replies and reports of using the package where covered in the documentation provided. From some of the replies I suspect that the teacher involved had not tried out the package before using in class. With an involved simulation such as this I feel that it would be essential for the teacher to be familiar with the working of the package. its commands the instruction set and the addressing modes. before attempting to use the package with students.

PAGE 53 6. Several schools said that they would use the package again, perhaps in a slightly different way, so it would appear to be of some use in its educational aims.

PAGE 54 CHAPTER 6 - Conclusions

Specific reommendations

As a result of the pilot testing of this simulation the following recpmmendations emerge:

The program should be added to be the inclusion of a small text editor to help in the production of source files. This would overcome the need to exit the simulation and use a word processor for this task.

A network version of the program should be produced.

Teachers should be encouraged to read the documentation carefully and use the package themselves before attempting its use with a class.

The simulation should be demonstrated to a class before they are expected to USe it.

The package should not normally be used with students at GCSE level.

General recommendations

In comparing the development of ENGINE which came out of the working together of a small group of teachers over a long period of time and the development of SIMPLE which was a more solitary activity over a shorter time span they following recommendations came forth:

It is more useful to involve a small group of like minded teachers in the project from the start than to attempt to develop a software package in isolation. Many of the problems can be discussed and removed before the coding begins and all the teachers involved in the trial will feel involved in the project and prepare for it more carefully. They know that

PAGE 55 their feedback will be valued and incorporated in future versions if found to coincide with the views of others.

The development of useful eduational software needs more than a single trial period. The package needs to be maintained through several development cycles before it can be considered finished. SIMPLE has as yet only gone round the cycle once.

PAGE 56 BIBLIOGRAPHY

ACORN COMPUTERS (1986) Master Series Reference manual parts 1 & 2: Cambridge,

ACORN CES (1986) Master Series Welcome Guide, issue 2: Cambridge, Acorn Computers

ALEXANDER K & BLANCHARD D (1985) Educational software a creator's handbook: Loughborough, Tecmedia

ANGELL I 0 & JONES B J (1983) Advanced Graphics with the Model B Microcomputer: London, Macmillan Press

ATHERTON R (1983) Structured Programming with BBC Basic: Chichester, Ellis Horwood

BARDEN W (1977) How to Program Microcomputers: Indianapolis, Howard W Sams & Co

BIRNBAUM I (1982) Assembly Language Programming for the BBC Microcomputer: London, Macmillan Press

BISHOP P (1982) [SMITH C (1982) editor] Microcomputers in Education: Chichester, Elllis Horwood

BISHOP P (1982) Computing Science: Walton-on-Thames, Nelson

BISHOP P (1983) IMC-2 Simulation System: London, Edward Arnold

BISHOP P (1987) Advanced Computer Science: London, Pan Books

BORK A (1985) Personal Computers for Education: New York, Harper & Row

PAGE 57 BRAY A C, DICKENS A C & HOLMES M A (1983) The Advanced User Guide for the BBC Microcomputer, Cambridge, Cambridge Microcomputer Centre

COLL J (1982) BBC Microcomputer User Guide: London, British Broadcasting Corporation

COLL J & MYERS A (1985) Wordwise Plus Reference Manual 2nd ed: Computer Concepts

CRYER N, PRYER P & CRYER A (1983) Graphics on the BBC Microcomputer: London, Prentice/Hall

DOBSON T (1982) Peeko-Computer: Cambridge, Acornsoft

DUNN Sand MORGAN V (1987) The Impact of the Computer on Education: London, Prentice/Hall

FERGUSON J & SHAW T (1983) Assembly Language Programming on the BBC Micro: London, Addison-Wesley

FRENCH C S (1984) Computer Science - 2nd edition: Eastleigh, D P Publications

GORDON JH (1978) editor Beginner's Mini Computer - Teacher's Manual: Hatfield, AUCBE

HEAFORD J M (1983) Myth of the Learning Machine: Wilmslow, Sigma Technical Press KELLER A (1987) When Machines Teach: New York, Harper & Row

McGREGOR J & WATT A (1983) Advanced programming Techniques for the BBC Micro: London, Addison-Wesley

MONSON C C, SEWELL I R & VICKERS (1978) Computer Studies Book 1: Reading, ICL Computer Education in Schools

PAGE 58 MONSON C C, SEWELL I R & VICKERS (1979) Computer Studies Book 2: Reading, ICL Computer Education in Schools

MOONEN J & TJEERD P (1987) eurit 86 - Developments in educational software and courseware: Oxford, Pergamon Press

O'SHEA T & SELF S (1983) Learning and Teaching with Computers: Brighton, The Harvester Press

PALMER D C & MORRIS BD (1980) Computing Science: London, Edward Arnold

ROSEN A (1978) Beginners's Mini Computer - Student text: Hatfield, AUCBE

SOLIDISK TECHNOLOGY (1986) The Solidisk Twomeg and Fourmeg RAM/ROM Expansions: Southend-on-Sea, Solidisk Technology Ltd

PAGE 59 APPENDICES

Notes about the appendices 61 1 Documentation for ENGINE 62 1.1 Using the simulation 62 1.2 Sample run 64 1.3 Eduational aims and specification 68 2 Teachers' notes for SIMPLE 74 2.1 Educational aims 74 2.2 The simulation 76 2.3 The instruction set 78 2.4 Commands 83 2.5 The assembler 87 2.6 Example programs 89 3 Students' documentation for SIMPLE 93 4 Testers' report form 11115 5 Listing of SIMPLE 11119 6 Listing of ASSEMBL 133 7 Listing of MAKfil7 142 8 Listing of MAKhel8 144

Page 6111 Some sections of the appendix, mainly dealing with program documentation, are almost identical to parts of the main report. They are included in the appendix because it was in this form that documentation for the programs was supplied to testers in the trial schools and future users of the program will be supplied with these notes rather than the report.

The three sections of the teachers' notes on the instruction set, the commands and the assembler were also given in the original students' documentation but have not been repeated again in the appendix.

On the second side of the disc are the WORDWISE-PLUS files needed to print this entire report and appendices and may be used to produce class sets of student notes.

Page 61 ENGINE - a simple computer simulation - Documentation

Al.l USING THE SIMULATION

On running the simulator the ENGINE title appears and the size of memory simulated is displayed (110 locations in this version). The user is asked for a program title. This can be just a simple program name but can also include the author's name. This string of characters will be printed out at the top of printed runs and listings and the name is useful if printers are shared between several users. (Typing DISK-IN takes the user directly to the disc I/O prompt.)

A ? prompt appears after the number 10. This means that the simulator is ready to receive an instruction for location 10. At this point the user can type in a mnemonic instruction, a constant (preceded by +, or =) or a directive to change the location. The user types in a suitable response and the location pointer increments to the next location. Faulty responses are not accepted and a short error message appears. Once a program has ben entered the directive (EXECUTE n) is issued. The n is the location of the first instruction to be executed. Pressing ! or ESCAPE while entering a program takes the user directly to the main program menu.

The execution of the user program begins with the Trace? prompt. If the user replies with a 'Y' then the type of trace required is requested. The 'FETCH/EXECUTE' trace is obtained by pressing 'F' or 'E' and the 'RECORD' trace selected with 'R'. The former executes the program at a user selected speed, even the ~astest of which is much slower than an untraced run, while displaying registers within the machine through a 'glass-top'. Its main function is to aid the understanding of the fetch/execute cycle. A record trace displays the changes

PAGE 62 to lo~ations and registers with the ~omputer during the run and ~an be useful in debugging programs.

At the end of a run the user is presented with a menu allowing programs to be saved or loaded from dis~, allowing the printer to be swit~hed on or off, allowing a lo~ation in memory to the edited, a listing of the program obtained, the entry of a new program or end of the simulation. (The final option is not a total disaster if pressed by a~~ident as 'GOTO 1000' typed immediately will return the user to the main menu with the internal user ~ode inta~t.)

PAGE 63 A 1.2 SAMPLE RUN

BBC ENGINE

MNEMONIC CODE SIMULATOR.

Number of storage locations is 110

Program title ?Eval xA2-7x+1 when x)=0

10 ?(STORE 20) 20 ?+1 21 ?+7 22 ?RNA 23 ?JLT 34 24 ?STA 10 25 ?MLT 21 26 ?STA 11 27 ?LDA 10 28 ?MLT 10 29 ?SUB 11 30 ?ADD 20 31 ?WNA 32 ?WNL 2 33 ?JUN 22 34 ?STP 35 ?(EXE 22)

Trace ? N

PAGE 64 Eval xA2-7x+l when x>=0

Executing from 22

# 7 1

# 8 9

# 5 -9

# -2

STOP at 34 Tap SPACE for menu

MENU ====

Press:

L for LIST

R for RUN

C for CHANGE program.

P for Printer ON.

N for NEW program.

F when Finished.

D for Disk 110.

? L

PAGE 65 Eval :."2-7:.+1 when x)=12I

LIST

Tap SPACE to continue

Loc. Instr. Contents

1 -2 1121 5 11 35 # 2121 1 21 7 22 RNA 42121121121121 23 JLT 34 2512134121 24 STA 1121 161211121121 25 MLT 21 412121121 26 STA 11 1612111121 27 LDA 1121 11211121121 28 MLT 1121 41211121121 29 SUB 11 312111121 3121 ADD 2121 21212121121 31 WNA 43121121121111 32 WNL 2 461211212121 33 JUN 22 212111122121 34 STP 5121121121121121

Executes from 22

End of list

Tap SPACE for menu.

PAGE 66 (Second run from MENU) Trace ? Y Type: Fetch/Execute or Record (R Pressed)

Eval xA2-7x+1 when x>=0

Executing from 22

# 4

22 420000 acc= 4 EA= 0

23 250340 SCR=24 acc= 4 F

24 160100 locH!!= 4 EA=10

25 4021<1l acc=28 EA=21

26 160110 locll=28 EA=l1

27 10100 acc= 4 EA=10

28 40100 acc=16 EA=10

29 30110 acc=-12 EA=11

30 20200 acc=-l1 EA=20 -11

33 200220 SCR=22 acc=-11 # -5

22 420000 acc=-5 EA= 0

23 250340 SCR=34 acc=-5 T

STOP at 34

PAGE 67 A 1.3 Educational aims and specification for ENGINE

ENGINE was originally developed to provide a simple low level language to replace CG319 which had previously been used to teach about machine architecture and low level languages for CSE and '0' level students. Its original specification included:

1 The program should run on the microcomputers available within the schools of the CSE mode 3 Computer Studies group.

2 The program should use denary internal codes and addresses.

3 Programs should consist of mnemonic instructions which are checked for errors on entry.

4 The four floating-point arithmetic operations (+-*/) should be available so that real solutions could be obtained.

5 Character manipulation should be supported.

6 Control of output should be supported.

7 Indexed addressing should be supported.

8 Subroutines should be supported.

9 A trace facility should be available to aid the debugging of programs.

PAGE 68 10 Program listings showing internal codes should be available.

11 A memory editor facility would be useful for program debugging.

After prolonged discussion a language consisting of a subset of CG319 was found to be suitable with the following directives and instructions:

DIRECTIVES

(STORE n) sets the program pointer to a location in store for program entry.

(EXECUTE n) begins execution of a program at location n.

Only the initial letter following the first bracket is checked allowing short form directives of the type (S 25) to be used.

CONSTANTS

These must be preceded by a + or - for numeric constants and by = for character constants. Constants may be placed from location 10 upwards.

INSTRUCTION FORMAT

Instructions consist of an operation code. three upper-case letters. with an operand made up of an address in denary and an optional modifier - an index register. i.e. ADD 34 more generally 000 aAi

In the following definitions A is the accumulator and (A) indicates the contents of the accumulator. a is and address in the store and (a) is the contents of that

PAGE 69 store and i is an index register and (il is the contents of the register:

DATA MOVEMENT OPERATIONS

LDA aAi Load accumulator from store location specified. A:=(a+(ill

STA aAi Store a copy of the contents of accumulator in specified location. a+(i) :=(Al

ARITHMETIC OPERATIONS

ADD aAi Add the contents of specified location to contents of accumulator A:=(Al+(a+(ill

SUB aAi Subtract the contents of specified location from contents of accumulator A:=(Al-(a+(ill

MLT aAi Multiply the contents of accumulator by contents of specified location. A:=(Al*(a+(ill

DIV aAi Divide the contents of accumulator by contents of specified location. A:=(Al/(a+(i) l

PAGE 7121 INPUT/OUTPUT OPERATIONS

RNA Read number into accumul4tor. Prompt is #

WNA Write number in accumulator.

WNL n Write n new lines.

WSS n Write n spaces (i~ n=0 skip to next column.)

RCH Read character into accumulator. ASCII value of character left in accumulator. Prompt is C

WCH Write character from accumulator. (ASCII code conversion used.)

JUMPINSTRUCTIONS

JUN aAi Jump unconditionally to location specified.

JEQ aAi Jump i~ accumulator contents =0

JLT aAi Jump if accumulator contents <0

JSR aAi Jump to subroutine at specified location after having saved return address in location 2. Loc2 =(SCR) (Return from subroutine with JUN 0 A 2)

TERMINATOR STP Stop execution of program

SPECIAL LOCATIONS IN ENGINE

o Protected zero 1 Accumulator 2 subroutine return address 3 to 9 index registers 10 to 110 may hold instructions, data or constants.

PAGE 71 INDEX REGISTERS

Indexed addressing is carried out by modifying the instruction address

i.e. ADD 99~3 The effective address will be found by adding the contents of location 3 to 99.

Using ENGINE

I have been using the program with students in CSE, 'O'level, 16+ and GCSE classes for several years to help teach the fetch/execute cycle and to obtain experience of low level code. The use of denary addresses, internal operation codes and floating-point arithmetic makes it very useful for this age group.

I normally use the program when I am teaching machine architecture, machine code and low level languages. I explain the effects of the various instructions which are available and we develop a program to evaluate a simple formula, such as 3a+7b-2, as a class exercise. Discussion takes place on where the program, constants and variables will go in memory, how they will appear in memory and how the program can store a term already evaluated for later use. The program is then entered and executed without tracing to see if it produces the expected result. The record trace is then used to check what happens to the data as it is processed and finally the fetch/execute trace is used to follow how the machine moves from one instruction to the next using the sequence control register and show that memory contains just numbers which can be interpreted as numbers, instructions or even characters.

PAGE 72 After the students have tried a similar task on their own we move on to loops and decisions with the limited tests available to the programmer in this language. The students are then set the task of making the computer count up or down between two values input as data.

The final session deals with 'real machine code' with the difficulties of addresses and operation codes in binary, limited arithmetic instructions and dealing with negative numbers. Students readily appreciate the need for an assembler program and the extra facilities which may be provided such as error checking, and symbolic variable names.

PAGE 73 SIMPLE - a 16-bit computer simulation

TEACHER'S NOTES

A 2.1 EDUCATIONAL AIMS:

1. To enable students to execute low-level language programs so that they can have first hand experience of this type of programming and so develop a greater understanding of the difficulties involved.

2. To provide a means of demonstrating different addressing methods and to provide experiences of their use.

3. To provide a demonstration of what happens within the the CPU while a program is being executed. To demonstrate the FETCH/EXECUTE cycle and the functions of the various registers within the CPU.

4. To demonstrate the usefulness of subroutines and illustrate one simple method of their implementation.

5. To demonstrate the facilities provided by an ASSEMBLER and provide practice in its use. To illustrate the usefulness of an assembler in the preparation of machine code programs.

TARGET STUDENTS

This package was originally designed for 'A' level Computer Science students (16 - 19 years) who have written programs in a high-level language and are studying the section of the syllabus on machine architecture. Its use is to augment the study of a suitable text and to provide experience of programming at lower levels, assembler and machine code.

PAGE 74 NECESSARY HARDWARE

The package will run a BBC Master 128 computer, a BBC B+ 128 or a BBC computer fitted with Sideways RAM to provide SHADOW screen memory and a 16K SWRAM bank. (It was developed on a Solidisk 256K RAM extension to a BBC computer.) A disc drive and wordprocessor or text editor are essential for the production of source files for the assembler, and access to a printer is useful.

If a printer is to be used the teacher should adjust the *FX commands in the MENU program on the disc to the normal settings. (The supplied settings are for a serial interface at 4800 baud with the ignore character being LF [10]).

This document is supplied in a Wordwise-Plus file called W.SIMDOC so that extra copies can easily be generated if required.

The disc is auto-booting with

PAGE 75 A 2.2 THE SIMULATION

The program simulates a small 16-bit computer with 8192 words of memory addressed from 0 to 8191. Each location can hold either an instruction or a data item. The format of an instruction is as follows:-

FFFFIXAAAAAAAAAA

Where F is function code I is indirection bit (or function extension) X is index bit and A is address.

Since 10 bits are used to specify an address only the locations 0 to 1023 may be addressed directly. The other locations can be accessed by indirect and indexed addressing.

With indirect addressing the address part of the instruction points to a location in memory. The contents of this location are used as the effective address when the instruction is executed allowing access to the full range of 16-bit addresses.

With indexed addressing the contents of the index register are added to the address part of the instruction to form the effective address for instruction execution.

If both indirect and indexed addressing are specified then the contents of the index register are added to the contents of the address part of the instruction to form the effective address.

PAGE 76 A term in brackets indicates the contents of this address or register.

Direct addressing: LDA ADDR Address used is ADDR

Indirect addressing: LDAI ADDR Address used is (ADDR)

Indexed addressing: LDAX ADDR Address used is ADDR+(xreg)

Indirect indexed addressing: LDAIX ADDR Address used is (ADDR)+(xreg)

This simulation uses one bank of sideways RAM in the BBC computer as its main memory and has only 8K words of main store.

PAGE 77 A 2.3 THE INSTRUCTION SET

(Here a ? indicates that the contents of the bit are irrelevant.)

o HLT 0000????????????

This instruction halts the processor. (It has the advantage that if an error in programming causes the simulator to attempt to execute data any small positive number will be interpreted as a HLT instruction.)

1 LDA 0001 IXAAAAAAAAAA

Load accumulator from memory. The contents of the accumulator will be overwritten by the contents of the specified location. Direct, indirect and indexed addressing are possible.

2 STA 0010IXAAAAAAAAAA

Store contents of accumulator in specified location in memory. This destroys the previous contents of this location. Direct, indirect and indexed addressing are possible.

3 Transfer between accumulator and index register. Two different transfers are possible depending on the value of the indirection bit.

TAX 00110??????????? (I clear)

Copy contents of accumulator into index register, overwriting its previous contents.

PAGE 78 TXA ~~111??????????? (I set)

Copy the contents of the index register into the accumulator, overwriting its previous contents.

The values of the index and address bits of the instruction can be anything.

4 ADD ~l~~1XAAAAAAAAAA

Add the contents of the specified location to the contents of the accumulator and store the result in the accumulator overwriting its previous contents. Direct, indirect and indexed addressing are possible.

5 ADN ~101VVVVVVVVVVVV

Add the value of the pseudo-address (0 to 4~95) to the contents of the accumulator and store result in the accumulator overwriting its previous contents.

6 SUB ~1011XAAAAAAAAAA

Subtract the contents of the specified location from the contents of the accumulator and store the result in the accumulator overwriting its previous contents. Direct, indirect and indexed addressing are possible.

PAGE 79 7 Decrement a register. (Reduce by 1)

This instruction will decrement either the accumulator or the index register depending on the value of the indirection bit.

DCA 01110??????????? (I clear)

Decrement the accumulator and overwrite previous contents.

DCX 01111??????????? (I set)

Decrement the index register and overwrite the previous contents.

8 AND 1000IXAAAAAAAAAA

Logical AND of the contents of the accumulator with the contents of the specified location. The result overwrites the previous contents of the accumulator. Direct, indirect and indexed addressing are possible.

9 ORA 1001 IXAAAAAAAAAA

Logical OR of the contents of the accumulator with the contents of the specified location. The result overwrites the previous contents of the accumulator. Direct, indirect and indexed addressing are possible.

PAGE 80 10 Logical shift of accumulator

The direction of the shift is given by the value of the indirection bit.

LSL 10100???????????

Logical shift left of the accumulator with a zero being inserted at the right, least significant bit.

LSR 10101???????????

Logical shift right of the accumulator with a zero being inserted at the left, most significant bit.

11 Arithmentic shift of accumulator

The direction of the shift is given by the value of the indirection bit. The sign (in twos complement convention) is preserved.

ASL 10110???????????

Arithmetical shift left of the accumulator with a zero being inserted at the right, least significant bit and the sign preserved.

ASR 10111??????????? (I set)

Arithmetical shift right of the accumulator with sign being preserved.

PAGE 81 12 Input/output

Input (clear) or output (set) is specified by the indirection bit. Input and output are both via the accumulator.

IN? 11000??????????? (I clear)

Input a value from the keyboard to the accumulator overwriting its previous contents. The value typed can be in Binary - starting with 7., Octal starting with @, Hexadecimal - starting with either $ or &, or Denary.

OUT 11001??????????? (I set)

Output the contents of the accumulator.

13 JUN 1101 IXAAAAAAAAAA

Unconditional jump to specified address. The SCR (sequence control register) is set to the specified address so that the next instruction to be fetched will be from this location.

14 JZR 1110IXAAAAAAAAAA

The jump if zero instruction only resets the SCR if the content of the accumulator is zero.

15 JNG 1111 IXAAAAAAAAAA

The jump if negative instruction only rests the SCR if the content of the accumulator is negative.

PAGE 82 A 2.4 COMMANDS

The program is command driven in the style of educational programs the Advisory Unit for Computer Education in Hatfield. The command window appears at the bottom of the screen with a colon as the prompt. The colon key can be used to wipe out a command entry line or to abort a long running command once it has begun. Commands are typed in upper case but only the first three characters are needed for the command to be recognised by the system. A list of the available commands is available from within the system by typing COMMANDS at the command prompt. The following commands are recognised by the system:-

ASSEMBLE ASS

This exits the simulation and loads the assembler program. It expects as input a file containing a source program produced with a word processor such as WORDWISE. The output is an OBJECT file which can be loaded into the simulator. After using the assembler the user is given the option of returning to the simulator program.

COMMANDS COM

This displays a list of all the commands recognised by the simulator. They appear in the upper window of the display.

DISASSEMBLE DIS

The user is asked for the first and last addresses of an area of memory and this is disassembled on screen with the option of printing.

PAGE 83 EDIT EDI

This command allows the user to look at the contents of a particular location in memory. Its contents are displayed in the upper window in binary and mnemonics. The user can then change the contents by typing in the new value in decimal, binary, octal or hexadecimal.

EXECUTE EXE

This runs the simulation. The user is asked for the location of the first instruction to be fetched. The simulation shows how data moves between registers within the computer with a commentary appearing in the upper window. The simulation may be stopped by pressing the colon key to interrupt the execution.

FINISH FIN

This terminates the program. Any user program will remain in SWRAM until overwritten. This allows the user to rerun the simulator and then save or disassemble a working program still in the simulator's memory.

HELP HEL

This command should be followed by a space and another command name. i.e. HELP EXECUTE. This will provide a short description of the command following the HELP in the upper window.

LOAD LOA

This command is used to load an object file into the simulator. It will display the locations it is filling in the top window as it loads the program. It is good practice to keep all all object files in directory O.

PAGE 84 SAVE SAV

This command will request the name of the file to which you want the program saved together with the start and finish locations. It is good practice to use directory 0 for such object files.

SPEED SPE

This will request a value of 0,1 or 2.

Speed 0 is very slow and is the single step mode. After each inter-register movement the simulation waits until is pressed. This allows the user to follow exactly what is happening inside the simulated computer.

Speed 1 is the default setting and shows all inter-register movements. It may be sightly too fast to follow in the early stages of using the simulator.

Speed 2 is the fastest setting. It is too fast to read the messages appearing in the upper window and has been provided to enable more experienced users to execute more difficult programs involving loops in a reasonable time. All changes in register values are displayed but line tracking is suppressed.

VALUES VAL

This displays the values of several system variables. The value of speed (0/1/2>, the name of the last file used and the starting and finishing locations are displayed in the upper window.

PAGE 85 * *

The characters following the * are passed to the MOS (machine operating system) of the BBC. This command was provided to allow the user to catalogue a disc or inform the computer of the printer type to be used via *FX commands. No error trapping has been provided and commands such as *COPY, *COMPACT will overwrite the simulator program.

PAGE 86 A 2.5 THE ASSEMBLER

The assembler is entered from the disc menu or the simulation with the command ASSEMBLE (or ASS in minimal form). The latter loads the assembler program but any instructions in the simulated computer's memory will be retained. At the end of an assembly run the user is given the opportunity of further assembly runs or a return to the main simulation program. Printer settings via the necessary *FX commands should have been set before entering the assembler. (Pressing while in the assembler offers the choice of a return to the simulator program or finishing.)

The assembler translates a source program of mnemonic instructions into the machine code of the simulated machine.

The source code for input to the assembler must be held in a text file. This is usually produced on a word processor such as WORDWISE or by an editor such as that resident in a BBC MASTER computer. If WORDWISE is used to produce the source file option 8, spool text, should be used rather than the more usual option 1, save entire text. No embedded commands should be used in preparing the source file. (It is good practice to spool source files to directory S i.e. use S.PROG1 as the file name, and use directory 0 for assembled files of object code. i.e. O.PROG1.)

The main output from the assembler is the object file but the user has the option of assembly listings and a symbol table on the printer. The object file can be loaded into the simulated computer's memory with the LOAD (LOA) command.

PREPARING THE SOURCE FILE

The assembler recognises two directives. Both are essential in all programs to be assembled. All source programs must start with the STORE directive of the form (STORE address)

PAGE 87 The address is that of the first location to be used as the program is translated and may be in Denary, Binary, Octal or Hexadecimal. The final directive is (END) and indicates the end of the source file. The directives must begin in the first position of their own lines. Only one STORE directive is allowed in a source file.

The format of the instructions within a mnemonic program must be as follows:-

LLLLLL OOOIX operand 12345678901234567890 Character positions

LLLLLL is an optional label of up to six alphabetic characters which must begin at position 1.

000 is the three letter operation code which must be in upper case and begin in position 8. It can also contain either VAR or CON to declare locations for variables or constants.

IX is the extension to the basic operation code to indicate indirect addressing (I) and/or indexed addressing (X). The I and X can be in either position. (i.e. ADD X 350 would be valid.) The I and/or X must be in positions 11 and 12.

The final field begins at position 14 and contains the operand. This can be a number (address or constant), a symbolic variable name or lable of up to six alphabetic characters. Numbers can be in one of several bases.

Base Example Denary 25 Binary 7.101010101101 Up to 16 bits Octal @165 Hexadecimal $F3 or &F3

PAGE 88 A 2.6 EXAMPLE PROGRAMS

1 Very simple - all direct addressing

(STORE 20) START LDA ONE ADD TWO STA THREE INP STA IN ADN 8

2 Harder with indirect and indexed addressing.

This program stores five numbers input from the keyboard in adjacent locations in memory using indirect and indexed addressing.

(STORE 10) LDA FIVE TAX LOOP TXA ,lZR FINISH INP STAIX BASE DCX ,lUN LOOP FINISH HLT FIVE CON 7.101 BASE CON @337 (END)

PAGE 89 When a source file is to be assembled the assembler requests the name of the source file. It then searches the current drive for the file and opens it for reading. If the file is not found the disc catalogue is displayed and the file name requested again.

The name of the object file is then requested and and opened for writing.

The user is asked if a printed listing is required. Entering 'V' will send output to the printer as well as the screen.

An example assembly run is shown below.

Name of SOURCEfile: S.LOOP

Name of OBJECTfile: O.LOOP Print (V/N) ? V

PASS 1 (STORE 1121) 1121 LDA FIVE 11 TAX 12 LOOP TXA 13 JZR FINISH 14 INP 15 STAIX BASE 16 DCX 17 JUN LOOP 18 FINISH HLT 19 FIVE CON 7.11211 2121 BASE CON @337 21 (END)

PAGE 9121 SYMBOL TABLE Symbol Location

FIVE 19

LOOP 12 FINISH 18 BASE 2111

PASS 2 1111 LDA FIVE

1111111111111111111111111111111111111111 11 TAX

11111111111111111111111111111111111111111111

12 LOOP TXA

111111111111111111111111111111111111111111 13 JZR FINISH

11111111111111111111111111111111111111 14 INP

11111111111111111111111111111111111111111111 15 STAIX BASE

11111111111111111111111111111111111111 16 DCX 1111111111111111111111111111111111111111 17 JUN LOOP 11111111111111111111111111111111111111 18 FINISHHLT

111111111111111111111111111111111111111111111111

19 FIVE CON 7.11111

11111111111111111111111111111111111111111111

2111 BASE CON @337

1111111111111111111111111111111111

Assembly complete - object file called O.LOOP

PAGE 91 A assemble another file R run simulator

Option (AIR) ? R

Loading simulator

The lb-bit binary numbers produced at the end of lines during the second pass are the simulated machine code produced by the assembler. They are stored in the object file for later loading into the simulator.

If the assembler is unable to assemble the source file and a fatal error is found in the source code then the object file is automatically deleted from the disc.

The source files S.LOOP and S.SR are included on the disc so that the user has easy access to suitable source files to practice using the the assembler.

PAGE 92 STUDENT EXERCISES WITH SIMPLE

Session 1 Introduction

1. Read through the list of instructions available with SIMPLE and ensure that you understand the purpose of the each of the six most significant bits. The following program will evaluate the expression x-2y+7 if the value for x in entered before the value for y.

INP STA X INP ASL STA TERM LDA X SUB TERM ADN 7 OUT HLT

Check that you understand how the program works, especially the use of the variable TERM and the action of the ASL instruction.

This program is written with the mnemonics of each instruction and uses symbolic variables. Before this program can be executed to must be translated into SIMPLE's internal machine code. In order to carry out this process we must first decide on where in the computer's memory the instructions are to be placed and where the variables are to be stored. If we use locations near to the bottom of memory we are likely to make fewer mistakes with the binary numbers. I suggest that the first instruction should be stored in location 10 and the

PAGE 93 variables be located below the program. ( i.e. X in location 8 and TERM in location 9, but choose your own locations if you prefer.)

The INP instruction is simple: 1100000000000000 in binary or 14000 in octal.

STA X will be 0010000000001000 if location 8 is used to store X.

Complete the coding of the rest of the program in binary and then convert some of the instructions to octal or hexadecimal.

The SIMPLE computer has been simulated on BBC computers. To run the simulation auto-boot the disc with

INPUT and OUTPUT are outside the main box surrounding SIMPLE and represent external devices for input/output.

ACC is the accumulator STR is the status register. At present only the two central bits have meaning. The more significant, bit 2, is set to 1 when the accumulator holds a negative number (in 2's complement), while the other, bit 1, is set if the accumulator contains zero.

X is the index register.

SCR is the sequence control register which plays a major part in program control. It usually points to the location from which the next instruction is to be fetched from memory.

PAGE 94 +1 represents circuits to increment the SCR.

ADR is the address register.

CIR is the current instruction register. MAR is the memory address register.

MDR is the memory data register.

MEMORY represents a window into the main store and showns the contents of the location that the MAR points to.

Above the diagram is a message window in which a commentary on the running of programs will be displayed and into which certain requested parameters will be entered. Below the diagram is the command window with the command prompt, a colon. Whenever the colon is displayed in the command window the simulation is waiting for a command. Typing COMMANDS, or just COM, will display all the available commands within the simulation. HELP followed by the first three letters of a command will provide some information about the command.

2. Using the computer activate the SIMPLE simulation and investigate the commands available. All inputs to SIMPLE must terminate with the key. If the colon key is pressed within an entry it wipes out the whole line. Pressing colon while a command is being carried out will terminate the command at a suitable point and activate the command window. should only be used if the colon fails as its effect is the abort the simulation. should never be pressed.

3. Issue the command EDIT and use it repeatedly to enter your program into the SIMPLE's memory. EDIT will display the current contents of the location in a variety of

PAGE 95 formats; in binary, octal, denary and in mnemonics. You will soon find some forms more useful than others. The new value can be entered in binary - preceded by 7., in octal - preceded by @, in hexadecimal - preceded by & or $, or in denary. (Remember key <:> will clear entry if a mistake is made.>

4. The command DISASSEMBLE can be used to check if your program has been entered correctly. The printer can be activated if required. Edit again to correct any mistakes before going on to the next stage.

5. Use the SAVE command to store a copy of your program on your disc. Call it 0.EX1. It may be reloaded at a later stage with the LOAD command.

6. Set the execution speed to 0 with the SPEED command. This will put the execution of your program into single step mode requiring the pressing of the key to precede to the next step at each stage of execution.

7. The command EXECUTE will ask for the location of your first instruction, give the option of printing I/O and then execute your code at the pre-set speed. Execute your program and follow the commentary at the top of the screen as it outlines the FETCH/EXECUTE cycle.

Set the speed to 2 and repeat the execution with data which should provide a negative result and notice the effect on the status register.

8. If locations 15, 16 and 17 contain the bit patterns 15: 0110000000010001 16: 0010000000010011 17: 0000000000000101 and the accumulator holds the octal value: 000017 describe all the steps in executing the program from location 15.

PAGE 96 STUDENT EXERCISES WITH SIMPLE

Session 2 Using the Assembler

The hand coding of machine code programs is time consuming and very prone to error. It is far quicker and more reliable to use the computer to carry out the translation process. A program called an ASSEMBLER is used. Such programs usually offer the ability to use symbolic variable names and labels to help cut out instruction counting. SIMPLE has an assembler made available with the command ASSEMBLE.

It requires as input the source text in a file. This may be produced with a text editor or word processor such as Wordwise. (If the latter is used the text should be SPOOLED to the disc with option 8 rather than saved with option 1.)

The format of the program within the source text file is very important or the assembler will not be able to translate it correctly.

The first line must be a store directive such as (STORE 10) to tell the assembler the start location of your program.

The operation codes must all begin in line position 8 and any operands (variable symbols, labelled addresses or constants) must start in line position 14.

The program must end with the directive (END) and a blank line.

PAGE 97 Below is an example program in the correct format.

(STORE 10) START INP STA X SUB FIVE JZR DONE LDA X ADD X OUT JUN START DONE HLT FIVE CON %101 X VAR (END)

The program stops when the value entered is 5, otherwise it outputs double the value.

It demonstrates how variables and constants are given locations, and how labels are used to indicate control jumps.

1. Use your text-editor or wordprocessor to produce a source file of this program for the assembler. Call it S.LOOPEX. The S directory indicates that it is a source file.

2. Enter the SIMPLE simulation and use the ASSEMBLE command to produce an object file called O.LOOPEX. The 0 directory indicating an object file which can be loaded into SIMPLE and executed.

3. Set SPEED to 0 and LOAD your object file. Execute the program and discover how the necessary jumps are implemented by the registers. When is bit 1 of the STR set?

PAGE 98 4. Write a program in SIMPLE code to input a number and output the number and the next two values greater than that entered. Store the code starting at location 25 and produce printed evidence of the assembly and the program executing correctly. Disassemble the code and compare it with the original. Which is easier to follow?

======

PAGE 99 STUDENT EXERCISES WITH SIMPLE

Session 3 Addressing methods

We have used two different methods of addressing in the examples and exercises.

The most common is DIRECT addressing, where the operand part of the instruction points to an instruction and we use the number that is found in that specified location. (i.e. LDA 200 means copy of the contents of location 200 into the accumulator.) The majority of instructions in SIMPLE use direct addressing.

When we used ADN 7 in the first program this was an example of IMMEDIATE addressing. The number 7 was immediately available for use without having to look in a location in main store to find the value. Only the ADN instruction uses immediate addressing in this simulation.

SIMPLE uses 16-bit words for its instructions. The most significant four bits provide the basic operation code and the next two bits are used to specify additional addressing modes. The instruction format is ooooIXAAAAAAAAAA where 0000 is the basic operation, I is the INDIRECT bit, X is the INDEX bit and the last ten bit provide an address.

With only 10 bits available to point to an address the maximum location which can be used for DIRECT ADDRESSING is 2~10-1 which is 1023. SIMPLE has 8K words of store, addressed from 0 to 8191. The locations above 1023 can be used to hold instructions but cannot be addressed directly. To use these locations to hold values we have to make use of INDIRECT ADDRESSING. In this case the INDIRECT bit is set and the value to be used is found by accessing memory twice.

As an example let us use the instruction ADDI 128 (0100100010000000). Here the location 128 holds the address of

PAGE 100 another location which can be greater than 1023. This is the location which holds the value to be added to the accumulator. The main disadvantage of this method of addressing is that it needs to access memory an additional time which slows the instruction down.

The next addressing method provided by SIMPLE is INDEXED ADDRESSING. Here the contents of the index register are added to the address part of the instruction and the result is used to point to the location in main memory. The index register can hold 16-bit numbers and so can point to all the possible 64K of possible address space. The instructions TAX and TXA allow values to be transferred between the accumulator and the index register while DCX decrements the index register by 1. This is very useful in pointing to items in a list one at a time in order.

Many computers, including SIMPLE allow both addressing methods to be applied together. In SIMPLE the content of the index register is added to the contents of the location pointed to by the operand to form the effective address.

1. The source program for the program below is held on the disc with the file name S.LP1. Assemble, load and execute the program.

(STORE 10) LDA THREE TAX LOOP TXA JZR FINISH INP STAX 100 DCX JUN LOOP FINISH HLT THREE CON 7.11 (END)

PAGE 101 2. The program above stores numbers in a list. At which location is the first number stored? At which location is the last number stored? (The disassembler may help.)

3. Write a program to print out the three numbers from these locations in reverse order using a loop.

4. Modify the program to use indirect indexed addressing so that the numbers are stored in a locations above 8000.

======

PAGE 102 STUDENT EXERCISES WITH SIMPLE

Session 4 Subroutines

It is often found that a section of code is needed at various places in a longer program. In high-level langugages procedures are used so that the code is only entered once. In low-level languages subroutines are used.

For a subroutine to be useful some mechanism must exist to return to the correct point in the main line program after the subroutine call. Some low-level languages have special instructions to jump to subroutines, storing the return address automatically, and for the return from the subroutine. Others, like SIMPLE, make use of the existing commands and addressing methods.

PAGE 103 Belm~ is a short demonstration program to illustrate the method. It is stored on the disc with the name S.SR. Comments have been added to aid understanding.

(STORE 10) INP STA X LDA ZERO Clear accumulator ADN BACK Utilises immediate addressing STA RTN Saves return address JUN DOUBLE Jump to subroutine BACK OUT Label for return address HLT DOUBLE LDA X Start of SIR ADD X JUNI RTN Return via indirect addressing RTN CON BACK X VAR ZERO CON 0 Needed to clear accumulator (END)

1. Assemble and execute the program with speed set to 0 or 1 to understand how the method works.

2. Write and test a subroutine to carry out multiplication by repeated addition using a loop.

3. Expand your program so that the subroutine can be used to evaluate the expression 3x-xy+24, were x and y are the first and second values entered.

PAGE 104 App~ ...... c:Jix 4-

SIMPLE ,E!'''''ti ...... g

1. Type of machine used

BBC Master 128 BBC B+ 128 BBC B with ••••••••••••••••• Extension board

2. Students using the software. Age range •••• to •••• Course

Normal textbook

3. Was the work on machine architecture new to the students at the time of testing or used for revision ••• extension ••• practice? (PI ease ti cl<>

4. Which wordprocessor or text-editor was used to prepare source program files?

5. Was the documentation for the teacher adequate? If not please list additional information which would be useful or any changes which will improve it.

6. How did you introduce the software to your students? Gave them the disc and student documentation plus exercises Gave a short demonstration of the system and then let them work through the student documentation and exercises

Gave demonstrations and explanations at each stage before setting work to the students

PAGE 105 7. How easily did the students understand the basic instruction set? Quickly and easily from their documentation They needed some help from the teacher . . . . . They needed considerable help from the teacher

8. Were the students able to hand code the first suggested program? Unable Easily With a little help With considerable help

9. Did the students manage to enter their program via the EDIT command and then DISASSEMBLE the first program? 10. What problems did the students experience with the first session?

11. How much help was needed from the teacher in producing a source file which assembled correctly? No help •••• A little help to a few students A little help to most students •••• Considerable help

12. If help was given was the problem with Faulty student code Poor inaccurately produced source file Faults in the assembler?

13. What problems did the students encounter with the DISASSEMBLER? None •••• or please list below.

14. What additional problems were encountered by the students in the second session? None •••• or please list below.

PAGE 106 15. How easily did the students understand the addressing methods available in SIMPLE? Quickly and easily from their documentation They needed some help from the teacher They needed considerable help from the teacher

16. Were the students able to extend the program to produce the reversed list? Quickly and easily from their documentation They needed some help from the teacher They needed considerable help from the teacher

17. Were the students able to extend the program to store the list above location 8000? Quickly and easily from their documentation They needed some help from the teacher They needed considerable help from the teacher

18. Please list any additional problems found during session 3.

19. Could the students understand the method used for subroutines in SIMPLE? Quickly and easily from their documentation They needed some help from the teacher They needed considerable help from the teacher

20. Were the students able to write and test the multiplication subroutine. Quickly and easily from their documentation They needed some help from the teacher They needed considerable help from the teacher

21. Were the students able to extend the program to evaluate the expression? Quickly and easily from their documentation They needed some help from the teacher They needed considerable help from the teacher

PAGE 107 22. Did you find that the work with SIMPLE helped your students with this part of the syllabus? Hindered Helped a little •••• Helped considerably

23. Would your use the package again? No •••• Yes with modifications Yes without modifications ••••

24. If you were to modify your use of the package please list the modifications below.

25. Please list below any changes to the software which you think would improve it.

26. If you found any bugs in the system please list them below together with the circumstances if known.

PAGE 108 Appe.ncfix :5

Listing of main simulator program -SIMPLE

10 REM SIMPLE 16 BIT SIMULATOR 20 REM (C) A Goodhew 30 REM MASTERISOLIDISK/B+ 13 Dec 87 40 ON ERROR GOT0260 50 REM" Tony Goodhew 60 REM"4 Knollgate Close 70 REM"Birstall, LEICESTER LE4 3JN 80 REM"Phone: 0533 675422 90 REM"at Groby College: 111533 875043 10121 : 11121 REM ***** LEVEL 0 ***** 12e : 130 *SHADOW 140 MODE7:VDU23,1,0;0;0;12I; 150 PROCti tIe 160 PROCinit 170 REPEAT:UNTIL TIME>1000 OR INKEY(-73) 180 MODE1:VDU19,1,4;0;23,1,0;0;0;12I; 190 PROCinside 200 PROCcomin 210 MODE7 22111 END 240 : 250 REM ** ERROR ROUTINE ** 26121 VDU3,4:COLOUR3:GCOL0,3 270 REPEAT:VDU26,7:CLS:IF ERR<>17 THEN 330 28121 PRINT"ESCAPE pressed'" 290 PRINT"Finish (F) or Run simulator (R)

: " ; : PROCi n2: key$=LEFT$ (i n$, 1> 300 p=INSTR("FfrR", key$): UNTILp< >0 310 IFp<3 THEN CLOSE#0:CLS:END 320 RUN 33121 CLS:REPORT:PRINT" at line ";STR$(ERLl

PAGE 109 340 PRINT'''Possible new bug_"'" Please report this error and how it"'" happened to Tony Goodhew": END 350 : 360 REM ***** LEVEL 1 ***** 370 : 38121 DEFPROCinit 390 osY.=FNos:IFosY.=l THEN bankY.=&E 400 IFosy'=2 THEN bankY.=&C 41121 IFosY.=3 THEN banky'=4 42121 REM l=B: 2=B+: 3=MASTER 43121 LOCALb Y. , i Y. 44121 op$="HLTTAXTXADCADCXANDORALSLLSRASLASRINPOUT" 45121 PROCmcode 46121 mosY.=octY.+&5121:byte7.=oct7.+&8121:of7.=&8121121121:of1Y.=&81211211: b$=STRING$(39," "):sp=0 470 xregY.=0:acc7.=0:maccY.=I2I:max7.=32767:stat7.=0:sp7.=1 480 file$="No file":last7.=I2I:first7.=12I 49121 CLOSED0:chn=OPENIN("D.SCR"):xY.=12I 51210 DIMbox(2,11),reg$(11),line(5,22) 51121 FORb7.=0T011:FORi7.=0T02: INPUTDchn,box (i7.,b7.):NEXT: INPUTDchn,reg$(b7.):NEXT 52121 FORi7.=I2IT022:FORk7.=I2IT05:INPUTDchn,line(kY.,i7.):NEXT:NEXT 53121 CLOSEDI2I:help=OPENUP("D.HELP") 54121 ENDPROC 550 : 56121 DEFPROCcomin 57121 LOCALcom$,len,p,q,done7. 580 done7.=FALSE 590 REPEAT 6121121 PROCcwin:CLS 61121 PRINT":";:PROCin:inx$=in$:in$=in$+" " 62121 IF LEFT$(in$,1>="*" PROCstar:GOT0830 63121 com$=LEFT$(in$,3):PROCtwin:CLS 64121 IFcom$="FIN" THENVDU26,12:CLOSE#I2I:done7.=TRUE:GOT083121 65121 IFcom$="VAL" PROCvalues:GOT060121 66121 IFcom$="COM" PROCcomds:GOT0600 67121 IFcom$="EXE" PROCexe:GOT06121121 68121 IFcom$="DIS" PROCdis:GOT061210

PAGE 110 69121 IFcom$="EDI" PROCedit:GOT06121121 7121121 IFcom$="EXP" PROCexp:GOT06121121 710 IFcom$="SPE" PROCspeed:GOT0600 720 IFcom$="ASS" CHAIN"ASSEMBL" 73121 IFcom$="LOA"PROCload:GOT060121 74121 IFcom$="SAV"PROCsave:GOT060121 750 len=LEN(in$l:p=1 760 REPEAT:p=p+1:UNTIL MID$(in$,p,1l=" " 770 REPEAT:p=p+1:UNTIL MID$(in$,p,1l<>" " 780 q=p:REPEAT:q=q+1:UNTIL MID$(in$,q,ll=" " 790 second$=MID$(in$,p,q-pl 800 IFcom$="HEL" PROChelp:GOT082121 81121 VDU7:PROCcwin:PRINT'''Invalid command. Type COMMANDS for listu.llof valid commands.1J 82121 TIME=0:REPEAT UNTIL TIME >500 OR INKEY(-73l:CLS 830 UNTIL done7. 840 ENDPROC 850 : 860 DEFPROCt i tl e 870 TIME=0 880 FORz7.=0 T01:PRINTTAB(8,4+z7.lCHR$141CHR$131"Simple machine":NEXT 890 PRINT'TAB(9lCHR$132"by Tony Goodhew"":PROCexp2 91210 ENDPROC 910 : 920 REM ***** LEVEL 2 ***** 930 : 940 DEFPROCin 950 *FX202,32 960 LOCALp,ch$,ch 970 in$="":p=POS:*FX21,0 980 REPEAT 990 ch$=GET$: ch=ASC (ch$l 11211211Zl IF ch)96 THEN ch=ch AND&DF 1010 IF ch<32 OR ch>127 THEN 1060 1020 IFch>96 AND ch<123 THEN ch$=CHR$(ch-32) 1030 IFch$=":" THEN CLS:PRINT":";:GOT0970 112140 IF POS)p OR ch<>95 THEN PRINTch$;

PAGE 111 1050 IF ch=95 AND LEN(in$»0 THEN in$=LEFT$(in$,LEN(in$)-1) ELSE IF ch<>95 in$=in$+CHR$(ch) 1060 UNTIL ASC(ch$)=13 AND LEN(in$)>0 1070 VDU26 1080 ENDPROC 1090 : 1100 DEFPROChelp 1110 LOCALx$,rec7.,c$,h7. 1120 IF second$="" THEN second$="HELP" 1130 DATAASS,COM,DIS,EDI,EXE,FIN,HEL,SPE,VAL,? 1140 x$=inx$ 1150 RESTORE1130:rec7.=-1 1160 PROCcwin:CLS 1170 REPEAT 1180 rec7.=rec7.+1:READc$ 1190 UNTIL LEFT$(c$,3)=LEFT$(second$,3) OR c$="?" 1200 IF c$="?" THEN PROCnohelp:GOT01220

1210 PTR~help=150*rec7.:

FORh7.=0T04:INPUT~help,h$:PRINT·h$;:NEXT 1220 ENDPROC 1230 : 1240 DEFPROCload 1250 LOCALlo7.,hi7. 1260 PROCtwin:PRINT"LOAD file name :";:PROCin2:file$=in$ 1270 IF LEN(file$)>9 THEN file$=LEFT$(file$,9) 1280 CLS:PRINT"Loading "file$:prog7.=OPENUP(file$) 1290 IFprog7.=0THEN VDU7:PRINT"File not found":PROCdelay(5):CLS:GOT01380 1300 INPUT#prog7.,first7.,last7. 1310 FORpt7.=first7. TO last7. 1320 PRINTTAB(0,1)pt7.

1330 lo7.=BGET~prog7.:PROCpush(of7.+2*pt7.,lo7.)

1340 hi7.=BGET~prog7.:PROCpush(of17.+2*pt7.,hi7.) 1350 NEXT

1360 CLOSE~prog7. 1370 CLS:PROCcwin:CLS 1380 ENDPROC 1390 :

PAGE 112 1400 DEFPROCsave 1410 LOCALpt:r. 1420 PROCtwin:PRINT"SAVE -file name :";:PROCin2:-file$=in$ 1430 IF LEN(file$»9 THEN file$=LEFT$(-file$,9) 1440 PROC-firstlast("SAVING "+file$) 1450 out:r.=OPENOUT(-file$) 1460 CLS:PRINT"Saving "-file$ 1470 PRINT#out:r.,start:r.,last%:firstl.=startl. 1480 FORpt:r.=start:r. TO last:r. 1490 BPUT#outl.,FNpull (o-f:r.+2*pt:r.): BPUT#out:r.,FNpull(of1:r.+2*ptl.) 1500 PRINTTAB(0,1)pt:r. 1510 NEXT 1520 CLS:CLOSE#out:r. 1530 PROCcwin:CLS 1540 ENDPROC 1550 : 1560 DEFPROCexe 1570 PROCtwin:CLS:PROCmes(0,"EXECUTE"):PRINTTAB(0,1) "Execut e address :11; 1580 PROCin2:PROCgetnumb(in$):IF(err=1)OR (val)8191) THEN VDU7:PRINT'''Invalid address":PROCdelay(5):CLS:GOT01570 1590 CLS:PRINT"Printed Input/Output (Y/N) :";:PROCin2:p=INSTR("YynN",in$):IFp=0 THEN VDU7:GOT01590 1600 pflag:r.=FALSE:IFp<3 THEN pflag:r.=TRUE 1610 CLS:PROCmes(1,"Execute address into SCR"):scr:r.=val:IFsp:r.<)2 THEN PROCdelay(2) 1620 halt:r.=FALSE 1630 REPEAT 1640 IF INKEY(-73)THEN PROCintrpt:GOT02100 1650 PROCwrtreg(6,scrl.)::PROCtwin:PROCmes(1,"") 1660 PROCmes <1, "FETCH INSTRUCTION SCR POINTS TO") 1670 PROCmes(2,"Copy SCR into MAR"):marl.=scr:r. 1680 PROCtrack(13,7,mar:r.) 1690 PROCmes ( 1 , "ACCESS MA I N MEMORY") 1700 PROCmes(2,"MAR points to memory location"):PROCtrack(14,8,marl.) 1710 IF mar:r.)8191 THEN

PAGE 113 haltY.=TRUE:PROCtwin:CLS:PROCmes(0,"Address out of MEMORY-CRASH STOP"):VDU7:PROCdelay(4):CLS:GOT02090 1720 memY.=FNpull(ofY.+2*marY.) 1730 PROCwrtreg(8,memY.) 1740 PROCmes(2,"Copy memory contents into MDR"):PROCtrack(15,9,memY.):mdrY.=memY. 1750 PROCmes(2,"Copy MDR into CIR"):PROCtrack(0,10,memY.):cirY.=mdrY. 1760 IF INKEY(-73)THEN PROCintrpt:GOT02100 1770 PROCmes(1,"Point SCR to next instruction") 1780 PROCmes (2, "Increment SCR") 1790 VDU26:t=11:PROCtrav(line(0,t),line(1,t), line(2,t),line(3,t),line(4,t),line(5,t),2) 1800 PROCtrav(line(0,t),line(1,t),line(2,t),line(3,t), line(4,t) ,line(5,t) ,1> 1810 scrY.=scrY.+1:PROCtrack(12,6,scrY.) 1820 IF INKEY(-73)THEN PROCintrpt:GOT0211210

1830 PROCmes (1, "Decode instruction") 1840 PROCdecode(cirY.):ead7.=adY. 1850 PROCtwin:CLS:instr$=cd$ 1860 FORii=1 TO 6-LEN(cd$):instr$=instr$+" ":NEXT:instr$=instr$+STR$(ad7.) 1870 PROCmes(l2I,instr$) 1880 PROCmes(2,"Address part into ADR"):PROCtrack(8,5,ad7.) 1890 IFiadY.=1 THEN PROCindirect 1900 IFxbtY.=1 THEN PROCindex

1910 PROCtI~in: CLS: PROCmes (0, "PROCESS "+instr$) 1920 IF INKEY(-73)THEN PROCintrpt:GOT0210121 193121 IFCY.=12I PROChlt:GOT021121121 1940 IFCY.=1 PROClda:GOT02090 1950 I FCY.=2 PROCsta:GOT0212190 196121 I FCY.=3 PROCtrg:GOT02090 197121 I FCY.=4 PROCadd:GOT0212l9121 1980 I FCY.=5 PROCadn:GOT0212190 1990 I FCY.=6 PROCsub:GOT0212l912l 21210121 I FCY.=7 PROCdcr:GOT0212190 21211121 IFCY.=8 PROCand:GOT0212l912l 212120 I FCi:.=9 PROCora:GOT021219121

PAGE 114 2030 IFC7.=10 PROCIsh:GOT02090 2040 IFC7.=ll PROCash:GOT02090 205111 IFC7.=12 PROCiop:GOT0211190 2060 IFC7.=13 PROCjun:GOT02090 2070 IFC7.=14 PROCjzr:GOT02090 2080 IFC7.=15 PROCjng:GOT02090 2090 IF I NKEY ( -73lTHEN PROCintrpt 2100 UNTIL halt7. 211111 TIME=0: REPEAT: UNTIL TI ME >40111 2120 PROCtwin:CLS 213l?j ENDPROC 2140 : 2150 DEFPROCedit 2160 LOCALloc7. 2170 PROCtwin:PRINT"Location for editing :";:PROCin2:PROCgetnumb(in$):IF(err=1)OR (val>B191) THEN VDU7:PRINT'''Invalid address":PROCdelay(5):CLS:GOT02170 2180 CLS:loc=val:PROCunpack(loc) 2190 PRINTTAB0 2290 IFp<3 VDU2 2300 PRINT'''Location Value Instruction'" 2310 FORpt7.=start7. TO last7. 2320 mem7.=FNpull(of7.+2*pt7.) 2330 .PRINTSTR$pt7.TAB(6);:N7.=pt7.: CALLoct7.:PRINT" ";:N7.=mem7.:CALLoct7.:PROCdecode(mem7.):PRINT"

PAGE 115 "cd$TAB(15)STR$(adl..) 2340 NEXT 2350 VDU3:PRINT'TAB(5)"Press SPACE to continue" 236121 REPEAT:UNTIL GET$=" .. 237121 CLS:PROCinside:PROCcwin 238121 ENDPROC 2390 : 24121121 DEFPROCstar 241121 VDU26:CLS:PROCoscli(RIGHT$(inx$,LEN(inx$)-1» 242121 PRINT'TAB(5)"Press SPACE to continue" 2430 REPEAT:UNTIL GET$=" ":CLS:PROCinside:PROCcwin 244121 ENDPROC 245121 : 246121 DEFPROCspeed 247121 PROCtwin:CLS:PRINT .. SPEED .. • .. Enter 121 (slow) 1 or 2 : ";: PROCin2: PROCgetnumb (in$) 248121 IF(err=1> OR (val<0 OR val >2) THENVDU7:PRINT"'Invalid number":PROCdelay(4):CLS:GOT0247121 249121 spl..=val:CLS 25121121 ENDPROC. 251121 : 252121 DEFPROCexp 2530 VDU26:CLS:PRINT"EXPLAIN'" 254121 PROCexp2 255121 PRINTTAB(8)"Press SPACE to continue": REPEAT: UNTIL GET$=" ":CLS:PROCinside 256121 ENDPROC 257121 : 258121 DEFPROCcomds 259121 PROCtwin.CLS:PRINT"COMMANDS available are ASSEMBLE COMMANDSDISSASSEMBLE EDIT EXECUTE FINISH HELP SPEED and VALUES." 26121121 ENDPROC 261121 : 262121 DEFPROCvalues 263121 PROCtwin:CLS.PRINT"VALUES" 2640 PRINT"Speed: "STR$(spl..) 265121 PRINT"Last file. "file$" from "STR$(firstl..)" to

PAGE 116 "STR$(last%l 2660 ENDPROC 2670 : 2680 DEFPROCmcode 2690 DIMcode% 255 2700 REM Routine to convert 16 bit 2710 REM binary number into octal 2720 REM and print it, including 2730 REM leading zeros. 2740 REM Negative numbers and decimals 2750 REM are not taken into account. 2760 REM The number to 2770 REM be dealt with is stored in 2780 REM the memory location that 2790 REM the variable 'number' points 2800 REM to, and the one after, in 2810 REM the form la byte, hi byte. 2820 2830 store=8.70 2840 number=&438 2850 groups=5:REM num groups of 3 bits 2860 oswrch=8.FFEE 2870 2880 FOR pass=0 TO 2 STEP 2 2890 P%=code%:oct%=code% 291210 [OPT pass 2910 2920 LDA#I2I:STA store 2930 JSR shiftbit \ Deals with first 2940 JSR print \ bit, which is 295121 \ remaining when 2960 \ number has been 2970 \ divided into 298121 \ groups of three 2990 \ starting on the 31210121 \ right 31211121 LDX#groups 3020 .loopy \ Main loop to

PAGE 117 31113111 J8R shift \ call the shift 31114111 J8R print \ and print 31115111 DEX:BNE loopy \ subroutines for 31116111 311170 \ JSR &FFE7 \ Form feed if needed 31118111 31119111 RTS \ each groupa bits 31111111 311111 .shift 312111 LDA#I2I:8TA store \ subroutine to 313111 LDY#3:.again \ chop the left 314111 J8R shiftbit \ three bits off 315111 DEY:BNE again \ the number 316111 RT8 317111 3180 .print 3190 LDA store \ subroutine to 320121 CLC:ADC#48 \ convert the 3210 J8R oswrch \ number to ascii 322111 RTS 323121 324111 .shiftbit 3250 A8L number \ shifts one bit 326121 ROL number+l \ of the number 3270 ROL store \ into 'store' 3280 RT8 3290 ]:NEXT 33121111 ENDPROC 331111 : 332111 DEFFNos 333111 REM Find 08 to identify machine 334111 REM 121=081.121: 1=081.2 2=082.111 335111 A%=I1I:X%=l 336111 =(U8R(&FFF4) AND&FFI2II1I)DIV&ll21l11 337121 : 338111 REM ***** LEVEL 3 ***** 339121 : 34111111 DEFPROCnohelp

PAGE 118 341121 VDU7

342121 PRINT' "Invalid command I " 343121 ENDPROC 344121 : 345121 DEFPROCfirstlast(top$) 346121 PROCtwin:start7.=-l 347121 CLS:PRINTtop$ 3480 IFstart7.>=12I THEN 351121 3490 PRINTTAB(I2I,l) "Start address :";:PROCin2:PROCgetnumb(in$):IFerr=1 THEN VDU7:PRINT"Invalid number": PROCdelay (5): CLS: GOT03460 . 35121121 start%=val 351121 PR I NTTAB (0,2) "Last address :";: PROCi n2: PROCgetnumb 8191THENCLS:VDU7:PRINT"Address out of memory (0-8191)":PROCdelay(3):GOT03460 3550 ENDPROC 3560 : 3570 DEFPROChlt 3580 PROCmes(2,"HALT EXECUTION"):halt'l.=TRUE 3590 ENDPROC 361210 : 3610 DEFPROCiop 3620 IFiad7.=l THEN 369121 3630 PROCtwin:CLS 3640 IFpflag7. THEN VDU2 3650 PRINTTAB(0,ll"Input value : ";: PROCi n2: PROCgetnumb (in$): VDU13: IFerr=l THEN VDU7:PRINT'''Invalid number":VDU3:PROCdelay(5)::GOT03630 3660 VDU3:PROCwrtreg(3,val):acc'l.=val:PROCmes(l,"Transfer value to ACC"):macc%=acc7. 3670 IFacc7.>max7. THEN acc7.=-FNcomp(acc7.) 3680 PROCtrack(l,l,macc7.):PROCtwin: CLS: VDU26: PROCstatus: GO'T0373121 3690 PROCmes(l,"Copy ACe to OUTPUT device")

PAGE 119 3700 IFpflag7. THEN VDU2 3710 PROCtrack(2,11,macc7.):PRINT:VDU3:IFsp7.<>2 THEN PROCdelay(2) 3720 PROCtwin:CLS:VDU26 3730 ENDPROC 3740 : 3750 DEFPROCunpack(loc7.) 3760 LOCALpw7. 3770 mem7.=FNpull(of7.+2*loc7.):PRINT"Loc: "STR$loc7." ";:N7.=mem7.:CALLoct'Y.:PRINT 3780 PROCbinout(mem7.) 3790 PROCdecode (mem7.): PRINT" "cd$" "STR$ad7." "STR$mem7. 3800 ENDPROC 3810 : 3820 DEFPROCindirect 3830 IF INSTR(op$,cd$)>0 THEN ad7.=0:ead7.=0:GOT03890

3840 PROCmes (1 , " I ND IRECT ADDRESS I NG" ) 3850 PROCmes(2,"Copy ADR into MAR") 3860 PROCdoubletrack(19,21,5,ad7.):mar7.=ad7. 3870 PROCfetchit 3880 ad7.=mdr7.:PROCmes(2,"Copy MDR into ADR"):PROCdoubletrack(20,22,5,ad7.) 3890 ENDPROC 3900 : 3910 DEFPROCindex 3920 PROCmes(l,"INDEXED ADDRESSING-add X to address") 3930 ead7.=xreg7.+ad7.: st$=STR$(xreg7.) +"+"+STR$(ad7.) +"="+STR$(ead7.) 3940 PROCmes(2,st$) 3950 IFsp7.<>2 THEN PROCdelay(2.5) 3960 ad7.=ead7.:PROCwrtreg(S,ad7.) 3970 ENDPROC 3980 : 3990 DEFPROClda 4000 PROCmes(l,"Copy ADR into MAR"):PROCdoubletrack(19,21,7,ead7.):mar7.=ead7. 4010 PROCfetchit:v7.=mdr7. 4020 PROCmes(2," "):PROCmes(l,"Copy MDR into

PAGE 120 ACC"I:PROCtrack(3,I,vXI 403121 maccX=vX:accX=vX:IFaccX>maxX THEN accX=-FNcomp(accXI 41214121 IFspX<>2 THEN PROCdelay(11 41215121 PROCstatus 41216121 ENDPROC 4070 4080 DEFPROCsta 412190 PROCmes <1, "Copy ADR into MAR"I:PROCdoubletrack(19,21,7,eadXI:marX=eadX 4100 PROCmes (1, "Copy ACC into MDR" I: PROCtrack (17,9, maccXI

4110 PROCmes (1, "Copy MDR to DATA BUS" I 4120 VDU26:PROCtrav(416,34121,416,272,660,272,21 413121 PROCmes(2,"Select location with MAR"I:PROCtrack(14,8,maccXI 4140 PROCtrav(416,34121,416,272,66121,272,11: PROCpush(ofX+2*eadX,maccXI 415121 PROCtwin:CLS:VDU26 416121 ENDPROC 417121 : 418121 DEFPROCtrg 419121 IFiadX=1 THEN 4220 42121121 PROCmes(I,"Copy ACC to X"I:xregX=maccX 421121 PROCtrack(18,4,xregXI:GOT0425121 422121 PROCmes (1, "Copy X to ACC") 423121 PROCtrack(5,I,xregXI:maccX=xregX 424121 accX=xregX:IFaccX>maxX THEN accX=-FNcomp(accXI 425121 PROCstatus 4260 ENDPROC 427121 : 4280 DEFPROCadd 429121 PROCmes(I,"Copy ADR into MAR"I:PROCdoubletrack(19,21,7,eadXI:marX=eadX 4300 PROCfetchit:vX=mdrX 431121 IF vX>maxX THEN vX=-FNcomp(vXI 4320 accX=accX+vX:maccX=accX 433121 IFmaccX<12I THEN maccX=FNcomp(-maccXI 4340 PROCmes(I,"Add ACC and MDR"I:PROCtrack(3,I,maccXI 4350 PROCstatus

PAGE 121 4360 ENDPROC 4370 : 4380 DEFPROCadn 4390 PROCmes(1,"Add ACC and address") 44(1)0 acc%=acc%+ad%:macc%=acc% 4410 IFmacc%<0 THEN macc%=FNcomp(-macc%) 4420 PROCwrtreg(1,macc%):IF sp%<>2 THEN PROCdelay(2) 4430 PROCstatus 4440 ENDPROC 4450 : 4460 DEFPROCsub 4470 PROCmes(1,"Copy ADR into MAR") : PROCdoubl etrack <19,21,7 ,ead%) : mar%=ead% 4480 PROCfetchit:v%=mdr% 4490 IF v%>max% THEN v%=-FNcomp(v%) 4500 acc%=acc%-v%:macc%=acc% 4510 IFmacc%<0 THEN macc%=FNcomp(-macc%) 4520 PROCmes(1,"Subtract MDR from ACC"):PROCtrack(3,1,macc%) 4530 PROCstatus 4540 ENDPROC 4550 : 4560 DEFPROCdcr 4570 IFiad%=1 THEN 4640 4580 PROCmes(1,"Decrement ACC by 1") 4590 acc%=acc%-1:macc%=acc% 4600 IFmacc%<0 THEN macc%=FNcomp(-macc%) 4610 PROCwrtreg(1,macc%) 4620 PROCstatus 4630 GOT04670 4640 PROCmes(1,"Decrement X by 1") 4650 xreg%=xreg%-1:mxreg%=xreg%:IFxreg%<0 THEN mxreg%=FNcomp(-xreg%) 4660 PROCwrtreg(4,mxreg%) 4670 PROCinrange(xreg%) 4680 ENDPROC 4690 :

PAGE 122 47121121 DEFPROCjun 4710 PROCmes<1, "Unconditional jump") 472121 PROCadrTOscr:IFsp7.<>2 THEN PROCdelay(1.5) 4730 PROCtwin:CLS:VDU26 4740 ENDPROC 4750 4760 DEFPRDCjzr 4770 PROCmes(1,"ACC=0 ?") 4780 IF acc7.=12I THEN PRDCmes(1,"ACC=11l ? TRUE"):PRDCadrTOscr:ELSE PROCmes(1,"ACC=12I ? FALSE"): I Fsp7.< >2 THENPROCdelay(1.5) 4790 PROCtwin:CLS:VDU26 48111121 ENDPRDC 4810 : 482111 DEFPROCjng 4830 PROCmes(1,"ACC<0 ?")

4840 IF acc7.<11I THEN PROCmes (1, "ACC<0 ? TRUE"):PROCadrTOscr:ELSE PROCmes(1,"ACC<0 ? FALSE"):IFsp7.<>2 THENPRDCdelay(1.5) 485121 PROCtwin:CLS:VDU26 4860 ENDPRDC 4870 : 4880 DEFPROCintrpt 4890 PRDCtwin:CLS:PRDCmes(0,"EXECUTION INTERRUPTED"):VDU7:PROCdelay(4):halt7.=TRUE 4900 ENDPROC 4910 : 4920 DEFPROCand 4930 PRDCmes(1,"Copy ADR into MAR"):PRDCdoubletrack(19,21,7,ead7.):mar7.=ead7. 494121 PROCfetchit:v7.=mdr7. 4950 macc7.=macc7. AND v7. 496121 acc7.=macc7.:IFacc7.>max7. THEN acc7.=-FNcomp(acc7.) 497121 PRDCmes(1,"AND ACC with MDR"):PRDCtrack(3,1,macc7.) 498121 PRDCstatus 499121 ENDPROC 50!Z1!Z1 :

PAGE 123 5010 DEFPROCora 502111 PROCmes(1,"Copy ADR into MAR"):PROCdoubletrack(19,21,7,ead'l.):mar'l.=ead'l. 503111 PROCfetchit:v'l.=mdr'l. 5040 macc'l.=macc'l. OR v'l. 5050 acc'l.=macc%:IFacc%>max% THEN acc%=-FNcomp(acc%) 51116111 PROCmes(1,"OR ACC with MDR"):PROCtrack(3,1,macc%) 51117111 PROCstatus 508111 ENDPROC 509111 : 5100 DEFPROClsh 511111 IF iad%=1 THEN 516111 512111 macc'l.=macc'l.*2:acc'l.=macc% 513111 IFacc'l.>max% THEN acc%=-FNcomp(acc%) 5140 PROCmes(1,"LOGICAL SHIFT LEFT of ACC"):IF sp'l.<>2 THEN PROCdel ay (1.5) 515111 GOTO 518111 516111 macc'l.=macc% DIV 2:acc%=macc%

517111 PROCmes (1, "LOGICAL SHIFT RIGHT of ACC"): IF sp'l.< >2 THEN PROCdelay C1. 5) 518111 PROCwrtreg(l,macc%):PROCstatus 519111 ENDPROC 52111111 : 521111 DEFPROCash 522111 sign'l.=SGNCacc%) 5230 IF iad%=1 THEN 5290 5240 macc'l.=macc'l.*2:acc%=macc% 5250 IFacc'l.>max% THEN acc%=-FNcompCacc%) 5260 PROCmesCl,"ARITHMETIC SHIFT LEFT of ACC"):IFsp%<>2 THENPROCdelayCl.5) 5270 PROCwrtregC1,macc%):IFsign%<>SGNCacc%)THEN VDU7:PROCmesC2,"OVERFLOW"):PROCdelayCl.5) 528111 GOT05330 5290 macc'l.=macc% DIV 2:acc%=macc'l. 5300 IFsign'l.<11I THEN acc'l.=-acc'l.:macc%=2A15+macc'l. AND &7FFF 531111 PROCmesCl,"ARITHMETIC SHIFT RIGHT of ACC"):IF sp%<>2 THENPROCdelayCl.5) 532111 PROCwrtregCl,macc'l.)

PAGE 124 5330 PRDCstatus 534111 ENDPROC 5350 : 5360 DEFPROCexp2 537111 PRINT"This program simUlates a small, simple .. • .. 16-bit computer with 8K words of memory. It displays the contents of registers while running a program ... • 5380 PRINT"It can be used to demonstrate the FETCH/EXECUTE cycle, machine code programming,the purpose of ASSEMBLERS and" 5390 PRINT"DISASSEMBLERS and various addressing methods ... • 5400 ENDPROC 5410 : 5420 REM ***** LEVEL 4 ***** 5430 : 544111 DEFPRDCinside 5450 LDCALb % , i % 5460 COLDUR2:PRINTTAB(35,10)"+1":CDLDUR3 547121 FDRb%=I2ITOll:PRDCbox(box(l1I,b%),box(1,b%),box(2,b%),reg$(b%»:NE XT 548111 MDVE258,888:DRAW1279,888:DRAW1279, 184:DRAW258, 184: DRAW 258,888 549121 GCOLI2I,1:FDRi%=I1ITD22:MDVEline(0,i%),line(1,i%):DRAWline(2,i%),1 ine(3,i%): DRAWline(4,i%),line(5,i%):NEXT 551210 PRINTTAB(I1I,0); 551111 VDU23,1,1;12I;11I;11I; 552121 ENDPRDC 5530 : 554111 DEFPRDCdoubletrack(t,t1,r,v) 555111 VDU26:PROCtrav(line(0,t) ,line(1,t),line(2,t), line(3,t),line(4,t),line(5,t),2) 556111 PRDCtrav(line(0,t1),line(1,tl),line(2,t1), line(3,t1),line(4,t1),line(5,t1),2) 557121 PRDCwrtreg(r,v) 558121 PRDCtrav(line(l2I,t),line(1,t),line(2,t),line(3,t), line(4,t) ,line(5,t), 1)

PAGE 125 5590 PROCtravClineC0.t1).lineC1.t1).lineC2.t1). lineC3.t1> .lineC4.tl> .lineC5.tl>.1> 5600 ENDPROC 5610 : 5620 DEFPROCpushCloc'l..v'l.) 5630 IFos'l.=l THEN 5680:REM for SOLIDISK 256 5640 ?byte'l.=v'l. MOD 256:?(byte'l.+1)=v'l. DIV 256 5650 byte1'l.=byte'l.+1

5660 st$="SRWRITE "+STR$~byte'l.+" "+STR$~byte1'l.+"

"+STR$~loc'l.+" "+STR$~bank'l. 5670 PROCoscliCst$):GOT05690 5680 ?&FE32=bank'l.:?loc'l.=v'l. MOD 256:?Cloc7.+1)=v7. DIV 256 5690 ENDPROC 5700 5710 DEFPROCin2 5720 *FX202.32 5730 LOCALch$.ch.v.p 5740 in$= .... :v=VPOS:p=POS:*FX21.0 5750 REPEAT 5760 ch$=GET$:ch=ASC(ch$) 5770 IFch>96 THEN ch=ch AND&DF 5780 IF ch<32 OR ch>127 THEN 5830 5790 IFch>96 AND ch<123 THEN ch$=CHR$Cch-32) 5800 IFch$=":" THEN PRINTTABCp.v)STRING$C25." "):PRINTTABCp-1.v)":";:GOT05740 5810 IF POS>p OR ch<>95 THEN PRINTch$; 5820 IF ch=95 AND LENCin$)>0 THEN in$=LEFT$Cin$.LENCin$)-l) ELSE IF ch<>95 in$=in$+CHR$Cch) 5830 UNTIL ASCCch$)=13 AND LENCin$)>0 5840 ENDPROC 5850 : 5860 DEFPROCgetnumbCn$) 5870 IFLENCn$)=0THENval=0:err=0:GOT05950 5880 n$=n$+" " 5890 n1$=LEFT$Cn$.1):err=0:t$=RIGHT$(n$.LENCn$)-1):t1$=LEFT$Ct$.LEN

Ct$) -1) 5900 IFn1$="@" THEN PROCoct(t1$):GOT05950

PAGE 126 591111 IFn1$="$"ORn1$="&" THEN PROChex(t1$),GOT0595111 592111 IFnl$="7."THEN PROCbin(t1$),GOT05951l1 593111 IFn1$>="I1I" AND n1$(="9" THEN PROCdec(LEFT$(n$,LEN(n$)-1»,GOT0595111 594111 err=1 5950 ENDPROC 5960 , 5970 DEFPROCdecode(insi.) 5980 C7.=insi.DIV4096,iadi.=I1I,xbti.=0:ad7.=11I 5990 IF(insi.AND211l48»I1ITHENiad7.=1 6000 IFCins7.AND1024»0THENxbti.=1 61'110 ON(C7.+1)GOT06020,6030,61114111,611150,6070,61118111,6090,61111111,6120,613111, 6140,616111,6180,621110,621111,6220 6020 cd$="HLT",GOT06230 61113111 cd$="LDA":PROCextra,GOT06230 611140 cd$="STA",PROCextra:GOT06230 6050 IFiad7.=0 THEN cd$="TAX",GOT06230 606111 cd$="TXA",GOT06230 611171'1 cd$="ADD",PROCextra,GOT0623111 61118111 cd$="ADN",ad7.=ins'l.AND411195,iad7.=I1I:xbt'l.=I1I,GOT06230 611190 cd$="SUB",PROCextra,GOT0623111 6100 IFiad7.=0 THEN cd$="DCA",GOT0623111 611111 cd$="DCX",GOT0623111 612111 cd$="AND",GOT06230 613111 cd$="ORA",GOT0623111 6140 IFiad7.=0 THENcd$="LSL",GOT06230 615111 cd$="LSR",GOT06231'1 6160 IFiad7.=0 THENcd$="ASL",GOT06230 6170 cd$="ASR",GOT06230 618111 IFiad'l.=0 THENcd$="INP",GOT0623111 619111 cd$="OUT",GOT0623111 6200 cd$="JUN",PROCextra,GOT06230 621111 cd$="JZR",PROCextra,GOT0623111 6220 cd$="JNG",PROCextra 6230 ENDPROC 6240 , 625111 DEFPROCbinout(v7.)

PAGE 127 6260 LOCALpw%,bit% 6270 FORpw%=15 TO 0 STEP-1 628121 bit%=2A pw%:IF(v%ANDbit%)=bit% THEN PRINT"l"; ELSEPRINT"I2I"; 629121 NEXT 63121121 ENDPROC 6310 : 632121 DEFPROCfetchit 633121 PRDCmes(2,"MAR points to memory location"):PROCtrack(14,8,mar%) 634121 mem%=FNpull(of%+2*mar%) 635121 PROCwrtreg(8,mem%) 636121 PRDCmes(2,"Copy memory contents into MDR"):PROCtrack(15,9,mem%):mdr%=mem% 637121 ENDPROC 638121 : 639121 DEFFNcomp(value%) 64121121 LOCALp%,t%,newvalue% 641121 newvalue%=l 642121 FORpY.=I2IT015 643121 tY.=2A pY.:IF(t% AND value%)=12I THEN newvalue%=newvalueY.+t% 644121 NEXT 645121 =newvalueY. 646121 : 647121 DEFPROCadrTOscr 648121 PROCmes (2, "Copy ADR into SCR") 649121 PROCtrack(7,6,ad%):scr7.=ad% 65121121 ENDPROC 651121 : 652121 DEFPROCstatus 653121 stat%=I2I:IFaccY.=12I THEN statY.=2:GOT0655121 654121 IF accY.<12I THEN stat%=statY.+4 655121 PROCwrtstat:PROCtwin:CLS:VDU26 656121 PROCinrange(accY.) 657121 ENDPROC 658121 : 659121 REM ***** LEVEL 5 *****

PAGE 128 6600 : 6610 DEFPROCbox(x,y,l,t$) 6620 LOCALh,tp,bt,lf,rt 6630 IFl<0THENI=6:h=14ELSEh=1 6640 tp=1032-y*32:bt=1016-(y+hl*32:lf=32*x-8:rt=32*(x+IJ+8 6650 GCOL0,2:MOVElf,tp:DRAWlf,bt:DRAWrt,bt:DRAWrt,tp: DRAWlf,tp:VDU5:PLOT0,8,32 6660 PRINTt$:VDU4 6670 ENDPROC 6680 : 6690 DEFPROCtrack(t,r,v) 6700 VDU26:PROCtrav(line(0,tl,line(1,tJ,line(2,tl, line(3,t) ,line(4,t) ,line(5,t) ,2) 6710 PROCwrtreg(r,v):IF(t=7) AND (spY.<>2) THEN PROCdelay(l) 6720 PROCtrav(line(0,t) ,line(1,t) ,line(2,t) ,line(3,t), line(4,t) ,line(5,t),1> 6730 ENDPROC 6740 : 6750 DEFPROCoscli(s$) 6760 $mosY.=s$ 6770 XY.=mosY. MOD 256:YY.=mosY. DIV 256 6780 CALL &FFF7 6790 ENDPROC 6800 : 6810 DEFFNpull (locy') 6820 LOCAL loY.,hiY. 6830 ?&F6=locY. MOD 256 6840 ?&F7=locY. DIV 256 6850 YY.=bankY.: loY.=USR (&FFB9) AND &FF 6860 ?&F6=(locY.+1) MOD 256 6870 ?&F7=(locY.+l) DIV 256 6880 YY.=bankY.:hiY.=USR(&FFB9) AND &FF 6890 =256*hiY.+loY. 6900 6910 DEFPROCbin(v$) 6920 REM Y. 6930 err=0:val=0:p=1:v$=v$+" ,. 6940 c$=MID$(v$,p,1)

PAGE 129 6950 IFc:$=" " THEN 6990 6960 IFc:$<)"1" AND c:$<)"0" THEN err=1:GDTD6990 6970 val=val*2+VAL(c:$):IF val<=&FFFF THENp=p+1:GDTD6940 6980 err=1 6990 ENDPRDC 7000 : 7010 DEFPRDChex(v$) 7020 REM $ or & 7030 err=0:val=0:p=1:v$=v$+" " 7040 c:$=MID$(v$,p,1) 7050 IFc:$=" " THEN 7110 7060 c:=ASC(c:$):IFc:<48DRc:)70DR(c:)57ANDc:<65)THENerr=1:GDTD7110 7070 IFc:)64THENc:=c:-55:GDTD7090 7080 IFc:<58THENc:=c:-48 7090 val=val*16+c::IF val<=&FFFF THENp=p+1:GDTD7040 7100 err=1 7110 ENDPRDC 7120 7130 DEFPRDCoc:t(v$) 7140 REM @ 7150 err=0:val=0:p=1:v$=v$+" " 7160 c:$=MID$(v$,p,1) 7170 IFc:$=" " THEN7210 7180 IFc:$<"0" OR c:$)"7"THEN err=1:GDTD7210 7190 val=val*8+VAL(c:$):IF val<=&FFFF THENp=p+1:GDTD7160 7200 err=1 7210 ENDPRDC 7220 : 7230 DEFPRDCdec:(v$) 7240 err=0:val=0:p=1:v$=v$+" " 7250 C:$=MID$(v$,p,1) 7260 IFc:$=" " THEN7300 7270 IFc:$<"0" DR c:$)"9"THEN err=1:GDT07300 7280 val=val*10+VAL(c:$):IF val<=&FFFF THENp=p+1:GDTD7250 7290 err=1 7300 ENDPROC 7310 : 7320 DEFPRDCextra

PAGE 130 7330 IFiad'Y.=1 THEN cd$=cd$+"I" 7340 IFxbt'Y.=1 THEN cd$=cd$+IIX" 7350 ad'Y.=ins'Y. AND112123 736121 ead'Y.=ad'Y. 737121 ENDPROC 7380 : 739121 DEFPROCwrtstat 74121121 LOCALpw'Y.,bit'Y. 741121 PRINTTABlboxll2l,2},boxI1,2}}; 742121 FORpw'Y.=3 TO 121 STEP-1 7430 bit'Y.=2Apw'Y.:IFlstat'Y. AND bit'Y.)=bit'Y. THEN PRINT"1"; ELSEPRINT"I2I"; 744121 NEXT:PRINT 7450 ENDPROC 7460 : 7470 DEFPROCinrangelcheck'Y.} 748121 IFcheck'Y.<32768 AND check'Y.)-32769 THEN 751210 7490 halt'Y.=TRUE:VDU7:PROCtwin:PRINT"Out of 16-bit range" • "CRASH STOP" 75121121 ENDPROC 751121 : 752121 REM ***** LEVEL 6 ***** 753121 : 754121 DEFPROCtravlx1,y1,x2,y2,x3,y3,col} 755121 IFsp'Y.=2 THEN 759121 756121 GCOLI2I,col:MOVEx1,y1 757121 IFx1=x2 PROCylinelxl,y1,y2}ELSEPROCxlinelyl,x2,x3} 758121 IFx2=x3 PROCylinelx2,y2,y3}ELSEPROCxlinely2,x2,x3) 759121 ENDPROC 760121 : 7610 DEFPROCdelaylsec} 762121 IFsp'Y.=12I THENREPEAT:UNTIL INKEYI-99}:GOT0764121 763121 TIME=I2I:REPEAT UNTIL TIME )sec*1121121 OR INKEY(-73) 764121 ENDPROC 765121 : 766121 DEFPROCmesly,text$} 767121 PROCtwin:PRINTTABII2I,y)b$:PRINTTABII2I,y)text$ 768121 ENDPROC

PAGE 131 7690 : 7700 DEFPROCwrtreg(reg,v) 7710 VDU26:PRINTTAB(box(0,reg),box(1,reg»;:N7.=v:CALLoct7.:PRINT 7720 IFsp7.=0 THEN REPEAT:UNTIL INKEY(-99) 7730 ENDPROC 7740 : 7750 REM ***** LEVEL 7 ***** 7760 : 7770 DEFPROCyline(x,ybeg,yend) 7780 LOCALsy,y 7790 sy=l:IFyend

PAGE 132 Listing of the assembler - ASSEMBL

10 REM ASSEMBL 13 Dec 87 20 REM (C) A.Goodhew 30 ON ERRORGOTO 1810 40 REM123456789012345678901234567 50 REMLLLLLL OOOIX AAAAAAA 60 MODE7 70 FORz7.=0T01:PRINTTAB (10, 1+z7.) CHR$141CHR$131 "Assembler": NEXT 80 PROCinit 90 PRINTTAB(0,4);:PRINT"Name ofSOURCEfile :";,PROCin2:sfile$=in$ 100 IF LEN(in$)(1 OR LEN(in$»9 THEN VDU7:PRINTTAB(0,4)STRING$(" ",39):GOT090 110 in7.=OPENUP(sfile$) 120 IFin7.=0 THENVDU7:PROCcat:RUN 130 PRINT'''Name offile :";:PROCin2:ofile$=in$ 140 REPEAT:CLS:PRINT"Print (Y/N) ? :";: PROCi n2: key$=LEFT$

PAGE 133 27121 IF abort% THEN PRINT'''Fatal error",CLOSE#I2I,os$="DEL. "+ofile$,OSCLI(os$) ELSE PRINT'''Assembly complete - object file called "ofile$ 28121 VDU3,firsttry%=TRUE 29121 REPEAT, IF firsttry%=FALSE THEN CLS 3121121 firsttry%=FALSE 31121 PRINT'''A - another assemble run" "'R - run simulator" 32121 PRINT' "Enter (AIR) ... 11 •, 33121 PROCin2, key$=LEFT$ 121 34121 IFp<3 THEN RUN 35121 MODE7: FORz%=I2IT01:PRINTTAB (7,7+z%) CHR$141CHR$131"Loadin g simulator",NEXT 36121 CHAIN"SIMPLE" 37121 : 38121 REM ** ERROR ROUTINE ** 39121 CLOSE#I2I, IF ERR<>17 THEN 47121 4121121 REPEAT,VDU3,7,CLS:PRINT"ESCAPE PRESSED'" 41121 PRINT"Finish (F) or Simulator (S) :";:PROCin2:in$=LEFT$(in$,1) 42121 p=INSTR("FfSs" ,in$) :UNTILp<>12I 43121 IFp<3 THEN CLS,END 44121 GOT036121:REM CH."SIMPLE" 45121 VDU3:CLS:REPORT:PRINT" at line "ERL 46121 PRINT"Please report this error and how it .. • .. happened to Tony Goodhew.":END 47121 , 480 REM ***** LEVEL 1 ***** 49111 , 5121111 DEFPROCinit 51121 CLOSE#12I 520 abort%=FALSE 530 DIMopt$(21) ,act%(21) ,label $ (2121121) ,pos%(2111121) 54121 labptr%=I2I,label$(I1I)=""'pos%(I2I)=11I 550 FORpl%=1T02121121:pos%(pl%)=-1,NEXT 56111 FORi%=1T021,READopt$(i%) ,act%(i%) ,NEXT 57111 pos%(1)=-2 58121 ENDPROC

PAGE 134 590 DATAADD,16384,ADN,20480,AND,32768,ASL,45056,ASR, 47104,DCA,28672,DCX,30720,HLT,0 600 DATAINP,49152,JNG,61440,JUN,53248,JZR,57344,LDA, 4096,LSL,40960,LSR,43008 610 DATAORA,36864,OUT,51200,STA,8192,SUB,24576,TAX,12288,TXA,14336 620 : 630 DEFPROCpass1 640 PRINT"PASS 1" 650 scrY.=-1:flag=0:tb=30:stY.=0 660 REPEAT:err=0 670 PROCline:IFerr=3 THEN PRINTin$TAB(30) "Unexpected end of file":abort7.=TRUE:GOT0900 680 IFLEN(in$)(1 THEN 670 690 PRINTin$ 700 st$=LEFT$(in$,4) 710 IFst$="(END" THEN flag=1:GOT0860 720 IFst$=" (STO"THENPROCscrset:GOT0850 730 IFerr=1 THENPRINTin$TAB(tb) "Invalid number":GOT0860

740 IFLEFT$ (st$, 1) =" ("THENPRINTi n$TAB (tb) "Inval id directive":GOT0670 750 lab$=FNchop(LEFT$(in$,7»:op$=FNchop(MID$(in$,8,5»: ad$=MID$(in$,14,7) 760 ad$=FNchop(ad$) 770 o$=LEFT$(op$,3):IF o$="VAR" OR o$="CON" THEN 830 780 PROCfind(op$):IFerr=2 THEN PRINTin$TAB(tb) "Invalid opcode":abortY.=TRUE:fY.=1 790 IFad$=" "THEN820 800 st$=LEFT$(ad$,ll:IF(st$)="A" AND st$(="Z")AND(LEN(ad$»0) THEN PROClabeI2(ad$) 810 PROCgetnumb(ad$):IFerr=2 THEN PRINTin$TAB(tb) "Invalid number":abortY.=TRUE:f7.=1 820 IFlab$=" "THEN840 830 PROClabeI1(lab$) 840 scr%=scr7.+1 850 PRINTSTR$(scrY.lTAB(5l; 860 UNTILflag=1 870 lastY.=scrY.-1

PAGE 135 SS0 IFst:r.(l THEN PRINT"No STORE directive given":abort:r.=TRUE 890 IFst:r.>l THEN PRINTst:r." STORE directives - too many":abort:r.=TRUE 900 ENDPROC 910 : 920 DEFPROCpass2 930 PRINT"PASS 2" 940 PRINT#outl.,firstl.,last:r. 950 scrl.=-1:flag=0:tb=30 960 REPEAT:err=0:addl.=0:opl.=0 97111 PROCline:IFerr=3 THEN PRINT"Unexpected end of file":flag=1:abortl.=TRUE:GOTOl190 980 IFLEN(in$)(l THEN 97111 990 st$=LEFT$(in$,4) 100111 IFst$=" (END" THEN flag=1:GOT01190 1010 IFst$="(STO"THENPROCscrset:GOTOl190 111120 IFerr=l THENPRINT"Invalid number":GOTOl190 111130 IFLEFT$(st$,l)="("THENPRINT"Invalid directive":GOT097111 111140 lab$=FNchop(LEFT$(in$,7»:op$=FNchop(MID$(in$,S,5»: ad$=MID$(in$,14,17) 105111 ad$=FNchop(ad$) 111160 o$=LEFT$(op$,3):IFo$="VAR" THEN add:r.=0:GOTOl140 111170 IF o$="CON" THEN 111(/) 1080 PROCfind (op$): IFerr=2 THEN PRINT" Inval id opcode":abort:r.=TRUE 1090 IFad$= .... THENadd%=0: GOT0114121 11121121 st$=LEFT$(ad$,1): IF (st$>="A" AND st$(="Z") AND (LEN (ad$) >121) THEN addl.=FNl ookup (ad$) : GOT0114121 111121 PRDCgetnumb(ad$):add'Y..=val:IFerr=2 THEN PRINT"Invalid number":abort:r.=TRUE 112121 IF add%>&FFF THEN PRINT"Number too big":aborti.=TRUE:GDT01141il 113111 IF add%>&3FF AND opi.<>2048111 THEN PRINT"Number too big":abort:r.=TRUE 1140 codei.= (opi.+add:r.) AND&FFFF:PROCbinout (code%) 1150 out$=STR$(scr%):sp=S-LEN(out$):out$=out$+STRING$(sp," ")+in$:sp=5111-LEN(out$):out$=out$+STRING$(sp," ")+bin$:PRINTout$

PAGE 136 116111 lo7.=code7. MOD 256:hi7.=code7.DIV 256 1170 BPUT#out7.,lo7.:BPUT#out7.,hi7. 1180 scr7.=scr7.+1 1190 UNTILflag=1 12111111 ENDPROC 1210 : 122111 DEFPROCcat 1230 *. 1240 PRINTTAB(H!lICHR$136CHR$130"No such file!" 1250 PRINTTAB(8) "Press SPACE to continue" 1260 REPEAT:UNTIL GET$=" " 1270 ENDPROC 1280 : 129111 DEFPROCin2 1300 *FX202,32 131111 LOCALch$,ch,p,v 1320 in$="":v=VPOS:p=POS:*FX21,0 1330 REPEAT 1340 ch$=GET$: ch=ASC (ch$) 1350 IFch}96 THEN ch=ch AND&DF 1360 IF ch<32 OR ch}127 THEN 1410 137111 IFch}96 AND ch<123 THEN ch$=CHR$(ch-32) 1380 IFch$=":" THEN PRINTTAB(p,vISTRING$(25," "1:PRINTTAB(p-1,vl":";:GOT01320 1390 IF POS}p OR ch<}95 THEN PRINTch$; 14111111 IF ch=95 AND LEN(in$)}0 THEN in$=LEFT$(in$,LEN(in$)-1) ELSE IF ch<}95 in$=in$+CHR$(chl 141111 UNTIL ASC(ch$)=13 AND LEN(in$)}11I 142111 ENDPROC 143111 : 1440 REM ***** LEVEL 2 ***** 145111 : 1460 DEFPROCfind(op$):REM" 1470op1$=op$:IFLEN(op$)}3 THENop$=LEFT$(op$,3) 1480 h=1:t=21:err=0 149111 p=INT«h+t)/2) 1500 IFh}t THENerr=2:GOT01540 151111 IFop$=opt$(pITHENop7.=act7.(p):GOT0154111

PAGE 137 152~ IFop$

153~ h=p+1:GOT0149~

154~ op1$=op1$+" ":ex$=MID$(op1$,4,2)

155~ IF~ THENopl.=op%+2A11

156~ IF(INSTR(ex$,"X"»)0 THENopl.=op%+2A1~

157~ ENDPROC

158~ : 1590 DEFPROCline

16~~ err=~:in$="":REPEAT:ch$=CHR$(BGET#inl.):in$=in$+ch$: UNTILASC(ch$)=13 OR PTR#inl.=EXT#inl. 1610 IFPTR#inl.=EXT#inl. THEN err=3:abortl.=TRUE:ELSEin$=LEFT$(in$,LEN(in$)-1)

162~ ENDPROC

163~

164~ DEFPROCscrset 1650 p=INSTR

167~ ENDPROC

168~ 1690 DEFPROClabe12(lab$)

17~~ foundl.=~

171~ FORpl%=0TOlabptr% 1720 IFlab$=label$(pll.)THENfound7.=1:pll.=labptr% 1730 NEXT 1740 IFfoundl.=0THENlabptr7.=labptr7.+1:1abel$(labptr7.)=lab$ 1750 ENDPROC 1760 : 1770 DEFPROClabe11(lab$) 1780 foundl.=0 1790 FORpl%=0TOlabptr7.

18~0 IFlab$=label$(pl7.)THENfound7.=1:pos%(pll.)=scr7.:pl7.=labptr7.

181~ NEXT 1820 IFfoundl.=0THENlabptr7.=labptrl.+1:1abel$(labptr7.)=lab$: posl.(labptr%)=scr% 1830 ENDPROC 1840

PAGE 138 1850 DEFFNchop(a$) 1860 REM REMOVE SPACES 1870 IFa$=""THENr$=a$:GOT01920 1880 r$="" 1890 FORp=1 TO LEN(a$) 1900 x$=MID$(a$,p,1):IFASC(x$»32 THEN r$=r$+x$ 1910 NEXT 1920 =r$ 1930 : 1940 DEFFNlookup(a$) 1950 foundX=0 1960 FORplX=0TOlabptrX 1970 IFa$=label$(plXlTHENfoundX=1:1ocX=plX,pl%=labptr% 1980 NEXT 1990 =pos% <1 oc%) 2000 : 201121 DEFPROCbinout(code%) 2020 bin$=1I " 2030 FORI%=15 TO 0 STEP-1 2040 mask%=2A I% 2050 IF (mask% AND code%»0 THEN bin$=bin$+"1" ELSE bin$=bin$+"0" 2060 NEXT 2070 ENDPROC 2080 : 2090 REM ***** LEVEL 3 ***** 2100 : 2110 DEFPROCgetnumb(n$) 2120 IFLEN(n$)=0THENval=0:err=0:GOT02200 2130 n$=n$+" " 2140 n1$=LEFT$(n$,1):err=0:t$=RIGHT$(n$,LEN(n$)-1): t1$=LEFT$(t$,LEN(t$)-1) 2150 IFn1$="@" THEN PROCoct(t1$):GOT02200 2160 IFn1$="$"ORnl$="&" THEN PROChex(t1$):GOT02200 2170 IFn1$="%"THEN PROCbin(tl$),GOT02200 2180 IFn1$)="0" AND n1$<="9" THEN PROCdec(LEFT$(n$,LEN(n$)-1»,GOT02200 2190 err=l

PAGE 139 2212HZJ END PR DC 2210 • 222e REM LEVEL 4 2230 • 2240 DEFPRDCbin(v$) 225[2] REM '1. 2260 err=0.val=0.p=1.v$=v$+" ,. 2270 c$=MID$(v$,p,1) 2280 IFc$=" ,. THEN 232121 2290 IFc$<>"1" AND c$<>"0" THEN err=1:GDTD2320 2300 val=val*2+VAL(c$):IF val<=&FFFF THENp=p+1:GDTD2270 2310 err=1 2320 ENDPRDC 233(2) : 2340 DEFPRDChex(v$) 2350 REM $ or & 2360 err=0:val=0:p=1.v$=v$+" ,. 2370 c$=MID$(v$,p,1) 2380 IFc$=" ,. THEN 2440 2390 c=ASC(c$):IFc<480Rc>70DR(c>57ANDc<65)THENerr=1:GDTD2440 2400 IFc>64THENc=c-55:GOTD2420 2410 IFc<58THENc=c-48 2420 val=val*16+c:IF val<=&FFFF THENp=p+1:GDTD2370 2430 err=1 2440 ENDPRDC 2450 : 2460 DEFPRDCoct(v$) 247121 REM @ 2480 err=l2I:val=0:p=1:v$=v$+" " 2490 c$=MID$(v$,p,1) 2500 IFc$=" ,. THEN2540 251121 IFc$<"0" OR c$)"7"THEN err=1:GDTD2540 2520 val=val*8+VAL(c$):IF val<=&FFFF THENp=p+1:GDTD2490 2530 err=1 2540 ENDPRDC 2550 : 2560 DEFPRDCdec(v$) 257121 err=0:val=0:p=1:v$=v$+" ,.

PAGE 140 2580 c$=MID$(v$,p,l) 2590 IFc$=" " THEN2630 2600 IFc$<"0" OR c$)"9"THEN err=1:GOT02630 2610 val=val*10+VAL(c$):IF val<=&FFFF THENp=p+l:GOT02580 2620 err=1 2631.'! ENDPROC

PAGE 141 Appe>,-,dix -:7

Listing of MAKfi17

10 REM CREATE SCREEN DATA FILE 20 REM (cl A Goodhew 1987 30 CLOSE#0 40 chn=OPENOUT ("D. SCR" l 50 FORb7.=0TO 11 60 FORi7.=0T02:READx:PRINT#chn,x:NEXT:READreg$:PRINT#chn,reg$:NEXT 70 FORi7.=0T022:FORk7.=0T05:READx:PRINT#chn,x:NEXT:NEXT 80 CLOSE#0:END 90 DATA35,10,2, .... ,9,9,6,ACC,14.6,4,STR,1,7,6,INPUT,13,13,6,X,20,7 ,6,ADR,33,7,6,SCR,33,20,6," MAR" 100 DATA21, 23,6, MEMORY, 10,20,6," MDR" ,20,18,6, .. CIR",1,13,6,OUTPUT 110 DATA500,396,500,436,628,436:REM MDR>CIR 120 DATA128,756,128,724,276,724:REM INP>ACC 130 DATA304,692,304,592,236,592:REM ACC>OUT 140 DATA320,398,320,692,320,692:REM MDR>ACC 150 DATA816,520,336,520,336,692:REM .>ACC 160 DATA404,592,368,592,368,692:REM X>ACC 170 DATA456,748,456,788,456,788:REM ACC>STR 180 DATA846,784,1044,784,1044,784:REM ADR>SCR 190 DATA688,460,688,756,688,756:REM CIR>ADR 200 DATA816,520,1072,520,1072,756:REM .>SCR 210 DATA816,520,1072,520,1072,396:REM .>MAR 220 DATA1216,756,1216,690,1196,690:REM SCR>+l 230 DATAl108,690,1088,690,1088,756:REM +l>SCR 240 DATA1232,756,1232,396,1232,396:REM SCR>MAR 250 DATAl152,340,1152,272,876,272:REM MAR>MEM 260 DATA660,272,416,272,416,340:REM MEM>MDR 270 DATA816,460,816,520,816,520:REM CIR>. 280 DATA320,692,320,398,320,398:REM ACC>MDR 290 DATA492,724,556,724,556,620:REM ACC>X

PAGE 142 300 DATA820,756,820,600,980,600:REM ADR>MARl 310 DATA466,396,466,488,656,488:REM MDR>ADRl 320 DATA980,600,980,372,1044,372:REM ADR>MAR2 330 DATA656,488,656,756,656,756:REM MDR>ADR2

PAGE 143 App"",.-,dix El

Listing of MAKhe18

10 REM MAKE HELP FILE 20 REM (c) A Goodhew 1987 30 CLOSElt0 40 chn=OPENOUT("D.HELP") 50 CLOSEltl2l 60 chn=OPENUP ("D. HELP") 7121 FORrec7.=0 TO 10 80 PTRltchn=rec7.*15121 90 READa$,b$,c$,d$,e$ 1121121 PRINTltchn,a$,b$,c$,d$,e$ 110 PRINTa$'b$'c$'d$'e$" 12121 NEXT 130 CLOSE#12I 140 END 150 DATAASSEMBLE,Call the assembler program.,It will produce an OBJECT file from a,SOURCE file generated with WORDWISE., 16121 DATACOMMANDS,List the valid commands. Only the first,three characters are needed., , 170 DATADISSASSEMBLE,This command will ask for the start and,end addresses of a section of memory,and list the instructions/data held,there. 18121 DATAEDIT,Display the contents of a specified,memory

I ocati on and all m~ it to be, "changed. Input in DENARY, BINARY,","OCTAL or HEXADECIMAL." 190 DATAEXECUTE,Run the user program starting from the,requested location in memory." 21210 DATAFINISH,End the simulation.", 21121 DATAHELP,The command whose purpose is required,should follow HELP. ,i.e. HELP EXECUTE, 22121 DATASPEED,Set the simulation speed.,I2I-is slow showing movements between,registers - tap to continue, 1 continuous 2 - is faster. 23121 DATAVALUES,Lists some useful system values.",

PAGE 144 240 DATA*,Allows BBC 'star' commands to be passed,to MOS. Useful for setting up printer,or list a disc catalogue., 250 DATAEXPLAIN,Give the purpose of the program.",

PAGE 145