Implementation of Forth with Floating Point Capabilities on an 8085 System
Total Page:16
File Type:pdf, Size:1020Kb
IMPLEMENTATION OF FORTH WITH FLOATING POINT CAPABILITIES ON AN 8085 SYSTEM / A Thesis Presented to The Faculty of the College of Engineering and Technology Ohio University In Partial Fulfillment of the Requirements for the Degree Master of Science Douglas R. -Graham, March, 1985 OHIO CDNlVERSLTY LIBRARY TABLE OF CONTENTS PAGE CHAPTER 1 INTRODUCTION 1 CHAPTER 2 INTRODUCTION TO FORTH CHAPTER 3 SYSTEM HARDWARE 3.1) The Basic SDK-85 Kit Configuration 3.2) Expanding the Memory 3.3) 82318 Arithmetic Processing Unit 3.4) Zenith Terminal 3.5) System Memory Map 3.6) SDK-85 Kit Monitor Routines 3.6.1) Keypad Operation of the SDK-85 Kit 3.6.2) Terminal Operation of the SDK-85 Kit CHAPTER 4 THREADED INTERPRETERS 4.1) Dic t ionary Space 4.2) Different Types of Threaded Code 4.2.1) Subroutine Threaded Code 4.2.2) Direct-Threaded Code 4.2.3) Indirect-Threaded Code 4.2.4) Token Threaded Code 4.3) Inner Interpreter 4.4) Outer Interpreter CHAPTER 5 OUTER INTERPRETER ROUTINES 5.1) ?SEARCH 5.2) ?NUMBER 5.3) ?EXECUTE 5.4) Other Outer Interpreter Routines 5.4.1) START/RESTART 5.4.2) TYPE 5.4.3) INLINE 5.4.4) ASPACE 5.4.5) TOKEN 5.4.6) QUESTION 5.4.7) $PATCH 5.4.8) *STACK CHAPTER 6 USER INTERACTION WITH FPFORTH 6.1) Number Porma t s 6.2) Log ica 1 Flags 6.3) Constants 6.4) Variables 6.5) Character Strings 6.6) Arrays 6.7) System Variables CHAPTER 7 STACK AND MEMORY REFERENCE OPERATORS 7.1) Data Stack Operators 7.2) Interstack Operators 7.3) Memory Reference Operators PAGE CHAPTER 8 INPUT AND OUTPUT ROUTINES 85 8.1) Single Precision 110 Operators 86 8.2) Double Precision I/O Routines 87 8.3) Floating Point Output Routine 88 CHAPTER 9 ARITHMETIC OPERATORS 9.1) Single Precision Operators 9.2) Double Precision Operators 9.3) Floating Point Operators 9.4) Conversion Routines CHAPTER 10 LOGICAL AND RELATIONAL OPERATORS 10.1) Logical Opera tors 10.2) Single Precision Relational Operators 10.3) Double Precision Relational Operators 10.4) Floating Point Relational Operators CHAPTER 11 LOOP AND BRANCH KEYWORDS 11.1) BEGIN and END Keywords 11.2) IF ELSE THEN Structure 11.3) WHILE Statement 11.4) DO LOOPS CHAPTER 12 DEFINING WORDS AND SYSTEM KEYWORDS 12.1) Defining Words 12.2) Sys tem Keywords CHAPTER 13 FPFORTH PROGRAMMING EXAMPLE CHAPTER 14 CONCLUSION Bibliography Appendix A Chip Pin Outs Appendix B SDK-85 Kit Schematic ~~~endixC Memory Expansion Buffers Schematic Appendix D Added Memory Schematic Appendix E Schematic of 82318 Interface to 80858 Appendix F zenith Terminal Interface Appendix G Outer Interpreter Routines Appendix H FPFORTH Keyword Dictionary LIST OF FIGURES PAGE Fig. APU COMMAND FORMAT 24 Fig. Structure of the APU Stack 26 Fig. Ope rand Formats 26 Fig. APU STATUS REGISTER 28 Fig. Basic SDK-85 KIT MEMORY MAP 3 1 Fig. EXPANDED MEMORY SPACE 3 2 Fig. Dictionary Structure 37 Fig. Primitive and Secondary Code Structures 40 Fig. Subroutine Threaded Code 42 Fig. Direct-Threaded Code 44 Fig. Indirect-Threaded Code 46 Fig. Token Threaded Code 4 7 Fig. Dictionary Bodies of a Primitive and a Secondary 44 Fig. Flowchart of Inner Interpreter 50 Fig. Flowchart of Outer Interpreter 5 5 Fig. RAM Memory Layout 58 CHAPTER 1 INTRODUCTION The FPFORTH system is an extension of the normal FORTH language. FORTH is a threaded interpretive language originally developed by Charles Moore. The language has been used by several organizations as a higher level language that can be used to control real time processes. FORTH has not gained widespread acceptance but has its place in microprocessor systems. Ron Loeliger developed his own version of FORTH in the early seventies. He later wrote a book entitled Threaded Interpretive Languages. The FORTH language described in this book is the basis for the FPFORTH. FPFORTH has expanded Loeliger's language to give it a much more powerful arithmetic capability. Loeliger's FORTH language was extended in the FPFORTH system by adding floating point arithmetic operations. The FP stands for the added feature of floating point arithmetic. The FPFORTH language uses Loeliger's concept of how a threaded interpretive language should work. The main idea behind a threaded code language is how control is passed along through the code. FORTH languages control how the threading of addresses is done through what is called the inner interpreter. The inner interpreter is usually a few very short machine code routines. The FPFORTH language uses an indirect-threaded code form of inner interpreter. The basic idea in an indirect-threaded code interpreter is that the routines consist of a list of addresses for machine code routines. The FPFORTH language is a complete computer language that allows the user to write complex programs. The advantage of FPFORTH over other FORTH like languages is its floating point capabilities. The floating point operations are made possible through the implementation of the 8231A arithmetic processing unit. The 8231A can perform single precision, double precision, and floating point operations. The APU also provides increased speed for all the arithmetic operations. The increase in speed arises from the fact that the arithmetic processing unit performs the math operations in hardware instead of a long software routine. The added features of the 82318 to the FPFORTH system make it possible to write programs that perform much number crunching. The FPFORTH system lends itself very well to performing scientific programming. Programming with the FPFORTH system is extremely different than programming in languages such as Fortran or Basic. There are a couple of reasons for this difference. One reason is the use of a stack to hold the operands used in an operation. The use of a stack gives the language the flavor of reverse polish notation. For users not used to reverse polish notation, it will take time to get used to performing the expressions in this format. The other reason that ~rogrammingon the FPFORTH system is different is that programs are formed from a bottom up procedure instead of the normal top down approach. The reason programs are written in this way is because the FPFORTH language builds on itself. All new instructions written in the language are made up of already existing instructions. The user must therefore start at the lowest level of new instructions to be compiled and work his way up. The user can do this method of stepping his way up until the point is reached when one instruction will perform the operation of a whole program. The FPFORTH System is almost a complete personal computer system. The FPFORTH system lacks two features that keep it from being a complete system. The biggest feature lacking in the system is some form of secondary storage that would allow a user to store already developed instructions or programs permanently. The other feature lacking in the FPFORTH system is an editor. The creation of new instructions is performed interactively with the system. If a user wants to change a previously defined instruction, he will have to reenter the whole definition of the instruction again. Without an editor it is impossible to change part of an instruction already defined. The two missing features just mentioned can be added to the system with the addition of a little hardware and by extending the FPFORTH language. You as the user of the FPFORTH system may feel that the system lacks some of the capabilities you desire. The FPFORTH system is very strong in this point because the system can be expanded to do almost anything. The system is very flexible because of the way the core language can be expanded by a user. The FPFORTH system can have many wide and varied applications. The user can decide on the application and build the FPFORTH language toward meeting the needs of this application. The FPFORTH system is limited only by the imagination of the user in most cases. The FPFORTH system is presented in the following chapters with an emphasis on what the user is able to make the system do. A general FORTH language is described in Chapter 2 to give the reader an idea of how the system works. The reader will also see how the FORTH language was expanded into a more sophisticated arithmetic processing language. The hardware for the FPFORTH system is presented in Chapter 3 before the software is presented because much of the software was written to take advantage of the hardwar2 features. The hardware being described early will give a better view of how the software uses the system hardware. The FPFORTH language is then detailed, starting with the inner workings of the interpreter. After the interpreter is described the FPFORTH instructions are briefly described in chapters broken down according to different types of instruction sets. The different FPFORTH instructions will often be referred to as keywords or routines throughout the text. A keyword is merely an instruction that is available to the user. Chapter 13 shows some examples of the FPFORTH language capabilities and demonstrates some of the keywords that were added to expand the normal FORTH language. The text should give the reader a fairly good understanding of the FPFORTH system, but a prior knowledge of FORTH is very helpful. This text does not try to present the entire use and operation of a FORTH language but give the reader with a knowledge of FORTH the advantages that are available on the FPFORTH system. CHAPTER 2 INTRODUCTION TO FORTH FORTH is an interactive interpretive language that was first developed by Charles Moore.