Microforth Tech Manual for RCA 1802
Total Page:16
File Type:pdf, Size:1020Kb
The contents of this document are the intellectual property of FORTH, Inc. and are protected by copyright. This document is provided free of charge for personal, non-commercial, and academic uses. You may not redistribute this in any form without permission from FORTH, Inc. microFORTH TECHNICAL MANUAL FORTH, Inc. 815 Manhattan Avenue Manhattan Beach, CA 90266 (213) 372- 8493 August 1978 Version 3 fo1· RCA COSMAC Copyright 1976, 1978 by FORTH, Inc. Version 3 (revised Appendices) 9 8 7 6 5 4 3 2 1 This book was produced by use of the textFORTH System. FORTH and microFORTH are trademarks of FORTH, Inc. All rights reserved. No part of this book may be reproduced in any form or by any means, electronic 01· mechanical, including photocopying, recording, or by an inf0t·mation retrieval system, without permission in writing from: FORTH, Inc. 815 Manhattan Avenue Manhattan I3each, CA 90266 TABLEOf CONTENTS 1.0 lNTRODUCTION 2 1 . 1 ElemcnLs of fi'OHTH ?. 1 • 1. 1 Dictionary 3 1 . 1. 2 Stack 3 1. 1.3 Code 4 1. 1. 11 lligh level definitions 4 1 . 1 • 5 Blocks ii l.2 Keyboard Input :.,1· 2.0 USE OF THE STACK 7 2. 1 Parameter Stc1ck 7 2.2 fleturn Stack 12 3.0 NUMBERSAND V/\Rl/lBLES 14 3. 1 Numbers 111 3.2 VAHJJ\BLEsnnd CONSTANTs 16 3.3 Arrnys 17 3. LI USER Variables 18 ii. O ARITHMETIC 19 5.0 COMPILER 23 5. 1 Literals 23 5,2 Logical now 21i 5,3 DO-LOOPs 24 5.3.1 l~xarnples of DO-LOOPs 25 5.ll flEGIN, .. END Loops 29 5.5 Conditionals 29 5.6 Special Loops 31 5. 6 .1 LEAVE 31 5.6.2 ~JHILE 33 5.7 Special Literals 311 5. '(. 1 Use of [ t J 34 5.7.2 Use of IN-LINE 35 5.8 Extending the Compiler 35 5.9 1·'.P.moryUsage and Timing 37 1 microFORTH TECHNICALMANUAi. 6,0 BLOCKI/0 38 6.1 Error Checking 110 'I. 0 TEXT EDlTOH lj 1 7,1 Text Editing Utility 112 'l.2 Program Listing Utility 1111 7.2.1 Index listings Lill 7.2,2 Program screen listings 45 8,0 OUTPUT 46 8.1 Right-Adjusting Numbers 46 8.2 Custom Number ~ormatting 118 8,3 Text Output 50 9,0 FORTHPROGRAMMING TECHNIQUES 52 9. 1 Overlays 52 9.2 Diagnostics 9.3 Testing 9,4 Top-Down Design 56 10.0 THE FORTHDICTIONARY STRUCTURE 58 11,0 THE INTERPRETER 63 11.1 Interpreting a String of Words Typed at the Terminal 63 11.2 Interpreting Source Blocks 6IJ 11.3 Compiling Definitions 65 11.4 Executing Definitions 65 11.5 Inner Interpreter Control 66 12,0 THE ASSEMBLER 68 12,1 Code Endings 70 12.2 Notational Conventions 70 12.3 Macros 73 12.4 Example '{3 12.5 Logical Structures 76 12.6 Device Handlers 78 12.7 Time and Memory Trade-Offs 78 13.0 SPECIAL DEFINING WORDS 80 13.1Useof 81 13. 1. 1 VF.CTOR (31j 13, ·1.2 ARRAY 811 13.2 High-level Defining Words 85 rnicrol"ORTIJ TECHNICALMANUAL 1II. 0 VOCABULARIES 90 15, 0 Tl!E: CROSS COMPIL.EH 95 15.1 Explanation of Terms 95 15.1,1 Cross Compiling 95 15. 1. 2 The Tar·gct System 96 15.1.3 The Host System 97 15. 1, 11 The Nucleus 97 1~.1.5 Defining vs Compiling 93 15,2 Organizing an Application to be Cross Compiled 99 16.0 THE CROSS COMPILERENVIRONMENT 102 16.1 Colon Definitions 1011 16.2 Defining Words 105 16.2,1 VARIABLEand CVARlABLE 105 16.2.2 TABLE 107 16.2.3 CONSTANT 108 16 .2 .11 USER 108 16.2,5 Code Definitions 109 16,2.6 EQU and LABEL 111 17.0 TllE CROSS COMPILlNGPROCESS 113 17.1 Procedure 113 17.2 The Cross Compiler Map 11 Li 17.3 Core Image Output 116 17.4 Program Dumps 117 17.5 Relocating and Expanding the Target Dictionary 118 18,0 EXTENDINGTHE CROSSCOMPILER 119 18.1 Defining Words 119 13.2 Compiling Words 122 19,0 A TYPICAL DEVELOPMENTCYCLE 124 19.1 Research and Design 1211 19.2 Coding and Testing 124 19.3 Cross Compiling 126 19.4 Installation and Checkout 127 Appendix A. microFORTII IMPLEMENTATION ON THE RCA COSMAC l. l DATA FORMAT A - 1 1.2 REGISTER ALLOCATION A - l 1.3 ASSEMBLER MNEMONICS A - ?, 1.3.1 Modifiers of Mnemonics A - 2 1.4 TRANSFERS A - 2 l.5 CODE BEGINNING WORDS A .. 3 1.6 MACROS - EXTENDING THE ASSEMULER A - 4 1.7 USE OF THE ALLOCATED REGISTERS A - 5 1.8 INTERRUPT HANDLING A - 5 1.9 TIMING CHART A - 6 l. 10 USER AllEA MAP A - 8 PREFACE Because of the i mpol'tance of the Technical Manual to progrnm mers, we are revising it as quickly as possible and issuing the revised sections as they are completed. When the revision is complete (in 1979), each microFORTII customer will receive a copy; updates and/or errata sheets will be issued thereafter as needed, The second edition of the Primer and the Appendices in this mnnual (i.e., the CPU-specific prose and both glossaries) reflect the most recent microFOH.'l'H systems. The next item scheduled is an expansion of the CPU-specific glossary to include the cross-compiler; you may request one to be sent at the time of publication by writing to the Editor at FORTH, Inc. In order to make reading our documentation as easy as possible, we at FORTH, Inc. use the following conventions in manuals: 1. All FORTH words that appear in prose passages as examples of commands a1·e enclosed by at least one extra space on each side. Words defined as occasional examples are also set off. 2, In all examples that show stack usage, the top item of the stack appears to the 1·ight (as il does on your terminal screen when you are entering). Additional conventions used in FORTH manuals are those that FORTH prog1·ammers use to make source screens readable. The most basic ai·e: 1. Al though only one space is absolutely necessary between each word of a definition, spacing three times after a new word that is being defined sets off the major components. 2, Double spacing between phrases (logical clusters) of a definition also helps make source text legible. 3. When a definition takes up more than one line, the following lines begin with an indentation of three or more spnces to save the left margin for woNls being defined. For microFOH.TH users we publish three levels of documentation. The m icroFOR TH Prim er covers the bl'Oadest and most basic aspects since it is intended fo1· the newcomer to pl'Ograrn ming to work throuzh before com rnencing study of the m icroFO RTH Technical Manual. The Prim er also serves as a prospectus for experienced progrnm rners to !'Cad quickly in orde1• to spot philosophical differences between FORTH and other high--level lang·uages nnd/or operating systems. The microFOR TH Technical Manual forms the second level of docurn entation. In the four chip-specffic - versions (808 0, 6800, 1802, and Z80), implementation that depends upon hardware is treated in more depth. Besides the differences in chips, variations exist within each chip category for particular development systems on which microFORTH has been produced. These differences are documented in the listings and CPU-specific instructions that are issued with each microFORTH system. When users report especially useful solutions to problems that arise during initial use of microFORTH systems, we share the information in these packets. The documentation of Options likewise accompanies delivery of each particular optional program. Since we want you to make the most of your microFORTH system, we have developed a Hotline service, programming classes, and the FORTH, Inc. Newsletter. During regular business hours a programmer is available to help you with suggestions about troubleshooting. Since all of our programmers work on-site when necessary, at times there will be a slight delay before someone retums your call. Try, therefore, to place your call as soon as you are sure you have a problem. Classes are held at FORTH, Inc. whenever the number of potential students warrants one. Each microFORTH class features an overview and then the focus turns to the specific needs of those who attend. If you would like to participate in such a class, use the Hotline to add your name to the request list for the next scheduling. A new aid, the FOR TH, Inc. Newsletter (And So FORTH ..• ), is being published quarterly. Each customer receives two copies; each isstwf eatures articles on programming. Since the content is intended to reflect user concerns, your questions and suggested will be appreciated. While you are reading any FORTI-I, Inc. manual, we hope you will make notes about questions raised but not answc1·cd, passages that are not clear, and, especially, any mis takes you may find. We include a "Reader Comment form" with both the Primer and the Technical Manual to remind you that we need your feedback in order that we may serve all our users well. microFORTH Technical Manual Pae;e 2 1 . 0 JNTHODUC'l'ION FORTH is a prograrn111ing technique originally designed for real--tirne inte1·active minicomputer applications. In such an environment it offers several advantages: it is interactive, it is compact (uses little memory), and it is very fast. FORTH has been implemented on many minicomputers and has been used in lrnndreds of minicomputer applications.