:II CJD. mD LLI- MOS Microcomputer Division 464 Ellis Street, Mountain View, California 94042 :£ 1977 Fairchild Camera and Instrument Corporation/464 Ellis Street, Mountain View, California 94042/(415)962-5011/TWX 910-379-6435 TABLE OF CONTENTS SECTION PAGE 1.0 INTRODUCTION .............................................. . 1-1 1.1 ASSUMED READER BACKGROUND ....................... . 1-1 1.2 SUPPORTING DOCUMENTATION. . . . .. . . . .......... . 1-1 2.0 THE F8 MICROPROCESSOR SYSTEM ... ...... '" . . . . . . . . . .. . .... ... ..... ......... .. . .. .. . ..... . . . 2-1 2.1 WHAT IS A MICROPROCESSOR . . .. . . . .. . . . . . . . . . ... . . ... . . . . ........ ... ... . . .. .. . . .. ... 2-1 2.2 SOME BASIC CONCEPTS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1 2.2.1 INSTRUCTIONS, PROGRAMS, DATA AND MEMORY .............................. . 2-1 2.2.2 INTERRUPTS ............................ . .......... . 2-2 2.2.3 PROGRAMMABLE CLOCKS. . . . . . . . . . . . . . . . . . . . . . .............. . 2-2 2.2.4 DIRECT MEMORY ACCESS .................................... . 2-2 2.2.5 A COMPLETE MICROPROCESSOR SYSTEM ................. . 2-3 2.3 THE F8 SYSTEM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 2.3.1 CHIP AND I/O PORT SELECTION. . . . . . . . . . . . . . . . . . ..................... 2-4 2.4 THE 3850 CPU. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............................. . 2-4 2.4.1 TIMING. . . . . . . .............................. . . ..................... 2-4 2.4.2 CPU REGISTERS .................................... . .................. 2-6 2.4.3 STATUS. . . . . . .. . . ................................ . 2-6 2.4.4 3850 INPUT/OUTPUT ............................... . 2-7 2.5 THE 3851 PSU....... . ......................... . 2-7 2.5.1 3851 TIMING ........................ _ . . ............. . 2-7 2.5.2 3851 REGISTERS.. . ............................................. . 2-8 2.5.3 3851 INPUT/OUTPUT ............................. . 2-9 2.5.4 3851 LOCAL TIMER AND INTERRUPT. . . . . . . . . . . ........................ . 2-9 2.6 THE 3852 DYNAMIC MEMORY INTERFACE.. . . . ............ . 2-9 2.6.1 3852 TIMING. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ......... . .. ...... 2-9 2.6.2 3852 REGISTERS ....................................... . ........... 2-9 2.6.3 3852 DIRECT MEMORY ACCESS AND MEMORY REFRESH 2-10 2.7 THE 3853 STATIC MEMORY INTERFACE ............................ . 2-10 2.8 THE 3854 DIRECT MEMORY ACCESS ................................................ . 2-11 2.8.1 3854 REGISTERS. . . . . . . . . . . . . . ................... . ..... 2-11 2.8.2 DMA CONTROL CODES ......................... . 2-12 3.0 F8 PROGRAMS . ............... . 3-1 3.1 FLOWCHARTING. ..................................... . ........... . 3-1 3.2 ASSIGNING MEMORY. . .................... . ........ . 3-1 3.3 SOURCE AND OBJECT PROGRAMS. . . .. . .. . . . . . . . . . . . . . .. . ................... . 3-2 4.0 ASSEMBLY LANGUAGE SyNTAX .......................................................... . 4-1 4.1 INSTRUCTION TYPES ........................................ . 4-1 4.1.1 COMMENTS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .............. . 4-1 4.1.2 EXECUTABLE INSTRUCTIONS.. .. .. .. .... .. .. . .. .. .. .. .. . .. ...... .. 4-1 4.1.3 ASSEMBLER DIRECTIVES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .......... . 4-1 4.2 INSTRUCTION FIELDS ................................................................... . 4-1 4.2.1 LABEL FIELD .................................. ............ . .............. . 4-1 4.2.2 MNEMONIC FIELD .............................................................. . 4-2 4.2.3 OPERAND FIELD. . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . ..................... . 4-2 4.2.4 COMMENT FIELD. . ................................ . 4-2 4.2.5 ALIGNING FIELDS .................................................. . 4-3 4.3 LANGUAGE COMPONENTS. 4-4 4.3.1 VALID CHARACTERS .. . 4-4 4.3.2 CONSTANTS ........... . 4-4 4.3.3 SYMBOLS ................. . 4-5 4.3.4 EXPRESSIONS ................ . 4-5 5.0 ASSEMBLER DIRECTIVES . ...................................... . 5-1 5.1 BASE - SELECT LISTING NUMERIC BASE ............................... . 5-1 5.2 DC - DEFINE CONSTANT ............................................... . 5-1 TABLE OF CONTENTS (Cont'd). SECTION PAGE 5.3 EJECT - EJECT CURRENT LISTING PAGE ......................... . 5-1 5.4 END - END OF ASSEMBLY ....................................... . ... 5-2 5.5 EQU - EQUATE A SYMBOL TO A NUMERIC VALUE .. 5-2 5.5.1 A COMPARISON OF THE EQU AND DC DIRECTIVES ....................... . 5-2 5.6 MAXCPU - SPECIFY MAXIMUM CPU TIME ......................... . . .. 5-2 5.7 ORG - ORIGIN A PROGRAM ....................................... . 5-3 5.8 SYMBOL - ASSEMBLER PROVIDE A SYMBOL TABLE .............. . 5-3 5.9 TITLE - PRINT A TITLE AT THE HEAD OF THE ASSEMBLER LISTING ......... . 5-3 5.10 XREF - ASSEMBLER PROVIDE A SYMBOL CROSS REFERENCE LISTING ........... . 5-3 5.11 WHEN TO USE ASSEMBLER DIRECTIVES .......................... . 5-3 6.0 THE INSTRUCTION SET ... .............................. . 6-1 6.1 ADC - ADD ACCUMULATOR TO DATA COUNTER ..... 6-2 6.2 AI - ADD IMMEDIATE TO ACCUMULATOR. 6-2 6.3 AM - ADD (BINARY) MEMORY TO ACCUMULATOR .... 6-3 6.4 AMD - DECIMAL ADD, MEMORY TO ACCUMULATOR 6-3 6.5 AS - BINARY ADDITION, SCRATCHPAD MEMORY TO ACCUMULATOR .. 6-4 6.6 ASD - DECIMAL ADD, SCRATCHPAD TO ACCUMULATOR ......................... . 6-4 6.7 BRANCH INSTRUCTIONS ....................... . 6-5 6.7.1 BF - BRANCH PM FALSE........ . ........... . 6-7 6.7.2 BT - BRANCH ON TRUE. . . .......... . 6-7 6.8 CI - COMPARE IMMEDIATE .................... . 6-7 6.9 CLR - CLEAR ACCUMULATOR. ........... . ......... . 6-7 6.10 CM - COMPARE MEMORY TO ACCUMULATOR ..... . 6-7 6.11 COM - COMPLEMENT .... 6-8 6.12 DCI - LOAD DC IMMEDIATE. 6-8 6.13 01 - DISABLE INTERRUPT. 6-8 6.14 OS - DECREMENT SCRATCHPAD CONTENT .. 6-8 6.15 EI - ENABLE INTERRUPT ............... . 6-8 6.16 IN - INPUT LONG ADDRESS ...... . 6-8 6.17 INC - INCREMENT ACCUMULATOR. 6-9 6.18 INS - INPUT SHORT ADDRESS ....... . 6-10 6.19 JMP - BRANCH IMMEDIATE .. . 6-10 6.20 LI - LOAD IMMEDIATE. . ......... . 6-10 6.21 LIS - LOAD IMMEDIATE SHORT ................. . 6-10 6.22 LlSL - LOAD LOWER OCTAL DIGIT OF ISAR. 6-10 6.23 LlSU - LOAD UPPER OCTAL DIGIT OF ISAR .... . 6-11 6.24 LM - LOAD ACCUMULATOR FROM MEMORY ....... . 6-11 6.25 LNK - LINK CARRY TO THE ACCUMULATOR ...................... . 6-11 6.26 LR - LOAD REGISTER ........ . 6-11 6.27 NI - AND IMMEDIATE. . ........... . 6-11 6.28 NM - LOGICAL AND FROM MEMORY. . . . . . . . . . . . . ............ . 6-12 6.29 NOP - NO OP... . ......................... . 6-13 6.30 NS - LOGICAL AND FROM SCRATCHPAD MEMORY .. . 6-13 6.31 01 - OR IMMEDIATE ........................... . 6-13 6.32 OM - LOGICAL "OR" FROM MEMORY ...... . 6-13 6.33 OUT - OUTPUT LONG ADDRESS ................. . 6-14 6.34 OUTS - OUTPUT SHORT ADDRESS .............. . 6-14 6.35 P! - CALL TO SUBROUT!NE !MMEDLl1.TE ....... . 61 A 6.36 PK - CALL TO SUBROUTINE DIRECT AND RETURN FROM SUBROUTINE DIRECT .. 6-14 6.37 POP - RETuRN ~HOiVl SUHHOU liN!:: ............. . 6-15 6.38 SL - SHIFT LEFT. . . . ............. . 6-15 6.39 SR - SHIFT RIGHT .......................... . 6-15 6.40 ST - STORE TO MEMORY .............................. . 6-15 6.41 XDC - EXCHANGE DATA COUNTERS .......... . 6-16 6.42 XI - EXCLUSIVE OR IMMEDIATE .............. . 6-16 6.43 XM - EXCLUSIVE OR FROM MEMORY .............. . 6-16 6.44 XS - EXCLUSIVE OR FROM SCRATCH PAD ......... . .............. . ... 6-16 TABLE OF CONTENTS (Cont'd) SECTION PAGE 7.0 PROGRAMMING TECHNIQUES. 7-1 7.1 MANIPULATING DATA IN THE SCRATCHPAD .. 7-1 7.1.1 SIMPLE SCRATCHPAD BUFFER OPERATIONS 7-1 7.1.2 INCREMENTING UP, AND DECREMENTING DOWN SCRATCHPAD BUFFERS .. 7-1 7.1.3 USING SCRATCHPAD REGISTERS AS COUNTERS ... 7-3 71.4 USING SCRATCHPAD REGISTERS FOR SHORT DATA OPERATIONS. 7-3 7.2 ROM, RAM AND DATA TABLES .. 7-4 7.2.1 READING DATA OUT OF TABLES IN ROM 7-4 7.22 ACCESSING DATA TABLES IN RAM .... 7-4 7.3 SUBROUTINES ... 7-6 7.3.1 THE CONCEPT OF A SUBROUTINE ...... . 7-6 7.3.2 SUBROUTINE PROGRAM STEPS ...... . 7-7 7.3.3 SIMPLE SUBROUTINE CALLS AND RETURNS .... 7-7 7.3.4 NESTED SUBROUTINES 7-8 7.35 MULTIPLE SUBROUTINE RETURNS .. 7-12 7.3.6 PASSING PARAMETERS 7-13 7.4 MACROS.. . .......... . 7-14 74.1 DEFINING AND USING MACROS ... . 7-14 74.2 MACROS WITH PARAMETERS ... . 7-14 74.3 RULES FOR DEFINING AND USING MACROS .. 7-15 7.4.4 WHEN MACROS SHOULD BE USED .. 7-15 75 JUMP TABLES. 7-15 7.5.1 JUMP TABLE USING JUMP INSTRUCTIONS 7-16 7.52 JUMP TABLE USING ADDRESS CONSTANTS .. 7-16 7.5.3 JUMP TABLE USING DISPLACEMENT TABLES. 7-16 76 STATUS, BITS AND BOOLEAN LOGIC. 7-17 7.61 MANIPULATING INDIVIDUAL BITS .... 7-17 7.6.2 TESTING FOR STATUS. 7-18 7.7 POWERING UP AND STARTING PROGRAM EXECUTION ..... 7-18 8.0 INPUT/OUTPUT PROGRAMMING . ... 8-1 8.1 PROGRAMMED I/O . 8-1 8.1.1 POLLING ON STATUS 8-1 8.1.2 DATA. STATUS AND CONTROLS ..... . 8-2 8.1.3 PARALLEL DATA AND CONTROL PORTS 8-3 8.2 INTERRUPT 1j0 8-3 8.2.1 THE INTERRUPT SEQUENCE ... 8-3 8.2.2 ENABLING AND DISABLING INTERRUPTS 8-4 8.23 INTERRUPT PRIORITIES. . . .......... . 8-4 8.2.4 PROGRAM RESPONSE TO AN INTERRUPT ................. . 8-5 8.2.5 MAKING 3851 PSU INTERRUPT ADDRESS PROGRAMMABLE 8-5 8.2.6 SIMPLE 1j0 INTERRUPTS ........... . 8-5 8.2.7 A SAMPLE PROGRAM .. . 8-6 8.3 LOCAL TIMERS (PROGRAMMABLE TIMERS) .... 8-7 8.3.1 LOCAL TIMER 1j0 PORTS ..... . 8-7 8.3.2 PROGRAMMING LOCAL TIMERS ......... . 8-8 8.3.3 A PROGRAMMING EXAMPLE - THE TIME OF DAY .... 8-8 8.4 DIRECT MEMORY ACCESS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ............. . 8-9 8.4.1 WHEN TO USE DMA . . . . .................... . ....................... . 8-9 8.4.2 PROGRAMMING DMA ............................................................. . 8-10 8.4.3 CATCHING DMA ON THE FLy............................ . .................... . 8-11 9.0 PROGRAM OPTIMIZATION . .............................. " . . .. .. . . . . . . . . . . . .... . . . . . ... . . . . . . . 9-1 9.1 COUNTING CYCLES AND BYTES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-1 9.2 ELEMENTARY OPTIMIZATION TECHNIQUES ....... , ..................... '" . . . . . . . .. . . . . . . . . . . .. 9-1 9.2.1 SCRATCHPAD AND RAM MEMORy..................................................... 9-1 9.2.2 IMMEDIATE INSTRUCTIONS .................. , ...................... , ...... ... .. . . . . . . . 9-1 TABLE OF CONTENTS (Cont'd) SECTION PAGE 9.2.3 SHORT INSTRUCTIONS ................ . 9-7 ~?4 n USf OF OS INSTRUCT!ON TO DECREMENT AND TEST ;:..'-,"7 9.2.5 USE OF THE BR7 INSTRUCTION ................................ . 9-7 9.3 PROGRAMMING FOR SPEED OR MEMORY ECONOMY .......... . 9-2 9.3.1 MACROS AND SUBROUTINES .... 9-2 9.3.2 TABLE LOOKUPS VERSUS DATA MANIPULATION 9-3 10.0 SOME USEFUL PROGRAMS .. ....... . 10-1 10.1 GENERATING TEXT ..... . 10-1 10.1.1 SIMPLE AND DEDICATED TEXT PROGRAMS .... 10-1 10.1.2 UNPACKING DECIMAL DIGITS .. . .. 10-1 10.1.3 VARIABLE TEXT .................... . 10-1 10.2 MULTIBYTE ADDITION AND SUBTRACTION. 10-2 10.2.1 16-BIT, BINARY ADDITION AND SUBTRACTION ..... . 10-2 10.2.2 MULTIBYTE BINARY OR DECIMAL ADDITION AND SUBTRACTION 10-3 10.3 MULTIPLICATION. iO-3 10.4 DiViSiON ...... . 10-5 APPENDIX A BINARY NUMBER SYSTEM. A-l APPENDIX B ASCII CODES ... B-1 APPENDIX C CONVERSION TABLES/TIMER COUNTS ... C-l APPENDIX D INSTRUCTION SUMMARY. D-l LIST OF ILLUSTRATIONS FIGURE PAGE 2-1 Multifunction Logic Device. . ......... . 2-1 2-2 Data and Instruction Paths In a Multifunction Logic Device. 2-1 2-3 Program P Being Interrupted to Execute Program R . . . . . . ........ . 2-2 2-4 Logical Components, Data Paths and Control Paths In any Microprocessor System. 2-3 2-5 F8 Microprocessor System Configurations ............... . 2-4 2-6 Logical Functions of the 3850 CPU .. 2-5 2-7 Instruction Timing .. 2-5 2-8 3850 CPU Programmable Registers 2-6 2-9 Logical Functions of the 3851 PSU .. 2-8 2-10 Logical Functions of the 3852 DMI Device 2-10 2-11 Logical Functions of the 3853 SMI Device ... . 2-11 2-12 Logical Functions of the 3854 DMA Device ....... . 2-12 3-1 Flowchart for a Program to Move Data from One RAM Buffer to Another .. 3-1 3-2 Flowchart for Program to Add Two Multibyte Numbers and Output the Result. 3-2 3-3 Source and Object Programs. . . . . . . . . . . . . . . . . . . . . . . . . . ........ . 3-3 4-1 Four Comment Lines (Shaded; in a Source Program .......... . 4-1 4-2 Label Fields (Shaded) in a Source Program. 4-2 4-3 Mnemonic Field (Vertical Shaded) in a Source Program ........ . 4-2 4-4 Operand Fields (Shaded) in a Source Program .... . 4-3 4-5 Comment Fields (Shaded) in a Source Program .. . 4-3 4-6 Source Program with Unaligned Fields ................... . 4-3 4-7 Symbols in a Source Program ...... . 4-5 5-1 Assembier Directives (Shadedj in a Source Program. 5-1 6-1 Generation of a Displacement Object Program Byte in Response to a Forward Branch. 6-5 6-2 Genel diiull UI d Di:;pidcelTlfli ObJeci Program Byte in Response to a Backward Branch 0-0 TABLE OF CONTENTS (Cont'd) FIGURE PAGE 7-1 Use of H, Q and DCl Registers to Hold Three Buffer Addresses 7-6 7-2 Subroutine, as Compared to a Macro. . . . . . . . . . ........ . 7-7 7-3 Scratchpad Stack .......... . 7-1C 8-1 Daisy Chaining and Interrupt Priority Determination ... 8-4 8-2 Two Levels of Interrupt. .. . ............ . 8-4 8-3 Two Devices Servicing a Keyboard to Cassette Application .. 8-6 8-4 How BUFC and BUFD are used to Control DMA Operations 8-lC 9-1 Counting Cycles and Bytes ... 9-2 LIST OF TABLES TABLE PAGE 2-1 Summary of Status Bits. . . ......... . 2-6 2-2 Hexadecimal Addresses of Four I/O Ports used as Registers by Four 3854 DMA Registers .. 2-11 4-1 Summary of Restricted Characters 4-4 6-1 Operand Symbols .............. . 6-1 6-2 Operands Referencing Scratchpad Memory, as Specified by Symbol Sreg 6-1 6-3 Branch Conditions 6-6 6-4 Branch Conditions for BF Instruction 6-6 6-5 Branch Conditions for BT Instruction 6-7 6-6 I/O Port Address Assignments .. 6-9 6-7 LR Instruction Operand Definitions ... 6-1 ~ 7-1 Scratchpad Memory Utilization. . . . . . . . . . . . . . . . . . ......... . 7-1 7-2 Use of a Memory Stack for Executing Multiple Level Subroutines ............ . 7-1C 8-1 Contents of Interrupt Control I/O Ports 8-4 v INTRODUCTION This manual explains how to write programs for the Fairchild 1.1 ASSUMED READER BACKGROUND F8 microprocessor system, and how these F8 programs cause a microprocessor system to function as a discrete logic This manual has been written for logic designers with little replacement. or no background in programming. The Fairchild F8 family of logic devices consists of a Central The reader is assumed to understand the following: Processing Unit and a number of complementary devices, manufactured using n-channel Isoplanar MOS technology. 1) Binary, octal, binary coded decimal and hexadecimal Components of the F8 family include the following devices: number systems 2) Signed and unsigned binary arithmetic 1) The 3850 Central Processing Unit (CPU) 3) Boolean logic 2) The 3851 Program Storage Unit (PSU) 4) ASCII and EBCDIC character codes 3) The 3852 Dynamic Memory Interface (DMI) 4) The 3853 Static Memory Interface (SMI) For readers without the assumed background, a summary of 5) The 3854 Direct Memory Access (DMA) this basic information is given in Appendix A. Complete microprocessor based systems may vary in size and 1.2 SUPPORTING DOCUMENTATION complexity from as little as two devices-the 3850 CPU and the 3851 PSU-to large systems incorporating the above The following manuals provide additional information on the five devices, plus any standard static and/or dynamic Random F8 microprocessor: Access Memory (RAM) devices. 1) F8 Circuit Data Book which provides electrical param- eter data for all Fairchild F8 Microprocessor devices. The following are some general characteristics of this micro- 2) F8 Timeshare Operating Systems Manual which ex- processor device set: plains how to assemble and debug F8 Microprocessor programs on NCSS and GE Timeshare Networks. • 8-bit data organization 3) F8 Circuit Reference Manual which describes the • 2 #1 s instruction cycle time interactive timing and signal sequences which occur • Over 70 microprocessor instructions between devices in the F8 Microprocessor family. • 64 general purpose registers in the CPU • Binary and decimal arithmetic, and logic functions 4) F8S and F8SEM Users Manuals which describe how • Up to 65,536 bytes of ROM and RAM, in any combination to assemble and debug microprocessor programs on • No need for special external interface devices the F8S and F8SEM hardware modules. • Internal, programmable real time clocks • Internal power on and reset logic 5) F8 Formulator Users and Reference Manuals which • Multi-level interrupt handling describe how to use and maintain Fairchild's F8 • Clock and timing circuits Formulator developmental hardware. 1-1 THE Fa MICROPROCESSOR SYSTEM The purpose of a microprocessor system is to replace discrete In order to function, the multifunction logic device will need logic; but in order to understand why a microprocessor system the following parts: is effective as a logic design tool, it is first necessary to understand what is in a microprocessor system. A) An Arithmetic Logic Unit (ALU), containing the neces- sary basic logic functions. B) A control unit, which decodes instructions and enables 2.1 WHAT IS A MICROPROCESSOR? elements of the ALU, as needed. After a product has been fabricated using discrete logic com- C) Registers to hold instruction codes and data, as needed. ponents, it consists of one or more logic cards; each card may D) Data paths within the CPU, and between the CPU and be visualized as generating a variety of signals output at the external devices. card edge, based on signals input at the card edge. The logic devices on the card are specifically selected and sequenced to generate the required product. Parts A), B), C), and D) are the basic components of any Central Processing Unit (CPU). A CPU must be the focal point of any computer-maxi, mini or micro. If the same product is implemented using the F8 micropro- cessor, the F8 CPU and its five supporting devices can be Referring to Figure 2-1, where do "instructions" and "data made to function in the same way as anyone of many mil- in" come from, and where will "data out" go? There are two lions of different discrete logic device combinations. In other possibilities: memory or external devices. words, the F8 CPU, optionally in conjunction with the sup- porting devices, has the capacity to duplicate the performance Refer to Figure 2-2. Memory is a passive depository of infor- of any discrete logic design, limited only by speed consider- mation where data or instruction codes may be stored. ations. F8 microprocessor systems have a 2 j.Ls instruction Memory must be divided into individually addressable loca- cycle time. The functions that will be performed by the F8 tions, each of which can store one element of instruction microprocessor system are established by a sequence code or one element of data. In an F8 system, each individ- of "instructions", stored in a memory device as a sequence ually addressable location will be an 8-bit data unit (a byte), of binary codes. Taken as a whole, the sequence of instruc- since the F8 is an 8-bit microprocessor. tions are referred to as a "stored program". MEMORY 2.2 SOME BASIC CONCEPTS Any logic device may be reconstituted from some or all of the following basic functions: 1) 8inary addition 2) The logical operations AND, OR and EXCLUSIVE-OR 3) Shifts and rotates of binary digit sequences which MULTIFUNCTION lOGIC are being interpreted as numerical entities (e.g., a DEVICE byte = eight bits). (CPUI A general purpose logic device can be created by implement- ing the basic functions listed above on a single chip. If the single chip is to duplicate the performance of other logic de- vices, it must be provided with a sequence of instructions that enable the required logic in the proper order, plus aa stream I/O PORT EXTERNAL DEVICES 1;0 PORT of data that is operated on by the specified logic. This is illustrated in Figure 2-1. Fig. 2-2. Data and Instruction Paths in a Multifunction Logic Device INSTRUCTIONS IN I "External devices" refer to any data source or destination beyond the perimeter of the microprocessor system. Drawing an analogy with a logic card, "'external devices" will refer to the world beyond the card edge connector. Data passes be- tween the microprocessor system and external devices via MULTIFUNCTION Input/Output (I/O) ports. LOGIC DEVICE (CPUI 2.2.1 Instructions. Programs. Data and Memory For a microprocessor to perform any specified operation, it will receive and process a sequence of instructions. The se- Fig. 2-1. Multifunction Logic Device quence may be very long-numbering even into the thousands 2-1 of instructions. A sequence of instructions that can be taken In Figure 2-3, P represents the program performing numerical as a unit is called a program; the purpose of this manual is operations on the data. Data is collected by repeated execu- to describe how a program is constructed out of a sequence tion of program R. Events occur as follows: of instructions. 1) Program P is executing. Data may (and usually will) be stored in memory. In fact, the 2) When the external instrument has data which it is 255 possible combinations of eight binary digits (Oi byte) may ready to transmit, it sends an interrupt signai iii to represent any of the following types of information: the microprocessor, along with the starting address of program R. 1) An instruction code 3) Upon receiving interrupt signal I, the microprocessor 2) Numeric or address data that is part of an instruction's does some elementary "housekeeping"; for example, code it saves the address of the program P instruction it 3) Numeric or address data that is independent of was about to execute, plus any intermediate data being instruction codes held in temporary storage registers. 4) A coded representation of a letter of the alphabet, digit 4) The microprocessor completely executes program R. or printable character 5) Upon completion of program R execution, the micro- processor restores values saved in step 3, then con- It would be impossible to determine the content of any tinues program P execution from the point where memory byte by random inspection. This does not cause prob- interrupt I occurred. Thus execution of program P ap- lems, since a program will occupy one or more segments of pears to have gone into "suspended animation" for contiguous memory bytes, and data resides in blocks of the duration of program R execution. memory as assigned by the programmer. The sequence of events illustrated in Figure 2-3 is quite com- mon in microprocessor applications, and is called an external 2.2.2 Interrupts interrupt. Interrupt programming is described in Section 8.2. The number of programs which may be stored in memory is limited only by the amount of memory available for program 2.2.3 Programmable Clocks storage. If ten programs were stored in memory, by simply There are many microprocessor applications in which It IS identifying one program, the same microprocessor system important that the microprocessor system be synchronized could be made to function in one of ten different ways. with the real time of the outside world. Such synchronization is accomplished using programmable clocks, which are reg- If a microprocessor has more than one program available for isters that count at a known rate. When the shift register execution, how is the one program which is to be executed counts to zero, the event is marked by an interrupt (as de- identified? There are two separate and distinct ways in which cribed in Section 2.2.2); in this case the interrupt is defined a program may be identified for execution: as a "time out" interrupt. Since the rate at which the clock register counts will be known for any microprocessor system, A) Program identification may itself be a programmed setting a real time interval simply involves loading the function; for example, each program, upon completing register with the correct initial count. execution, may identify the next program to be exe- cuted. The key to this method of program identification 2.2.4 Direct Memory Access is that it is internally controlled, within the logic of Notice from Figure 2-2 that data may be input to the micro- the microprocessor system. processor from memory or from an external device, via an I/O port. B) Programs may be called into execution by external devices; this may happen even if another program is It is easy to imagine how, in many applications, data will be in the middle of execution. For example, take the sim- transferred from an external device, via an I/O port and the ple case of a microprocessor that is recording data CPU, to memory; the data will then be accessed from memory input by an external instrument; while receiving data in the normal course of program execution. from the external instrument, the microprocessor per- forms numerical operations on the collected data. It makes little sense to tie up the logic of the CPU while shunt- Program executions are illustrated in Figure 2-3. ing data from an I/O port to memory; therefore, provisions are made for Direct Memory Access (DMA), whereby data is moved between memory and an "I/O port". bypassing the CPU entirely. The DMA "I/O port" is called a "DMAchannel". In order to implement DMA, the microprocessor system must have iogic (outside the CPU) which provides the follOWing three pieces of information: 1) A starting memory address for a data block. 2) A byte length for the data block. 3) The direction of the data movement. If the microprocessor has this logic, data may be transferred between memory and an I/O port independent of, and in Fig. 2·3. Program P Being Interrupted to Execute Program R parallel with, unrelated CPU-memory operations. 2.2.5 A Complete Microprocessor System 4) 1/0 ports, through which bidirectional data pas- ses between the microproc'essor system and external devices. 5) DMA logic, which provides a direct data path between To summarize, a complete microprocessor system will have memory and external devices, bypassing the CPU. the following logical components: 6) Interrupt logic, which causes the CPU to temporarily suspend current program execution. Along with each interrupt request signal, interrupt logic identifies the 1) A CPU, which is the multifunction logic device of the program which is to implement operations required by system. the source of the interrupt. 2) Memory (of various types and combinations), in which 7) Real time clock logic, which synchronizes the entire programs and data are stored. microprocessor system with the real outside world by 3) Memory interface logic which identifies: generating interrupts at variably definable time a) the next memory location which must be accessed intervals. to fetch instruction codes for the CPU, and b) the memory location from which a byte of data will Figure 2-4 illustrates these seven logical components, with be read, or to which a byte of data will be written. associated data flow paths. _OATAPATHS _---+_ CONTROL PATHS REAL TIME ~ ~ ,- CLOCK ,/ ......._--'""- / / I I ~'l- / I Q / I / / / / / / I MEMORY I I I \ \ \ \ CPU MICROPROCESSOR SYSTEM OUTSIDE WORLD Fig. 2·4. Logical Components. Data Paths and Control Paths in any Microprocessor System 2-3 2.3 THE F8 SYSTEM 2.3.1 Chip and I/O Port Selection There is no one-for-one correspondence between the logical Every 3851 PSU has two permanent select codes-a chip components of a microprocessor system, as illustrated select code and an liD port select code. in Figure 2-4, and the devices of the F8, or any other micro- processor product. In fact, it is counter-productive to extend The 3851 PSU chip select code is a six digit binary number, the concept of isolating functions on separate devices which is always the highest six bits for memory addresses because it reduces the flexibility of a microprocessor system on that device: to satisfy simple, as well as complex, applications needs. More than any other microprocessor product, the F8 combines 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 many functions on single chips, thus allowing simple systems to be implemented with as few as two devices, and complex IxlxlxlxlxlxlAIAIAIAIAIAIAIAIAIAI systems to be implemented using many devices. "-v-" Chip Select Figure 2-5 illustrates the way in which F8 microprocessor system devices interconnect to give a variety of system Memory Address for Individual Bytes on Chip configurations. The 3851 PSU liD port select code is also a six digit binary The simplest F8 system contains one 3850 CPU and one number, and is independent of the chip select code. The I/O 3851 PSU. port select code is always the highest six bits for liD port numbers on that device: Another very simple F8 system consists of one 3850 CPU, 76543210 plus either one 3852 OMI interfaced to a single dynamic memory, or one 3853 SMI interfaced to a single static IxlxlxlxlxlxlAIAI memory device. "-v-" 1;0 Port Select A fully expanded F8 system may have one 3850 CPU, one 3852 OMI and one 3853 SMI device, up to four 3854 OMA 1;0 Port Number devices, plus 3851 PSU and static or dynamic memory devices in any combination, providing not more than a combined total The 3852 OMI and 3853 SMI devices have a fixed (pre- of 65,536 bytes of memory are directly addressed by the 3850 assigned) liD port select code, but have no on-board chip CPU. It is possible to address more than 65,536 bytes of select code. memory using special techniques which are described in the F8 Circuit Reference Manual. The dynamic andlor static memories associated with the 3852 OMI and 3853 SMI derive their select function from 11,0 ,'" external logic. This allows the system designer complete II '7 ,{M LOAD CONTENTS OF MEMORY BYTE ADDRESSED BY DCO 0108 2C SIX DC EXCHANGE DCO AND DCl 010C 17 SEVEN ST~ STORE ACCUMULATOR IN MEMORY BYTE ADDRESSED BY DCO 0100 2C EIGHT XDC EXCHANGE DCa AND DC 1 alOE 31 NINE DS ~ 1 DECREMENT SCRATCH PAD BYTE 1 010F 94 BNZ LOOP IF SCRATCH PAD BYTE 1 IS NOT ZERO, RETURN TO LOOP 0110 FA END Fig. 4-2. label Fields (Shaded) in a Source Program Assembler BUFA EQU H'08OO' SET THE VALUE OF SYMBOl BUFA Directives { BUFB EQU ORG H'Q8AO' H'0100' SET THE VALUE OF SYMBOL BUFB 0100 2A ONE DCI BUFA SET DCa TO BUFA STARTING ADDRESS 0101 08 0102 00 0103 2C lVVO XDC STORE IN DCl 0104 2A THREE DCI BUFB SET DCa TO BUFB STARTING ADDRESS 0105 08 0106 AO 0107 2C FOUR .. t H'8C' LOAD BUFFER LENGTH iNTO ACCUMULATOR 0108 so 0109 51 FIVE LR l.A SAVE BUFFER LENGTH IN SCRATCHPAD BYTE 1 010A 16 LOOP Lr..,1 LOAD CONTENTS OF MEIViORY BYTE ADDRESSED BY Dca 0108 2C SIX XDC EXCHANGE DCO AND DCl 010C 17 SEVEN ST STORE ACCUMULATOR IN MEMORY BYTE ADDRESSED BY DCO 0100 2C EIGHT XDr. FXr.HANGF nco AND DC1 alOE 31 NINE OS DECREMENT SCRATCHPAD BYTE 1 010F 94 BNZ LOOP IF SCRATCHPAD BYTE 1 IS NOT ZERO, RETURN TO LOOP 0110 FA Assembler - END ~ Directive- Object Program Fig. 4-3. Mnemonic Field (Vertical Shaded) in a Source Program field is ignored by the Assembler and generates no object code. The comment field must be separated from the operand field (or the mnemonic field if there is no operand field) by at least one blank; it continues to the end of the text line. Figure 4-5 identifies the comment fields of a program. BUFA EQU H'0800' SET THE VALUE OF SYMBOL BUFA BUFB EQU H'OBAO' SET THE VALUE OF SYMBOL BUFB ORG H'Ol00' ONE DCI BUFA SET DCO TO BUFA STARTING ADDRESS TWO XDC STORE IN DCl 4.2.5 Aligning Fields THREE DCI BUFB SET DCO TO BUFB STARTING ADDRESS Figure 4-6 illustrates the source program of Figures 4-1 to FOUR LI H'BO' LOAD BUFFER LENGTH INTO ACCUMULATOR FIVE LR l.A SAVE BUFFER LENGTH IN SCRATCHPAD BYTE 1 4-5, with a single space code separating each field of every LOOP LM LOAD CONTENTS OF MEMORY BYTE ADDRESSED BY DCO instruction. SIX XDC EXCHANGE DCO AND DCl SEVEN ST STORE ACCUMULATOR IN MEMORY BYTE ADDRESSED BY DCO EIGHT XDC EXCHANGE DCO AND DCl NINE OS 1 DECREMENT SCRATCHPAD BYTE 1 BNZ LOOP IF SCRATCH PAD BYTE 1 IS NOT ZERO. RETURN TO LOOP Clearly the program in Figure 4-6 is hard to read. For clarity END it is recommended that all fields be aligned within character positions of every line; here is one possibility: Label field: Characters 1 to 6 Mnemonic field: Charcters 7 to 11 Operand field: Characters 12 to 19 Comment field: Characters 20 to 72 Fig. 4-6. A Source Program with Unaligned Fields BUFA EQU H'0800' SET THE VALUE OF SYMBOL BUFA BUFB EQU H'OSAO' SET THE VALUE OF SYMBOL BUFB ORG H'01oo' 0100 2A ONE DCI BUFA SET DCO TO BUFA STARTING ADDRESS 0101 OS 0102 00 0103 2C 1W0 XDC STORE IN DCl 0104 2A THREE DCI BUFB SET DCO TO BUFB STARTING ADDRESS 0105 OS 0106 AO 0107 20 FOUR LI H'SO' LOAD BUFFER LENGTH INTO ACCUMULATOR 010S SO 0109 51 FIVE LR 1,A SAVE BUFFER LENGTH IN SCRATCHPAD BYTE 1 010A 16 LOOP LM LOAD CONTENTS OF MEMORY BYTE ADDRESSED BY DCO 010B 2C SIX XDC EXCHANGE DCO AND DCl 010C 17 SEVEN ST STORE ACCUMULATOR IN MEMORY BYTE ADDRESSED BY DCO 010D 2C EIGJ.iT XDC EXCHANGE DCO AND DCl 010E 31 NINE DS 1 DECREMENT SCRATCHPAD BYTE 1 010F 94 BNZ lOOP IF SCRATCHPAD BYTE 1 IS NOT ZERO, RETURN TO LOOP 0110 FA END Fig. 4-4. Operand Fields (Shaded) in a Source Program BUFA EQU H'08oo' SET THE VALUE OF SYMBOL BUFA BUFB EQU H'OBAO' SET THE VALUE OF SYMBOl BUFB ORG H'Oloo' 0100 2A ONE DCI BUFA SET oeo TO BUFA STARTING ADDRESS 0101 08 0102 00 0103 2C 1W0 XDC STORE IN DC1 0104 2A THREE DCI BUFB SET DCO TO BUFB STARTING ADDRESS 0105 08 0106 AO 0107 20 FOUR U W80' LOAD BUFFER LENGTH INTO ACCUMULATOR 0108 80 0109 51 FIVE LR l,A SAVE BUFFER LENGTH IN SCRATCHPAD BYTE 1 010A 16 LOOP LM LOAD CONTENTS OF MEMORY BYTE ADDRESSED BY oeo 0108 2C SIX XDC EXCHANGE DCO AND DCl 010C 17 SEVEN ST STORE ACCUMULATOR IN MEMORY BYTE ADDRESSED BY DCO 0100 2C EIGHT XDC EXCHANGE DCO AND DCl OlOE 31 NINE OS 1 DECREMENT SCRATCHPAD BYTE 1 010F 94 BNZ LOOP IF SCRATCHPAD BYTE 1 IS NOT ZERO. RETURN TO LOOP 0110 FA END Fig. 4-5. Comment Fields (Shaded) in a Source Program 4-3 4.3 LANGUAGE COMPONENTS HEXADECIMAL A hexadecimal number consists of a string of from one to 4.3.1 Valid Characters four numeric characters and/or alphabetic characters (A to F inclusive) enclosed in single quotes and preceded by an H. The F8 Assembler accepts all characters available on an input No blanks are allowed within the number or between the H terminal as valid characters. Alphabetic (A-Z), numeric (0-9), a~d the ~umber. Hex:adeGimal nl.lmhers in the rclnge H'O' to and special (aU other terminal characters) characters are va!:d H'FFFF' are valid. Signed hexadecimal numbers are invalid. when correctly used; in other words, there is no character which will always be invalid. Examples: Some characters have been assigned special meaning; the Valid Invalid Reason invalid use of these special characters is therefore restricted, as H'12' 'ABCD' No preceding H described in the following sub-sections, and summarized in H'ABCD' H'-12' Invalid character H Table 4-1. H'lAFO' H'12.A3' Invalid character (.) Restricted BINARY Character Function Example A binary number consists of a string of from 1 to 16 ones or zeroes, enclosed within a pair of quotes and preceded by a B. D Specify decimal constants D'1234' No blanks are allowed between the apostrophe symbols, or H Specify hexadecimal constants H'123A' between the B and the number. If there are less than 16 B Specify binary constants B'10011101 ' binary digits, leading 0 digits are assumed. 0 Specify octal constants 0'23714' C Specify character constants C'VALID' Examples: T Specify timer counts T'123' * Current memory location *+3 Valid Invalid Reason invalid * Multiplication sign (VAL*2) Exponentiation sign (VAL **2) B'101101' B1011101 No quotes ** B'0010' B'10110111011100101 ' Too many digits + Addition sign I (VAL+2) B'10021' Invalid digit (2) - Subtraction sign (VAL-2) / Division sign (VALl2) ( Beginning of an expression (VAL+2) OCTAL ) End of an expression (VAL+2) An octal number consists of a string of from one to six nu- Separate operands A,l meric digits, excluding 8 or 9, enclosed between single quotes and preceded by an O. Octal numbers in the range 0'0' to Table 4-1. A Summary of Restricted Characters 0'177777' are valid. Signed numbers are invalid. Examples: Restricted characters may be used in any way that does not directly conflict with the restricted use. Valid Invalid Reason invalid 0'17243' 017243 No quotes 0'2462' '2462' No preceding 0 4.3.2 Constants 0'177272' 0'277272' Value exceeds maximum Constants represent quantities or data that do not vary in 0'23714' 0'23914' Invalid character (9) value during the execution of a program. The syntax for constants' representation is described below. CHARACTERS Any characters (other than the single quote character) may be enclosed in single quotes and preceded by a C, in which DECIMAL case the characters will be interpreted as ASCII characters A decimal number consists of a string of from one to five nu- (see Appendix B). meric characters. The number may be preceded by a minus "-" sign but no blanks are allowed within the number. The value of a decimal digit must fall in the range +32767 to Examples: -32768. Optionally, decimal numbers may be enclosed between single quotes. preceded by a D character. Valid Invalid Reason invalid CVALID' VALID' No preceding C C'12345' C12345' No initial single quote Examples: C'NAME' C"NAME" Double quotes Valid Invalid Reason invalid 12 123456 Too many digits -123 123- Invalid character 12345 12.3 Invalid character TIMER COUNTS -5432 12}S3 Invalid character As described in Section 2, the 3851 PSU and the 3853 23456 65432 Above +32767 Memory Interface device each have a timer which may be D'12' '12'D D does not precede loaded under program control. Depending on the value loaded number in quotes into the timer, variable delays may be programmed, at the D'23456' D'65432' Above +32767 end of which a timer interrupt is transmitted to the 3850 CPU. 4-4 Timer counts may be entered, as decimal numbers between Figure 4-7 illustrates a number of symbols in a source pro- a and 255, enclosed in single quotes and preceded by a T. gram. Observe that symbols may appear in the label field or The assembler converts the timer count to the exact binary the operand field of an instruction. code which (based on the timer logic) will generate the re- quired time delay. Appendix C provides the exact codes that correspond to each timer count entered using 1'nn' format. When a symbol appears in the label field of an instruction, it is either assigned a value by that instruction (EQU) or it is Recall that the exact time delay is given by the equation: assigned a value equal to the location of that instruction, depending on the nature of the instruction. Sections 5.5 Delay = (timer counts) * 31 * Clock period and 5.7 describe how this is done. Examples: Valid Invalid Reason invalid When a symbol appears in the operand field of an instruction, 1'25' T25 No single quotes the assembler substitutes the assigned value for the symbol. 1'127' 1'12A' Invalid character (A) For example, instruction THREE in Figure 4-7 causes the value 1'254' 1'264' Count too high associated with symbol BUFB to be loaded into the DCa reg- isters of all memory and memory interface devices. Instruc- 4.3.3 Symbols tion THREE therefore generates the following object code: A symbol is a character string of from one to four characters, the first of which must be alphabetic (A-Z). A symbol may have any number of characters; however, only the first four characters are interpreted by the assembler. A symbol can- not have the exact appearance of a number, as specified in Section 4.3.2. 2A Since a blank space acts as a field delimiter, it cannot be present as a character within a symbol. 08 Examples: AO Valid Invalid Reason invalid ABCD ABt:SCD A blank present. AB is the assumed symbol AB12 12AB A numeric first character 4.3.4 Expressions 012 0'12' Would be interpreted as Expressions may appear in the operand field of an instruction, decimal 12 and are evaluated by the assembler to generate a constant SYMBOLA SYMBOLB Both symbols are SYMB which is used in the object program. BUFA EQU H'OSOO' SET THE VALUE OF SYMBOL BUFA BUFB EQU H'OSAO' SET THE VALUE OF SYMBOL BUFB ORG H'0100' 0100 2A ONE DCI BUFA SET DCO TO BUFA STARTING ADDRESS 0101 OS 0102 00 0103 2C TWO XDC STORE IN DCl 0104 2A THREE DCI BUFB SET DCO TO BUFB STARTING ADDRESS 0105 OS 0106 AO 0107 20 FOUR LI H'SO' LOAD BUFFER LENGTH INTO ACCUMULATOR 010S SO 0109 51 FIVE LR l.A SAVE BUFFER LENGTH IN SCRATCHPAD BYTE 1 010A 16 LOOP LM LOAD CONTENTS OF MEMORY BYTE ADDRESSED BY DCO 010B 2C SIX XDC EXCHANGE DCO AND DCl 010C 17 SEVEN ST STORE ACCUMULATOR IN MEMORY BYTE ADDRESSED BY DCO 010D 2C EIGHT XDC EXCHANGE DCO AND DCl OlOE 31 NINE DS 1 DECREMENT SCRATCHPAD BYTE 1 010F 94 TEN BNZ LOOP IF SCRATCHPAD BYTE 1 IS NOT ZERO. RETURN TO LOOP TL 0110 FA END Object Program Hexadecimal memory address in which object code is stored. Fig. 4-7. Symbols in a Source Program 4-5 Unlike higher level languages, expressions do not represent 3) * for multiply equations to be resolved at execution time. By the time a 4) / for divide program is executed, every expression in the source program 5) ** for exponentiate will have been converted (by the assembler) to a constant in 6) ( and) to enclose expression and subexpressions, the object program. which are to be evaluated as a constant. An expression can have three types of numeric value, linked Expressions and subexpressions must be enclosed in brackets. by six types of algebraic symbol. An exception is the simple (and most frequently used expression: These are the three types of numeric value: *±numeric constant 1) Any symbol, as defined in Section 4.3.3. Subexpressions may be nested ten deep. 2) Any constant numeric value, as defined in Section 4.3.2. Use of complex expressions is pointless, since it is almost as 3) An asterisk (*), which will be interpreted as having the simple to evaluate the expression and use the evaluated re- value of the memory address into which the first ob- sult in the object program. The one time when expressions ject program byte for this instruction will be stored. are useful is when calculating instruction addresses. Refer- ring to Figure 4-7, the following are substitutes for LOOP in These are the six algebraic symbols that are recognized: the operand field of instruction TEN: 1) + for add *-5 (equals H'010F' - 5) 2) - for subtract (FOUR+3) (equals H'01 01' + 3) 4-6 , ASSEMBLER DIRECTIVES Assembler directives are instructions to the assembler; as 5.2 DC - DEFINE CONSTANT such, they generate no object code. Assembler directives This directive causes the assembler to generate a one or two provide the assembler with the following three types of byte constant. The DC directive is an exception in that information: it causes one or two bytes of object code to be generated- identical to the one or two byte constant specified. 1) Values of symbols 2) How memory is to be mapped The DC directive will usually have a label, which becomes the 3) Assembly listings print options symbol via which the constant is referenced. The general format of the DC directive is: Assembler directives are described in alphabetic order on the Label Mnemonic Operand following pages. A summary of the assembler directives LABEL DC VALUE which are necessary, versus those which are optional, is given LABEL is any valid symbol. The label is optional. in Section 5.11; hints on good programming practice are VALUE is any valid numeric value as described in Section also provided. 4.3.2. 5.1 BASE - SELECT LISTING NUMERIC BASE For examples of DC directive use see Section 7.2.1. See This is an optional directive which specifies the number sys- also Section 5.5.1 for a discussion of when DC directives tem in which object program codes will be printed on the are used and when EQU directives are used. assembler printout. The following three options are provided: 5.3 EJECT - EJECT CURRENT LISTING PAGE This directive has no effect on the program being assembled. Label Mnemonic Operand Comment It controls the line printer on which the assembler is printing BASE HEX Select hexadecimal output out an assembly listing. BASE OCT Select octal output BASE DEC Select decimal output When the assembler encounters EJECT in the mnemonic field of an instruction, it immediately advances the line printer If no base is specified, decimal output will be selected by de- paper to the top of the next page. fault. If a base is specified, one BASE instruction should ap- pear at the beginning of the program, as illustrated in If the assembler is not printing out an assembly listing, it will Figure 5-1. ignore the EJECT directive. The format of the EJECT directive is: Since hexadecimal notation is the standard for the Fa micro- processor, it is strongly recommended that programmers use Label Mnemonic Operand this numeric option. EJECT nUE';'.':i~~~~,rtiMtlV~ti~~~a~,;~1·y;·;';(·,:'·l,:,1~,,·' " 'MAXcroso,itMilOF !;)pSECONDS'CN 'riME S~ECfFlEO:\ "'!<';'~' ~;:'Y;; SYMBOL ',AS;f'MBOL,TA9.I.;E V\ln..lFOI.;I-C>WSOURCE PR~_,~, ,: XREF,SYMBOLS'CRQSSLlSTlNG WtLLFQU.dVV'SOY'RC~ '~M:.' 'BASE HEX HEXADECIMAL NUMBERS SPECIFIED FOR ASSEMBLYHSllNG ,SOFA ebU H'o8oo'; SET THE VALUE OfSYMBQlBUFA BUFB 'EQU 'H,'QaAO' SET THEVALU,E OF SYMBOL BUFB 'ORG H'0100' 0100 2A ONE DCI' BUFA SETDCD TO BUFA STARTING ADDRESS 0101 OS 0102 00 0103 2C TWO XDC STORE IN DCl 0104 2A THREE DCI BUFB SET DCa TO BUFB STARTING ADDRESS 0105 OS 0106 AO 0107 20 FOUR LI H'SO' LOAD BUFFER LENGTH INTO ACCUMULATOR 010S SO 0109 51 FIVE LR l,A SAVE BUFFER LENGTH IN SCRATCHPAD BYTE 1 010A 16 LOOP LM LOAD CONTENTS OF MEMORY BYTE ADDRESSED BY Dca 0108 2C SIX XDC EXCHANGE DCO AND DCl OlOC 17 SEVEN ST STORE ACCUMULATOR IN MEMORY BYTE ADDRESSED BY DCO 0100 2C EIGHT XDC EXCHANGE Dca AND DCl OlOE 31 NINE DS 1 DECREMENT SCRATCHPAD BYTE 1 alOF 94 BNZ LOOP IF SCRATCHPAD BYTE 1 IS NOT ZERO, RETURN TO LOOP 0110 FA END Fig. 5-1. Assembler Directives (Shaded) in a Source Program 5-1 5.4 END - END OF ASSEMBLY With reference to Figure 5-1, consider the following erroneous An END directive must terminate every source program. Upon variation of the BUFA symbol's use: encountering this directive, the assembler stops reading source program instructions, and starts to perform various ORG H'2FAO' post-assembly computations. BUFA DC H'0800' Figure 5-1 illustrates use of an END directive. Note that an END directive cannot, and must not. have a label. ORG H'0100' ONE DCI BUFA The format of the END directive is: The DC directive causes the two byte, hexadecimal value Label Mnemonic Operand H'0800' to be stored in two memory bytes, with addresses Must END H'2FAO' and H;2FA 1'. In instruction ONE, BUFA acquires the be blank value H'2FAO', not H'0800'. 5.5 EQU - EQUATE A SYMBOL TO A NUMERIC Now consider how the DC directives might be correctly used VALUE in the Figure 5-1 program. BUFB has been equated to Every symbol in a source program must be the label of an H'OSAO', which is the starting memory address of the source assembly language instruction or a DC directive, or the sym- buffer. The source buffer contents could be specified, using bo! must be assigned a value by an EQU directive. The general DC directives, as follows: format of an EQU directive is: BUFA EQU H'0800' Label Mnemonic Operand ORG H'0100' LABEL EQU VALUE ONE DCI BUFA TWO XDC LABEL is any valid symbol. THREE DCI BUFB VALUE is any valid numeric value as described in Section 4.2.2. Refer to Figure 5-1. The symbols BUFA and BUFB appear in ORG H'08AO' instructions ONE and THREE, and are assigned values by two BUFB DC H'20A1' EQU directives. Therefore: DC H'143E' DC H'5A62' BUFA EQU H'0800' The symbol BUFB no longer needs to be equated to H'OSAO' since it appears as a label at address H'OSAO'. The DC direc- tives cause the data string H'20A 1143E5A62' to be loaded ONE DCI BUFA into memory starting at memory location H'OBAO'. is identical in its net effect to: NOTE: When a buffer's contents are specified by DC directives, ONE DCI H'0800' the buffer's data becomes part of the program, and are loaded into memory when the program is loaded Why then are Equate directives used? In a real program, a into memory. symbol (such as BUFA) is likely to appear many times. If the value of the symbol changes, the progrram can be corrected by modifying one Equate directive, then re-assembling the 5,6 MAXCPU - SPECIFY MAXIMUM CPU TIME program. If absolute values are used in instruction operands This directive is only meaningful when the source program is (instead of symbols), every instruction that references the being assembled on a large host computer (e.g., an IBM 360 absolute value must be changed in the source program if or 370). On such large computers, programs exist to simu- the absolute value changes; the source program nust be late the F8 microprocessor; therefore once the source program re-assembled. has been assembled, the object program may be "run" using the host computer simulator. For example. suppose there are 24 instructions in a source program that reference the ~ymbol BUFA. The Equate direc- A potential problem lies in executing an object program tive could be eliminated, in which case each of the 24 instruc- which, due to programming errors, may run for ever; a large tions would have H'0800' where it had BUFA. However, if amount of costly host computer time may be expended before H'0800' had to be changed, instead of making the chan!;le in the existence of the error is detected. The MAXCPU directive one Equate directive, the change would h(;I\ For AD16, change / ,.\ \ i'~ \ / / " \j I, '\ \ ONE LR A,O LOAD LOW ORDER I / \ 1\ \ '\ \ II 1/\1 '\ AUGEND BYTE 1/ 1I 1 , II II \: -0 ¥ ,-. " to the following equivalent instruction: I I I I (BI ROUTINE "5" APPEARS ONCE EXECUTION LOGIC AD16 LR A.O LOAD LOW ORDER (REPRESENTED BY ..... ~ I BRANCHES TO THE AUGEND BYTE BEGINNING OF "5". THEN RETURNS, FROM THE END OF "5", TO THE BRANCH POINT Note that although the first sequential instruction is also the Fig. 7-2. Subroutine, as Compared to a Macro first executed instruction for MADD and AD 16, the first executed instruction may, in reality, be any instruction within 7.3.2 Subroutine Program Steps the subroutine. The instructions that implement any logic are the same within, or outside of, a subroutine. Compare the 16-bit addition pro- gram (AD16) in Section 7.3.3 with the equivalent program The last instruction executed by a subroutine must be POP, in Section 7.2.1; the only changes relate to entry and exit PK or LR PO,Q. Therefore, if for the moment the AD 16 error procedures. return is ignored, subroutine AD16 becomes: 7.3.3 Simple Subroutine Calls and Returns AD16 LR A,O FIRST INSTRUCTION As described in Sections 6.35 and 6.36, there are two EXECUTED FOR AD16 instructions used to call a subroutine into execution. TWO AS 2 THREE LR 2,A Instruction PK saves the contents of the program counter FOUR LR A,l (PCO) in the stack register (PC1). then loads the subroutine FIVE LNK starting address from the K register (scratchpad registers SIX BNO EIGHT 12 and 13) into the program counter. SEVN POP IF THE RESULT IS TOO LARGE, RETURN Instruction PI saves the contents of the program counter in EIGHT AS 3 the stack register; it then loads the subroutine starting ad- NINE LR 3,A dress (which is in the two object program bytes following OUT POP RETURN AT END OF the Plop code byte) into the program counter. SUBROUTINE For straightforward returns from subroutines, the POP in- struction, described in Section 6.37, moves the contents of Notice that a subroutine may have more than one exit. 7-7 Subroutine MADD becomes: *THIS ORIGIN FOR MADD HAS BEEN ARBITRARILY SELEClED ORG H'09EO' MADD LI CNT FIRST INSTRUCTION MADD LI CNT USE SCRATCHPAD EXECUTED FOR MADD REGISTER 0 TWO LR OA irest of subroutine follows here) (rest of subroutine as in Section 7.2.2) *THIS ORIGIN FOR THE MAIN PROGRAM HAS BEEN * ARB!TRAR!LY SELECTED TWTl DS o ORG H'1000' BNZ LOOP RETURN FOR MORE *BEFORE SUBROUTINE AD16 IS FIRST CALLED, LOAD POP RETURN AT END OF *ITS STARTING ADDRESS INTO THE SCRATCHPAD K SUBROUTINE REGISTERS ONE LI H'09' LOAD STARTING ADDRESS TWO LR KUA OF SUBROUTINE AD161NTO Consider the very simple case of subroutineAD16 being called THREE LI H'80' K REGISTER using a PI instruction. Instruction sequences, with arbitrarily LR KLA selected memory addresses, might be as foiiows: Memory *MAIN PROGRAM SEGMENT FOUR PK FIRST CALL TO SUBROUTINE Address AD16 H'102A' ONE PI AD16 FIVE PI MADD FIRST CALL TO SUBROUTINE H'102D' TWO INC MADD SIX PK SECOND CALL TO SUB- ROUTINE AD16 *SUBROUTINE AD16 STARTS HERE H'2130' AD16 LR A,O SEVEN PK THIRD CALL TO SUB- ROUTINE AD16 H'213B' OUT POP Before instruction ONE is executed, PCO contains H'102A'. etc After instruction ONE has executed, PCO contains H '2130' and PCl contains H'102D'. Execution now proceeds from 7.3.4 Nested Subroutines AD16, at H'2130'. "Nesting" is the term applied to subroutines being called from within other subroutines. There is no reason why a subroutine should not, itself, call Before instruction OUT is executed, PCO contains H'213B' another subroutine. In fact, subroutines are such efficient and PCl still contains H'102D'. Instruction OUT moves programming tools, that it is not uncommon to find subroutines H'102D' to PCO, thus returning execution to TWO. nested eight deep, or more, in large programs. Consider a very simple case, where creation of the correct carry status for multibyte addition is packaged into a sub- The following sequence illustrates PK being used to call AD 16, routine named CBIT. This subroutine is equivalent to instruc- and PI being used to enll MADD' t:C:1S E!GHT thivugh THRT of the addition program in Section *THIS ORIGIN FOR AD 16 HAS BEEN ARBITRARILY SELECTED 7.1.2. Subroutine CBIT appears as follows: I AD16 ORG H'0980' 10 1...11 ' ' ' ' ... l""t. , ,,",,'AI LVMU LVVV vnucn ",....~,.._ CS~T In 1...1"\ A " M,;;} iviOVE STATUS FROM LNK t AUGEND BYTE ADDITION TO A LR J,W MOVE STATUS FROM BYTE ADD TO W (rest of subroutine follows here) XS 9 EXCLUSIVE-OR STATUSES LR 9,A RETURN STATUSTOJVIAW LR W,J POP I First try changing the addition program in Section 7.1.2 as H'080A' ONE PI SUB1 CALL FIRST SUBROUTINE follows: H'080D' NXT1 FIRST SUBROUTINE RETURNS HERE MADS COM INITIALLY CLEAR THE CARRY STATUS ORG H'2073' ONE LlSU 7 ADDRESS LOW ORDER "START OF FIRST SUBROUTINE BYTE OF EACH BUFFER H'2073' SUB1 FIRST INSTRUCTION OF LOOP LlSU 4 ADDRESS FIRST BUFFER SUB1 TWO LR A,S LOAD FIRST BUFFER BYTE INTO A H'2082' TWO PI SUB2 CALL TO SECOND SUB- THREE LlSU 5 ADDRESS SECOND BUFFER ROUTINE FOUR LNK ADD ANY CARRY TO A H'2085' NXT2 SECOND SUBROUTINE FIVE LR J,W SAVE STATUS IN SCRATCH- RETURNS HERE PAD BYTE 9 SIX AS S ADD SAME BYTE OF H'2132' RET1 POP RETURN TO MAIN SECOND BUFFER PROGRAM SEVEN LR D,A STORE ANSWER AND INC- REMENT BYTE POINTER EIGHT PI CBIT CALL C STATUS SUB- "START OF SECOND SUBROUTINE ROUTINE ORG H'12A4' FORT BR7 LOOP RETURN IF NOT END H'12A4' SUB2 FIRST INSTRUCTION OF FIFT POP RETURN FROM SUB- SUB2 ROUTINE H'12B3' THRE PI SUB3 CALL TO THIRD SUB The addition routine has been converted into a subroutine named MADS. H'12B6' NXR3 THIRD SUBROUTINE RETURNS HERE When subroutine MADS is called, the return address is stored in PC1 to be returned to PCO by POP instruction FIFT. Un- H'12E2' RET2 POP RETURN TO FIRST fortunately, when CBIT is called at EIGHT, the PI instruction SUBROUTINE will also store a return address, the address of instruction FORT, in PC1. The POP at FIFT will no longer work, since it will branch execution back to FORT, thus forming an endless execution loop. (This type of program error is handled by the "START OF THIRD SUBROUTINE MAXCPU directive.) ORG H'1558' H'1558' SUB3 FIRST INSTRUCTION OF When subroutines are nested one deep, (and this is often SUB3 sufficient in simple F8 applications), the K registers in the scratchpad can be used to overcome the problem of wiping out PC1. For example, in Subroutine MADD, save PC1 in K upon entering MADS then use PK to return from MADD: H'1596' RET3 POP RETURN TO SECOND MADS LR K,P SAVE RETURN ADDRESS SUBROUTINE COM INITIALLY CLEAR THE CARRY STATUS The sequence in which instructions are executed is given in Table 7-2, along with contents of PCO, PC1, and a "stack" in memory, where PC1 contents may be stored. EIGHT PI CBIT CALL C STATUS SUB- Notice that the first return address, H'080D', is passed to SO, ROUTINE the first two bytes of the memory stack. Similarly the sec- FORT BR7 LOOP RETURN IF NOT END ond (H'2085') and third (H'12B6') return addresses are stored FIFT PK RETURN FROM SUB- in the second and third byte pairs of memory stack. At a" ROUTINE FOR END times, data in PC1 and K are merely the accidental result of logic needed to pass return addresses to the stack. When subroutines are nested more than two deep, a stack is created in RAM to hold subroutine return addresses. When creating such a memory stack, it is wise to use PC1 and K as A memory stack "pointer" must be maintained. After each address conduits to the stack, never actually retaining address return address is stored in the stack, the stack pointer wi" permanently in PC 1 or K. identify the next free stack byte. Consider the following simple, three-deep subroutine nest: Return logic is the opposite of subroutine call logic. Before Arbitrary each call, the most recently stored return address (in the Memory two stack bytes right behind the stack pointer) are moved to Addresses PC1, and the stack pointer address is decremented by 2. "MAIN PROGRAM The memory stack may either be in scratchpad memory, or in RAM memory. 7-9 REGISTERS/STACK CONTENTS r INSTRUCTION i PCO L........~~g~___-L.. PC1 J K First six bytes of Memory Stack I SO --L~--~.2_ J 1080A ? ? 7 ! ? r--- Before ONE 0;00 i2073 I 7 ! 7 7 I 7 ! . - - AftAr SU81 [2073 0800 ? I ? 7 1 ? Before 0800 0800 ! 0800 2082 ! 7 i ? Before TWO After ~ 2085 ! 0800 ,12A4 0800 7 I: 1 ! 1~_S~12A4 2085 0800 0800 7 Before 12B3 2085 2085 0800 2085 I ) ! - 4 - - Before I THRE 1558 1286 2085 ! 0800 2085 7 !.--- After SU83 1558 1286 2085 0800 2085 7 ,--- Before -- ! i I 1596 I 1286 1286 i 0800 2085 r 1286 ,--- Before RET3 1286 1286 1286, 0800 2085 1286 After NXT3 ~86 1286 0800 2085 1286 Before 12E 2 2085 2085 0800 2085 12B6 !~ Before RET2 2085 2085 2085 0800 2085 1286 _ _ _ After i NXT2 12085 2085 2085 0800 2085 1 12~_ Before - 12B6~--_ Before -- [2132 0800 0800 0800 2085 RET1 0800 0800 0800 0800 2085 1 12B6 r--- After I L~ Instructions are In order of execution Table 7-2. Use of a Memory Stack for Executing Multiple level Subroutines Consider first a stack in scratch pad memory. By assigning MADD LR K,P SAVE RETURN ADDRESS one 8-byte buffer to serve as a memory stack, subroutines IN K may be nested four deep. One byte at the beginning of PI CALL SAVE RETURN ADDRESS scratchpad memory will serve as the stack pointer. IN STACK ONE LIS CNT USE SCRATCHPAD REGISTER 0 Subroutine CALL, described next, uses scratch pad bytes 0'77' TWO LR OA AS A COUNTER to 0'70' as the memory stack, as illustrated in Figure 7-3. Scratchpad byte 8 is the stack pointer which must be initialized to H'7T. Since the call to CALL is preceded by PC 1 contents being saved in K, PCl is now free to hold the return address for BYTE SCRATCH PAD NO. STACK / BEGINNING OF STACK CALL. Subroutine CALL has the following instructions: 077' 076' H1 L1 I FIRST RETURN ADDRESS CALL LR A,8 MOVE THE STACK POINTER TOISAR 075' H2 } SECOND RETURN ADDRESS Cl LR ISA 074' l2 C2 CI 0'67' CHECK FOR STACK If-------ij } 073' H3 OVERFLOW l3 THIRD RETURN ADDRESS 0'72' C3 BZ SFUL STACK HAS OVERFLOWED. 071' I H4 l4 } FOURTH RETURN ADDRESS MAKE ERROR EXIT. 070' C5 LR A,KU MOVE KU TO STACK f-------l I ~END OF STACK C6 LR DA C7 LR A,KL MOVE KL TO STACK SUBROUTINE CAll lOAD ADDRESSES INTO THIS STACK SUBROUTINE RTRN FETCH ADDRESSES OUT OF THIS STACK C8 LR SA DO NOT DECREMENT ISAR C9 LR A.IS SAVE ISAR IN SCRATCH- PAD SYTE:3 C10 LR 8A Fig. 7-3. Scratchpad Stack Cll DS 8 DECREMENT VALUE SAVED FOR ISAR Every subroutine must begin by saving PCl contents in K, C12 POP RETURN then calling CALL. This is illustrated as follows for subroutine MADD, which is the addition program from Section 7.2.2, The address of the next free stack byte is held in scratch pad converted into a subroutine: byte 8. If this address is 0'67', it means that 0'70' is the address of the last filled stack byte and the stack is full. RTRN Move the stack pointer address from scratchpad Therefore when CALL is called, the stack address is tested R1 register 8 to ISAR. Increment ISAR to move ad- for overflow by checking ISAR. A value of 0'67' indicates the dress from the first free stack byte to the last stack has overflowed. A value of 0'77' indicates the stack occupied stack byte. is empty. R2 Move the address identified by ISAR to QL and QU. Subroutine CALL logic proceeds as follows: to Increment ISAR to point to the prior address. Leave R5 ISAR addressing what is now the first free byte. CALL Move the stack address from scratchpad byte 8 to ISAR R6 Save the new value of ISAR in scratchpad register 8. C1 R7 C2 Test stack address for 0'67'. R8 The subroutine that called RTRN now wishes to return to the address which RTRN has moved to C3 It is assumed that SFUL is the label of an instruction the Q registers. RTRN can simply move this ad- which will handle stack full errors in any way re- dress from Q to PCO in order to effect the desired quired by program logic. This instruction branches return. execution to the instruction labeled SFUL. For large stacks, RAM memory may be used for the memory Move the contents of the K registers to the next two stack. Only minor logic modifications are required to CALL C5 free bytes of the stack. The ISAR is only decremented and RTRN if the stack is in RAM. Assuming that the stack to once. The second decrement can be performed in pointer is maintained in scratch pad registers 8 (high) and C8 7 (low), subroutine CALR and RTRR perform the same func- the scratchpad, where 0'70' will decrement to 0'67' tions as CALL and RTRN but, for a RAM stack, that may be which is indicates stack full, rather than to 0'77' more than 256 bytes long. which would erroneously indicate stack empty. As for the scratch pad stack, the RAM stack begins at a high C9 Return the new contents of ISAR to scratchpad RAM address, and the stack address is decremented as the register A. stack gets filled. The end of the RAM stack is identified by a low address, represented using the symbols SPHI and SPLO C10 for the high and low order bytes of the address. C11 Decrement ISAR in scratch pad so that 0'70' will The stack pointer address identifies the last filled stack byte. decrement to 0'67' which is full, not to 0'77', which is empty. *VERSION OF SUBROUTINE CALL FOR RAM STACKS, WITH *THE STACK POINTER IN SCRATCHPAD REGISTERS 8AND 7. C12 Return from subroutine CALL. CALR LR A,7 LOAD LOW ORDER BYTE OF STACK ADDRESS A subroutine that uses CALL to save its return address on LR 11,A MOVE TO HL the stack will use another subroutine, named RTRN, to re- CI SPLO COMPARE WITH END-OF- turn to the calling program. For example, subroutine MADD STACK L.O. BYTE will now end with: LR A8 LOAD HIGH ORDER BYTE OF STACK ADDRESS lWT2 PI RTRN LR 10,A STORE IN HU BNE CA8 IF LOW ORDER BYTE DOES Since RTRN resets PCO, PI may be replaced with: NOT EQUAL STACK END, CONTINUE lWT2 JMP RTRN CI SPHI COMPARE HIGH ORDER BYTES Subroutine RTRN takes the address most recently stored in BEQ CA20 IF EQUAL, STACK HAS the stack and moves this address to PCO, effecting the desired OVERFLOWED return, as follows: CA8 LR DC,H MOVE H TO DC *SUBTRACT 2 FROM THE STACK ADDRESS, SINCE IT INCRE- RTRN LR A8 MOVE THE STACK POINTER *MENTS WHEN MEMORY IS ACCESSED. BY SUBTRACTING TO ISAR *2, DCO ADDRESSES THE SECOND FREE STACK BYTE. R1 LR IS,A LI H'FE' LR AI INCREMENT ADDRESS TO ADC LAST FILLED STACK BYTE LR AKU MOVE KU TO STACK R2 LR AI MOVE THE ADDRESS ST R3 LR QL,A IDENTIFIED BY ISAR TO Q LR A,KL MOVE KL TO STACK R4 LR AS ST R5 LR QU,A *SUBTRACT 2 FROM STACK ADDRESS, SINCE IT HAS INCRE- R6 LR AIS RESTORE ISAR *MENTED TO BEGINNING OF PREVIOUS ADDRESS. R7 LR 8,A LI H'FE' R8 LR PO,Q MOVE Q TO PCO ADC LR H,DC RESTORE STACK POINTER Subroutine RTRN executes as follows: LR A 11 7-11 LR 7.A 7.3.5 Multiple Subroutine Returns LR A10 Observe that the 16-bit addition subroutine in Section 7.1.4 LR 8.A requires two returns, one for an overflow in the answer, the POP RETURN other for a valid execution. CA20 JMP SFUL STACK FULL ERROR Frequent!y subrout:nes may execute with more than one The logic of CALR differs from ihe iogic of CALL oniy in the possible outcome. The most efficient way of handling such way stack overflow is handled. Rather than leaving the stack logic is to build multiple returns into the calling program and pointer addressing the next free byte of the stack, the stack into the called subroutine. Here are some examples. First. pointer addresses the last used byte of the stack. Stack over- an error return: flow is tested for by comparing the contents of the stack pointer with an address that has been specified as the end of the stack. This end of stack address can be equated to any value that is convenient to program logic. PI SUB1 CALL SUBROUTINE SUB 1 BR ERR ERROR RETURN FROM SUB 1 Notice that whenever memory is accessed via the DC reg- NON-ERROR RETURN FROM isters the address in the DC registers is automatically incre- SUB1 mented. The stack in RAM has arbitrarily been selected to begin at a high address and end at a low address, which is the opposite direction as seen by the DC registers. Since Next, mu!tiple valid returns: the DC registers address the last filled byte of the stack, two must be subtracted from this address so that two bytes of PI SUB2 address data may be loaded into the stack without overloading BR PLUS RESULT IS POSITIVE the last filled byte. Also, after the two bytes of address have BR ZERO RESULT IS ZERO been loaded into the stack, two must again be subtracted RESULT IS NEGATIVE from the address in the DC registers so that the address once again identifies the last filled byte of the stack. Subroutines RTRN and RTRR can easily be rewritten to handle Although the sense of direction of the stack is inverted with multiple returns. Instructions will be added that return, to regard to the DC registers when CALR is executed, stack PCO, the last address entered into the stack, plus any dis- direction will agree with the DC registers when RTRR is exe- placement that is in QL (scratchpad register 15) when the cuted. Since stack access involves a forward and then a subroutine is called. RTRN will now appear as follows, renamed reverse direction, it makes no difference what is chosen to RTRD: be forward and what reverse; either CALR or RTRR must access the stack by decrementing addresses. This is contrary RTRD LR A,8 MOVE STACK POINTER TO to the sense of the DC registers which only increment addresses. ISAR LR IS.A LR AI INCREMENT ADDRESS TO *VERSION OF SUBROUTINE RTRN FOR RAM STACKS, WITH LAST FILLED BYTE *THE STACK POINTER IN SCRATCH PAD REGISTERS 8 AND 7. LR AQL LOAD LOW ORDER RTRR LR A8 MOVE THE STACK POINTER ADDRESS BYTE TO H AS I ADD DISPLACEMENT IN QL LR 10.A LR QL.A STORE RESULT IN QL LR A7 LR AS LOAD HIGH ORDER LR 11.A ADDRESS BYTE LR DC,H MOVE THE STACK POINTER LNK ADD ANY CARRY FROM LO TO DC BYTE ADDITION LM LOAD HIGH ORDER BYTE LR QU.A STORE RESULT IN QU LR QU.A OF RETURN ADDRESS R6 LR AIS RESTORE ISAR INTO QU R7 LR 8A LR PO,Q MOVE Q TO PCO LM LOAD LOW ORDER BYTE LR OLA OF RETURN ADDRESS Taking advantage of RTRD, the i 6-bit addition subroutine INTO OL will become: LR H,DC SAVE STACK POINTER IN LR A10 SCRATCHPAD BYTES 8 AD16 LR K,P SAVE RETURN ADDRESS AND 7 IN K LR S,A Pi CALL SAVE RETURN ADDRESS LR A,11 IN SCRATCHPAD STACK LR 7.A LR AO LOAD LOW ORDER LR PO,Q MOVE Q TO PCO AUGEND BYTE AS 2 ADD ADDEND LOW ORDER In F8 systems that have a 3852 and/or 3853 Memory Inter- BYTE face device, if DC1 is not used to address data buffers, it can LR 2.A SAVE THE RESULT be used effectively as a RAM stack pointer. LR A,1 LOAD HIGH ORDER /- I L AUGEND BYTE Once MADD is entered, the return address in PC1 is in LNK ADD ANY CARRY FROM fact, the address where the augend buffer starting address LOW ORDER BYTE ADD will be found. Before entering into the body of the subroutine, BNO EIGHT IF THERE IS A CARRY OR MADD will load parameters into H, Q and DC1. This is AN OVERFLOW, RETURN illustrated below for subroutine MADD with parameters, WITHOUT DISPLACEMENT renamed MADP. BR ERR EIGHT AS 3 ADD THE HIGH ORDER MADP LR K,P SAVE THE RETURN ADDRESS ADDEND BYTE IN P LR 3,A SAVE THE RESULT PI CALL SAVE THE RETURN ADDRESS LIS 2 FOR A GOOD RETURN, ADD IN THE STACK 2 TO RETURN ADDRESS LR A,KU MOVE THE RETURN BNO OK AGAIN IF THERE IS A ADDRESS FROM K CARRY OR OVERFLOW LR 10,A TO DCO. DCO WILL NOW ERR CLR FOR AN ERROR RETURN, ADDRESS THE FIRST OF THE ADD 0 TO RETURN LR A,KL TWO BYTES IN WHICH VALA ADDRESS IS STORED, FOLLOW!NG OK LR QL,A SAVE THE DISPLACEMENT LR 11,A THIS CALL TO MADP IN QL LR DC,H LOAD PARAMETER PI RTRD ADDRESS INTO DCO LM LOAD VALA INTO H Now AD16 will be called as follows: LR 10,A LM LR 11,A XDC MOVE VALA FROM H TO DC1 BY PI AD16 LR DC,H EXCHANGING DCO WITH DC1 BR ERROR ERROR RETURN XDC MOVING VALA TO Dcd, GOOD RETURN THEN LM AGAIN EXCHANGING DCO AND DC1 LR 10,A NEXT LOAD VALB INTO H 7.3.6 Passing Parameters LM LR 11,A Subroutine MADD, as described so far, is of limited value, LM LOAD VALC INTO Q since the starting addresses of buffers BUFA, BUFB and LR QU,A BUFC are fixed. MADD will only add the contents of two LM fixed buffers and store the result in a third, fixed buffer. The LR Ql,A subroutine would be far more useful if buffer locations and LM LOAD COUNT iNTO lengths could be specified at the time the subroutine is called. This can be done and is called parameter passing. SCRATCHPAD BYTE 0 LR O,A LR DC,H MOVE VALB TO DCO The parameters to be passed to a subroutine are listed, in *THE MULTIBYTE ADD MAY NOW BEGIN the calling program, after the subroutine call. For example, COM INITIALLY CLEAR THE CARRY the call to MADD would appear as follows: BIT LR J,W VA LA EQU H'2080' LM LOAD THE NEXT AUGEND LOOP VALB EQU H'2088' VALC EQU H'2800' LR W,J • BYTE COUNT EQU H'08' LNK ADD ANY PREVIOUS CARRY LR J,W SAVE STATUS IN J XDC ADDRESS ADDEND BUFFER AM ADD CORRESPONDING *CALL TO MADD IN MAIN PROGRAM ADDEND BYTE PI MADD CALL SUBROUTINE MADD XDC READDRESS AUGEND DC VALA VALA IS A TWO BYTE BUFFER AUGEND BASE ADDRESS LR H,DC SAVE AUGEND ADDRESS DC VALB VALB IS A TWO BYTE IN H ADDEND BASE ADDRESS LR DC,Q LOAD ANSWER BUFFER DC VALC VALC IS A TWO BYTE ADDRESS ANSWER BASE ADDRESS ST STORE THE ANSWER DC COUNT COUNT IS A ONE BYTE LR Q,DC SAVE THE ANSWER BUFFER BUFFER LENGTH ADDRESS IN Q BR ERROR RETURN HERE IF THERE IS LR DC,H MOVE AUGEND ADDRESS AN ERROR BACK FROM H RETURN HERE FOR BNC TWT1 NO CARRY FOR NEXT BYTE SUCCESSFUL EXECUTION LR J,W 7-13 1WT1 DS DECREMENT COUNTER CBIT, rather than as a subroutine named CBIT. The macro is BNZ lOOP RETURN FOR MORE defined in the source program by enclosing the instructions lR W,J of the macro between assembler directives MACRO and LIS 9 LOAD A FOR A GOOD MEND, as follows: RETURN BNC OUT TEST FOR A FINAL CARRY MACRO US 7 THERE is A CARRY, CSIT PREPARE FOR ERROR lR A,9 MOVE STATUS FROM LNK OUT lR Ql,A SAVE THE DISPLACEMENT ADDITION TO A IN QL NI H'02' MASK OUT All BUT C BIT PI RTRD RETURN FROM SUBROUTINE LR J,W MOVE STATUS FROM BYTE ADD TO W Parameter passing works as follows: AS 9 ADD STATUSES LR 9,A RETURN STATUS TO J VIA W A subroutine that expects to receive parameters will initiate LR W,J execution with the return address pointing to the first byte MEND of the parameter list, and not to the instruction which must be executed once program control returns to the calling pro- In theory, a macro definition, as illustrated above, could ap- gram. In other words, after subroutine CALL has executed, pear anywhere in a source program; the assembler simply the address saved on the stack is the address of the first takes everything between the MACRO and MEND directives parameter, not the address of the next instruction to be exe- and holds it to one side, inserting the instructions whenever cuted in the calling program. Initial subroutine iogic must it sees the macro name appear in the mnemonic field of an therefore move the address of the first parameter to the instruction. In practice, it is good programming to collect DCO registers, and must then appropriately load parameters macro definitions either at the very beginning or at the very into registers where they will be needed for execution of end of a source program. the subroutine. This process is straightforward data movement and requires no special explanation. As an example of how a macro works, subroutine MADD could specify CBIT as a macro, rather than as a subroutine, Observe that when subroutine RTRD is called to effect a as follows: return to the calling program (in this case the main program which called MADP) the return address, as stored in the stack, is still the address of the first parameter byte. There- fore, before RTRD is called, the value loaded into the accu- mulator is not zero or a displacement representing multiple (Body of subroutine MADD) returns. It is the number of bytes of parameters, or the num- ber of bytes of parameters plus the displacement of the multi- ple returns. For example, subroutine MADP requires seven bytes of parameter information to follow the call to MADP. EGTN LR DC,H MOVE AUGEND ADDRESS Therefore, an error return from MADP requires the value 7 BACK TO H to be loaded into the accumulator before RTRD is called; a LR K,P SAVE PCl IN K value of 9 must be loaded into the accumulator before RTRD NNTN CBIT INSERT INSTRUCTIONS if there is no error. FROM CBIT MACRO HERE 1WTl DS 0 DECREMENT COUNTER 7.4 MACROS BNZ LOOP RETURN FOR MORE Observe in Figure 7-2(A) that an instruction sequence may 1WT2 PK RETURN FROM SUBROUTINE reappear in a program each time it is reused. Such an instruc- FOR END tion sequence may be identified as a macro. When the assembler assembles the above instruction se- Refer to Figure 7-2. If the instruction sequence represented quence, instruction NNTN will be replaced directly by the six by "s" is a subroutine (we will assume that it is named instructions listed between MACRO CBIT and MEND. For SUB1), then wherever the logic of SUB1 is required, a PI this reason, the programmer may look upon a macro simply or PK instruction in the main program will cause execution as a short-hand method of writing source programs (i.e., a to branch to one set of code, as illustrated in Figure 7-2(BI method of taking the tedium out of re-writing the same and described in Section 7.3. If,. on the other hand, the instruction seauence again and againl. logic of SUB 1 is to be treated as a macro, then the name SUB1 will appear in the mnemonic field of the source pro- 7.4.2 Macros with Parameters gram as though SUB 1 were the mnemonic for ali instruction. A simple macro, as illustrated for CBIT in Section 7.4.1, is In the object program, the assembler will actually insert of limited value; it makes an object program longer, but it the sequence of instructions represented by SUB 1 wherever makes vvr!t!ng the sot.!!"ce program eas!er. The p:-cgrlJm SUBl appears in the source program, as illustrated in Figure executes faster since the PI and POP instructions are not 7-2(A). executed. 7.4.1 Defining and Using Macros Macros with parameters are more useful. Refer to subroutine Beginning with a very simple example, suppose the instruc- MADP, in Section 7.3.6. In order to make the multibyte tion sequence which creates the correct carry status in multi- addition program MADD useful, it was modified so that the byte addition routines is to be identified as a macro named call to subroutine MADD could be followed by seven bytes I of parameter data, including three 2-byte addresses and When the assembler encounters the above instruction, it will a single byte buffer length counter. Instructions at the be- substitute all ofthe instructions listed between MACRO MADD ginning of subroutine MADP transfer these parameters to and MEND; however wherever it finds &CNT it will replace the H, a and DCl registers before performing the multibyte it with CNT, wherever it finds &VALA, &VALB or &VALC it addition, thus allowing subroutine MADP to perform muiti- will substitute BUFA, BUFB or BUFC, respectively. byte additions on the contents of buffers that can have any length and can be anywhere in memory. 7.4.3 Rules for Defining and Using Macros The multibyte addition may also be specified as a macro, The following few rules apply to the use and definition of where the macro name is followed by a number of para- macros: meters. In this case, the parameters would again be three addresses and a byte count. Now when the assembler sub- 1) No macro can be referenced in a program unless it stitutes the instruction sequence of the multibyte add for the has been defined as a macro, using the MACRO and macro name appearing in an instruction mnemonic, it changes MEND assembler directives. instructions within the sequence according to parameter specifications. 2) When a macro is defined, it can reference another When a macro is defined, macro parameters are listed after macro so long as the other macro is defined separately the macro name with an ampersand as the first character elsewhere. of each parameter and one space separating parameters. This is illustrated for macro MADP below: 3) If a macro is defined with parameters, then every time the macro is specified within the body of a pro- MACRO gram, the specification must have a valid symbol in MADP &VALA &VALB &VALC &CNT the operand field, corresponding to every parameter ONE LI &CNT USE SCRATCHPAD in the macro definition. REGISTER a TWO LR a,A AS A COUNTER 7.4.4 When Macros Should be Used THREE DCI &VALC SAVE THE ANSWER BUFFER There are two circumstances when macros are more ef- FOUR LR a,DC STARTING ADDRESS IN a ficient as a programming tool than subroutines. FIVE DCI &VALA SAVE THE SOURCE BUFFER SIX XDC ADDRESSES IN Dca AND DCl Short instruction sequences that are frequently used within SEVEN DCI &VALB a program are often better represented as macros, if sub- EIGHT COM INITIALLY CLEAR THE routine addresses are being maintained in a stack. It takes CARRY BIT a certain amount of time to store a return address in a LR J,W stack, then at the end of a subroutine to retrieve the ad- LOOP LM LOAD THE NEXT AUGEND dress from the stack. If the body of the subroutine is quite BYTE short, the time taken to maintain the stack may become LR W,J CARRY FROM PRIOR ADD excessive. Under such circumstances it is better to repro- TO STATUS duce the instruction sequence as a macro wherever it is NINE LNK ADD ANY PREVIOUS CARRY needed within a program. TEN LR J,W SAVE STATUS IN J ELEV XDC ADDRESS ADDEND BUFFER Subroutines which require a large number of parameters TWEL AM ADD CORRESPONDING to be passed from the main subroutine are frequently bet- ADDEND BYTE ter represented as macros; a considerable number of in- THRT XDC READDRESS AUGEND structions may be needed to move the parameters from BUFFER the parameter list that follows the subroutine call, to the FRTN LR H,DC SAVE AUGEND ADDRESS registers or memory locations out of which the subroutine IN H will access the parameters. Consider subroutine MADP; FFTN LR DC,a LOAD ANSWER BUFFER if this subroutine is called only two or three times it is ADDRESS probably more efficient to represent it as a macro rather SXTN ST STORE THE ANSWER than as a subroutine. EGTN LR DC,H MOVE AUGEND ADDRESS BACK TO H Macros always result in faster program execution than BNC TWTl NO CARRY FOR NEXT BYTE subroutines. Macros may result in longer programs than TWTY LR J,W SAVE CARRY FROM AM subroutines. Therefore, in an application where speed is INSTRUCTION important, macros should be used in preference to subroutines. TWTl DS a DECREMENT COUNTER BNZ LOOP RETURN FOR MORE MEND 7.5 JUMP TABLES Any program can tell the assembler to insert the instruction A jump table is a programming device which is particularly sequence specified by macro MADP, changing the symbols useful in microprocessor applications. A jump table allows &CNT, &VALA, &VALB and &VALC to any four symbols speci- an index number to be loaded into the accumulator after fied in the operand field of the instruction that references which program execution jumps to a memory location which macro MADP. For example, in order to reproduce the multi- is dedicated to that index number. byte addition instruction sequence as illustrated in Section 7.2.2, the following instruction would have to appear: Jump tables are commonly used in switching applications, where data may be received from, or control signals may have MADP BUFA BUFB BUFC CNT to be sent to, one of many external devices. 7-15 7.5.1 Jump Table Using Jump Instructions 7.5.3 Jump Table Using Displacement Tables The F8 instruction set is well-suited to execution of jump Under some circumstances the addresses of the jump table tables. As illustrated, one jump table may serve an entire may all be within 256 bytes of each other. When this situa- application of diverse operations. The jump table consists tion exists, only a displacement need be created in the table. of nothing more than a large number of jump instructions. This displacement, when added to some base address, will To execute the jUIT'P table, a pmgraIT' SiIT'ply loads an !D. produce the address requ~red for the Jump. Nct~ce that :n the number into the accumulator, then jumps to the table logic. following example, entry FOUR and FIVE go to the same lo- The table logic adds the contents of the accumulator, three cation. This is a variation that is quite useful. Perhaps the times, to the address of the first jump instruction, which is values 4 and 5 are invalid and an error routine needs to be stored in the DCO registers. The sum is moved (via the a called. The jump table will satisfy this condition in a most registers) to the program counter and the jump is effected. efficient manner without a separate compare instruction for each invalid value. Also notice that the entry points need not be in any particular sequence; however, in this example A 1 must be the first entry point encountered, and it must have the lowest address in order for the arithmetic to be valid. "JUMP TABLE PROGRAM. JUMP NUMBER IS ASSUMED TO "BE IN THE ACCUMULATOR. This displacement table is most efficient since the table values JUMP DCI JMPO LOAD THE FIRST JUMP are only one byte each. If an entry is beyond the 256 range ADDRESS INTO DCO it is possible to treat it as a special case within the table. ADC ADD THREE TIMES THE Notice that A6 is more than 256 bytes beyond the start of BRANCH A 1 and is too large to insert before A4. To include it insert ADC INDEX TO DCO, FOR THE a JMP A6 prior to the coding at A4. If this instruction is ADC THREE BYTES OF A JMP labeled A66, an entry in the table would be: INSTRUCTION LR O,DC MOVE DCO TO PCO LR PO,O JUMP OCCURS HERE JMPO JMP AO JMP A1 JMP A2 SIXS DC (A66-A 1-1 28) 82 JMP A3 JMP A4 The value of THRE would now become 85. etc. 7.5.2 Jump Table Using Address Constants "THE JUMP NUMBER IS ASSUMED TO BE IN THE Another jump table technique uses a table of addresses "ACCUMULATOR which are indexed as in the previous example. However, JUMP DCI ZERO LOAD FIRST TABLE instead of a JUMP (LR PO,O) to the jump table, the address LOCATION INTO DCO is loaded from memory into Q. The LR PO,Q instruction then ADC ADD VALUE FROM causes a direct jump to the address in Q. The major advan- ACCUMULATOR tage of this technique is that the table is only two bytes per LM LOAD TABLE VALUE entry, as compared to three bytes in the previous example. TO ACCUMULATOR It also executes using fewer instruction cycles. DCI (A1+128) LOAD FIRST ORIGIN ADC ADD DISPLACEMENT "THE JUMP NUMBER IS ASSUMED TO BE IN THE VALUE ADDED TO DC "ACCUMULATOR LR Q,DC RECALL DC TO Q JUMP DCI JMPO LOAD THE FIRST JUMP LR PO,Q JUMP TO ROUTINE ADDRESS INTO DCO ZERO DC (Al-Al-128) VALUE = -128 ADC ADD TWICE THE JUMP ONE DC (A2-A 1-128) VALUE =- 78 ADC NUMBER. DCO NOW AD- TWO DC (A5-A 1 -128) VALUE = 22 DRESSES A JUMP ADDRESS THRE DC (A4-A 1 -128) VALUE = 82 LM LOAD FIRST BYTE OF JUMP FOUR DC (ERR-A 1-128) VALUE =- 53 ADDRESS F!VE DC (ERR-A 1-128) VALUE = - 53 LR QH,A STORE IN QH SIX DC (A3-A 1-128) VALUE =- 28 LM LOAD SECOND BYTE OF SVEN DC (A6-A 1 -1 28) VALUE = 207 JUMP ADDRESS TOO LARGE! LR QL,A STORE IN QL LR PO,Q BY iviOViNG Q TO PO, rOReE JUMP JMPO DC AO DC A1 DC A2 Values are displaced by -128 to take into account the fact DC A3 that the DCI instruction points to the middle of the table DC A4 (A 1+ 128). Therefore, addresses are created as shown on the etc. following page. I-Hi ARBITRARY DECIMAL ADDRESSES: ~ DCI MASK STORE THE MASK ADDRESS IN H -- 2100 A1 STARTS HERE LR H,DC 2150 A2 STARTS HERE DCI BUFA STORE THE BUFFER w t:l STARTING ADDRESS IN Q :i 2175 ERR STARTS HERE LR Q,DC a: ~ 2200 A3 STARTS HERE LI CNT USE SCRATCHPAD BYTE III OASA 2250 f - - - - - - - - i A5 STARTS HERE LR O,A COUNTER LOOP LM LOAD NEXT BYTE 2310 f - - - - - - - - - 1 A4 STARTS HERE L1 LR DC,H LOAD MASK ADDRESS 2356 L2 NM AND ACCUMULATOR WITH 2435 f - - - - - - - - - 1 A6 STARTS HERE} MASK OUT OF RANGE L3 LR DC,Q RELOAD BYTE ADDRESS 2585 f - - - - - - - - - 1 A6 ENDS HERE L4 ST STORE MASKED BYTE IN ORIGINAL BYTE POSITION L5 LR Q,DC SAVE INCREMENTED BUFFER ADDRESS IN Q 7.6 STATUS, BITS AND BOOLEAN LOGIC L6 DS 0 DECREMENT COUNTER The F8 instruction set is rich in boolean logic instructions L7 BNZ LOOP RETURN FOR MORE which are very useful in applications manipulating bits and control lines. In addition to demonstrating use of the NM instruction, the Examples given in the following subsections demonstrate above example shows how to process data in a single buffer, some elementary uses of boolean logic instructions, along restoring a modified byte to its original byte position. with some less obvious but commonly needed routines. 7.6.1 Manipulating Individual Bits The program proceeds as follows: Immediate boolean instructions specify data in the operand The instructions preceding LOOP load the mask address into of the instruction; they may be used to set or reset individual H and the beginning buffer address into Q. The buffer length bits within the accumulator. is loaded into scratchpad byte A which is osed as a counter. To reset one or more bits within the accumulator, AND the accumulator contents with a mask which is the complement LOOP The data counter holds the initial buffer address of the bits to be reset. For example, the following instructions when this instruction is first executed and the next will reset bit 3 of scratchpad byte 1: byte address on all subsequent executions of this instruction. This instruction therefore loads the LR A,1 LOAD SCRATCHPAD BYTE next byte from BUFA. 1 INTO A NI H'FT MASK OUT BIT 3 L1 Load the mask address from the H registers into LR 1,A RETURN TO SCRATCHPAD the data counter, wiping out the incremented buffer BYTE 1 address that resulted from instruction LOOP. Similarly, individual bits can be set by ORing the accumu- L2 AND the contents of the accumulator with the lator with a mask which has a 1 in every bit position that mask byte. The fact that the AND with memory is to be set. For example, bit 3 of scratchpad byte 1 contents instruction will increment the address in the data can be set to 1 as follows: counters is not consequential since this incremented address is not saved. On the next execution of LR A,1 LOAD SCRATCHPAD BYTE this instruction, the original mask address stored 1 INTO A . in the H registers will be reused. 01 H'04' SET BIT 3 LR 1,A RETURN TO SCRATCH PAD L3 Reload the buffer address from the Q registers. BYTE 1 This is the same address that was used by instruction LOOP. Masks may also be accessed out of RAM or scratch pad memory. The following instruction sequence takes every L4 Store the contents of the accumulator back in the byte from a buffer CNT bytes long, starting at BUFA; it sets buffer. Since the address loaded by L3 is the same to 0 the bits specified by a mask stored in a memory byte address as was used by instruction LOOP, the addressed by MASK. BUFA, CNT and MASK are symbols masked byte will be stored back in the same memory which have been given arbitrary values below. location from which it was loaded. BUFA EQU H'2380' L5 This time save the incremented address in the MASK EQU H'08FF' data counters back in the Q registers. CNT EQU 50 L6 Decrement the counter in scratch pad byte O. If L7 the result is zero, end. If the result is not zero process the next byte of the buffer. 7-17 By using the NM instruction, the above example is resetting IN 0 INPUT NEW STATUS (to 0) selected bits from every byte in BUFA. By merely re- S2 LR 4.A SAVE IN SCRATCHPAD placing the NM instruction with an OM instruction, selected BYTE 4 bits from every byte of BUFA could be set to 1. S3 XS 3 EXCLUSIVE-OR ACCUMU- LATOR WITH OLD STATUS By storing the mask byte in a scratchpad register, the pro- S4 LR 5.A SAVE "CHANGED gram can be greatly simplifip.n Thl;! illstruct!(I!"' seque'"!ce STATUSES" INDICATORS below is similar to the previous example, but the mask byte IN 5 is stored in scratchpad register 1, and the DCl registerS are S5 NS 3 AND WITH OLD STATUSES used to hold the buffer address, rather than the Q registers. S6 LR 6.A SAVE "STATUSES TURNED OFF" IN 6 Notice that at the LM instruction (LOOP), DCO is incremented; S7 XS 5 EXCLUSIVE-OR WITH prior to the ST instruction, DCO and DC1 are exchanged. "CHANGED STATUSES" The ST instruction then increments DCO, thus both addresses S8 LR 7.A SAVE "STATUSES TURNED remain synchronized. ON" IN 7 S9 LR A,4 NEW STATUS FROM SAVE MASK EQU B'any binary value' S10 LR 3.A OLD STATUS FROM NEXT BUFA EQU H'2380' USAGE. CNT EQU 50 Suppose the old status was: ONE LI MASK 7 6 5 432 1 0 Bit No. TWO LR l.A Old Status = 1 0 1 1 1 0 0 0 DCI BUFA STORE BUFFER ADDRESS XDC IN DCO AND IN DCl Suppose the new status is: REGISTERS DCI BUFA 7 6 543 2 1 0 Bit No. LI CNT USE SCRATCHPAD BYTE 0 New Status = 1 1 0 1 0 1 1 0 LR O.A AS A COUNTER LOOP LM LOAD NEXT BYTE Bits 6, 2 and 1 have turned on. THREE NS AND WITH MASK IN Bits 5 and 3 have turned off. SCRATCH PAD BYTE 1 Bits 6, 5, 3, 2 and 1 have changed. XDC ST STORE IN ORIGINAL Here is the result of instruction S3: LOCATION OS o DECREMENT COUNTER 7 6 543 2 1 0 Bit No. BNZ LOOP RETURN FOR MORE Old Status 101 1 100 0 New Status 11010110 Again this routine can be simplified even further by deleting Changed Statuses 01101110 instructions ONE and TWO and changing instruction THREE to one of the following: Here is the result of instruction S5: NI MASK AND WITH MASK 7 6 543 2 1 0 Bit No. 01 MASK OR WITH MASK Changed Status 01101110 XI MASK EXCLUSIVE OR WITH MASK Old Status 10111000 This change would result in saving two bytes. however the Turned Off 00101 000 loop time would be increased by 1.5 cycles. Here is the result of instruction S7: 7.6.2 Testing for Status 7 6 543 2 1 0 Bit No. Turned Off 0010100 0 II The EXCLUSIVE-OR instruction is very useful as a means of Changed Statuses 01101110 detecting changed statuses. There are many applications in which it will be necessary to keep a record of status for various Turned On o 1 00 0 1 1 0 control lines, and to detect when individual control line sta- tuses change and how they change. As illustrated in the instruction sequence below, eight control iines have their 7.7 POWERING UP AND STARTING PROGRAM statuses maintained in scratchpad byte 3. When new sta- EXECUTION tuses are input from I/O port 0, they are temporarily saved Whp.n power is turned on, an peo reg!sters !n an F8 micro in scratch pad byte 4. By EXCLUSIVE-ORing the new and old processor system are set to O. Therefore the first instruction statuses, the accumulator identifies those status bits which executed is located at memory byte O. have changed. By ANDing the changed status indicators with the old status, those indicators which went from "on" Every F8 microprocessor system must, therefore, have a to "off" are identified. By EXCLUSIVE-ORing this result with memory device (either a 3851 PSU, 3852 OMlor 3853 SMI). the changed status indicators, those statuses which went The first program to be executed must be originated at H'OO', from "off" to "on" are identified. as illustrated on the following page. I ORG H'oo' • Resets the Interrupt Control Bit (lCB) START FIRST INSTRUCTION • Sets control block on the 3852 MI circuit EXECUTED When power is connected to the circuit or the reset line goes The power on detect circuit for an F8 system is located in the low, the CPU clears the program counter (PCO), pushing its CPU. This circuit insures that all critical control circuits and previous contents into the stack register (PC1). Therefore, registers are in a valid operating condition when power is the instruction in location zero is executed first. The inter- first applied. It performs the following functions: rupt control bit is also cleared at this time. The rest of the F8 system is initialized under program control. The local in- • Pushes previous contents of the program counter to terrupt block of the individual memory devices must be loaded the stack register before allowing any interrupts to occur. Output latches must • Resets the program counter to address "0000" be reset to zero before they may be used to input data . 7-19 INPUT/OUTPUT PROGRAMMING Input/output programming covers program steps that cause ready to transmit or receive data. The 3850 CPU continuously data to be transferred between the F8 microprocessor system inputs a byte of data from the port until the "ready status" and the world beyond the microprocessor system. appears. For example, suppose a 1 in the high order bit (bit 7) of the I/O port signifies a ready status; the following routine There are three separate and distinct types of input/output will input a byte of data via port 0: (I/O) programming: Programmed I/O, Interrupt I/O and Direct Memory Access (DMA). *ROUTINE TO INPUT A BYTE OF DATA VIA PORT 0, POLLING *ON STATUS TO SYNCHRONIZE WITH THE EXTERNAL Programmed I/O is characterized by the 3850 CPU executing *DEVICE. an instruction to initiate and control the I/O transfer of a single INa LIS a FIRST CLEAR THE PORT byte of data, via an I/O port. The key feature of programmed OUTS a I/O is that it is initiated by the CPU, on a byte-by-byte basis. LOOP INS a INPUT STATUS BP LOOP RETURN IF BIT 7 is a Interrupt I/O is characterized by an external device issuing La INS a BIT 7 IS 1. INPUT A DATA an interrupt to the 3850 CPU; (this concept is discussed in BYTE Section 2.2.2). The interrupt does not itself cause any input ST STORE IN MEMORY BYTE or output data transfer to occur; rather it initiates execution ADDRESSED BY DCa of a program which performs any required programmed I/O L1 PI TEST BRANCH TO END OF INPUT TEST DMA has been described conceptually in Sections 2.2.4, L2 BR LOOP RETURN FROM TEST FOR 2.6.3 and 2.8. DMA transfers data between a memory device MORE INPUT within the microprocessor system and any device external to L3 RETURN FROM TEST FOR the microprocessor system, in parallel with other micropro- END cessor operations. DMA is initiated using programmed I/O and, optionally, may terminate with an interrupt. Three features of the above routine need to be explained. The first two instructions clear the output port. This is necessary The use of software clocks is also covered in this chapter. because data being input at an I/O port is ORed with what- Even though software clocks have nothing to do with trans- ever is already in the port. If, by chance, the high order bit fer of data between the microprocessor system and the out- of the last data byte input was 1, this would be interpreted side world, they do allow events within the microprocessor as a ready status. system to be synchronized with real time. The data which is input to the accumulator by instruction 8.1 PROGRAMMED 1/0 LOOP will be interpreted as a byte of status. While in this A programmed input or output operation moves a byte of simple application only the high order bit of the status byte data from the 3850 CPU accumulator either to an I/O port is being interrogated, in any real application all eight bits of (OUT), or from an I/O port to the accumulator (IN). the status byte could be assigned meaning. In this case, when bit 7 of the status byte is tested to be 1, a byte of data Four instructions enable programmed I/O: INS and iN enable is input by instruction La to the accumulator. This routine input, while OUTS and OUT enable output. (See Sections assumes that the time delay between execution of instructions 6.16, 6.18, 6.33 and 6.34.) LOOP and La is sufficient for the external device to transmit a data byte. Note that a number of I/O ports are accessed by I/O instruc- tions, but transfer no data between the microprocessor system This routine assumes that an indeterminate number of char- and the outside world. These I/O ports hold control information acters are expected on input. A subroutine named TEST is used by interrupt I/O, DMA and real time clocks. Section 6.16 called to determine if more bytes of data are expected. The summarizes the I/O port addresses used by the F8, and operations performed by subroutine TEST are immaterial to indicates how the individual port addresses may be used. the 1;0 routine. Subroutine TEST must have two returns; to instruction L2 if another byte of data is to be input, or to in- Programmed I/O is a very open ended subject, since it is de- struction L3 if data input is complete. pendent on how external circuitry accesses the I/O ports. The following subsections describe some general approaches to Each byte of data that is input to the accumulator in sub- I/O programming as seen by the CPU. Actual applications will routine INa must be stored in some read/write memory loca- usually require modified versions of the given programming tion. INa assumes that the DCa registers address a RAM byte techniques. into which the data must be stored. This assumes that before INa is called as a subroutine, the beginning address of a RAM 8.1.1 Polling on Status data buffer is loaded into the DCa registers. Data bytes, as A key feature of programmed I/O is that the microprocessor they are input, will be stored in ascending bytes of the ad- system and external devices operate at different speeds; the dressed RAM data buffer. Scratchpad bytes can also be used external device must transfer data at a rate which is slower to hold data being input. than the I/O program's execution speed. Subroutine OUTO, described below, is a variation of subroutine The simplest way of handling programmed I/O, when external INa. OUTO outputs data from a RAM buffer. The only dif- devices run slower than the microprocessor, is to have the ex- ference between subroutines INa and OUTO is that in OUTO, ternal device input a "status byte" to the I/O port when it is once a ready status has been detected, the data byte which 8-1 is to be output must first be transferred from memory to the data. Depending on the design of the cassette drive, accumulator before being output to port O. the cassette drive controller may transmit a status byte back to the microprocessor after each individual Both subroutines INO and OUTO can address any port that data byte has been received. This status byte reports the INS and OUTS instructions can address. In order to ad- that the previous data byte has been recorded accu- dress other ports it is only necessary to replace the INS and rately, and the controller is ready to receive and record OUTS instructions vv;th II\J and OUT instructions. the next byte of data. *ROUTINE TO OUTPUT A BYTE OF DATA VIA PORT 0, POL- 6) After the microprocessor has completed transmittal of *LlNG ON STATUS TO SYNCHRONIZE WITH THE EXTERNAL an entire record of data, it must send a control signal *DEVICE to the cassette drive commanding the cassette drive OUTO LI o FIRST CLEAR THE PORT to stop forward movement. OUTS o LOOP1 INS o INPUT STATUS 7) When all records have been written to the cassette BP LOOP1 RETURN IF BIT 7 is 0 drive, the microprocessor will issue a third control com- LM BIT 7 IS 1. READ FROM mand which causes the cassette drive to mechanically MEMORY THE BYTE TO BE rewind. OUTPUT MO OUTS 1 OUTPUT THE DATA BYTE Observe that this simple application receives either data or M1 PI TEST BRANCH TO END OF INPUT status from the keyboard, then outputs either controls or TEST data to the cassette drive; additional status information may M2 BA LOOP1 RETURN FROM TEST FOR come back from the cassette drive. MORE INPUT M3 RETURN FROM TEST FOR Any external device may transmit two types of information END to the microprocessor system: data or status. Any external device may receive two types of information from the microprocessor system: data or controls. 8.1.2 Data, Status and Controls Thus there are four types of information that may be trans- Observe that in Section 8.1.1, a byte input by an external ferred between the microprocessor system and an external device may be interpreted as status information or as data. device. They are: Similarly, the 3850 CPU may output a byte which is to be interpreted as control signals or as data. a) data in To illustrate, consider an F8 microprocessor system being b) status in used to read data input from a keyboard, block the data into c) data out 256 byte records, then write the records out to a cassette. d) control out Events would proceed as follows: 1) Using a programmed input sequence such as INO, An external device may communicate with the microproces- interpret a byte input from the keyboard as status. sor system using one, two, three or all four of the above types When a ready status is sensed, interpret the next of information. For example, the keyboard uses "data in" and byte arriving from the keyboard as data. "status in" but does not use "data out" or "controls out". The cassette drive in the illustrated application uses "status in", 2) A subroutine such as TEST is called to create a 256 "data out" and "controls out" but does not use "data in". Of byte record in RAM, in the format needed for output course the cassette drive would be capable (at another time) to the cassette. of using "data in", when the data which was recorded on the cassette is subsequently read back into the microprocessor 3.) When the microprocessor is ready to write a record system. to the cassette, it must first turn the cassette drive motor on, since the cassette drive will be stationary It is .feasible to use one port for all four of the information during the intervals when records are not being written transfer types listed above when communicating with any out. The microprocessor will turn the cassette drive one external device. For example, ane !/O port cou!d be used on by outputting an appropriate control byte whose bit to receive status and data from the keyboard, and could also pattern is determined by the specifications of the be used to receive status or data from the cassette drive and cassette drive controller. to output controls or data to the cassette drive. However, if more than one type of information is to go through one 1/0 4) The cassette drive will respond to the control byte. port, exte!'"na~ ~og!C must have the means of mu!t:p!c;dng :n- commanding the drive be turned on by transmitting formation in or out. A scheme that uses more 1/0 ports, but back a status byte indicating that the command was less external logic, allocates one port for data in or out and successfully executed and the drive is now ready to another port for status in or controls out. For example, 1/0 receive data. port 0 may be assigned to keyboard status in, 1/0 port 1 may be assigned to keyboard data in, 1/0 port 4 may be assigned 5) Upon receiving back the ready status from the cassette to cassette status in and controls out and 1/0 port 5 may be drive the microprocessor will output 256 bytes of assigned to cassette data in and out. I 8.1.3 Parallel Data and Control Ports processor system cannot be predicted. For example, an external device may only communicate to the microprocessor Many applications will require data to be handled on paths under distress circumstances, atwhich time the microprocessor that are more than eight bits wide. Sixteen-bit data, for must execute a program to compute and output needed cor- example, is a common word size. Less frequently, it will be rection data. When the external device's need for access necessary to handle more than eight control lines at a time. to the microprocessor system cannot be predicted, an inter- rupt is the only reasonable way in which the external device Data paths that are more than eight bits wide can be handled can gain control of the microprocessor system. in 8-bit units, sequentially through a single port. Alternatively, two or more ports may be assigned to one external data bus 8.2.1 The Interrupt Sequence so that. whenever the microprocessor inputs data from an external device or outputs to the external device, it accesses Each 3851 PSU in an F8 microprocessor system has an each 110 port allocated to the data bus. This is illustrated be- external interrupt line, as does the 3853 SMI device, if present. low in subroutine IN16, which inputs data in 16-bit units via ports 4 (bits 0-7) and port 5 (bits 8-15). The sequence of events surrounding an interrupt is as follows: *ROUTINE TO INPUT 16 BITS OF DATA VIA PORTS 4 AND 5, 1) For interrupts to be processed, interrupts must be *POLLING ON STATUS VIA PORT a TO SYNCHRONIZE WITH enabled within the 3850 CPU and at the device re- *THE EXTERNAL DEVICE ceiving the interrupt request signal. At the 3850 CPU, IN16 LIS a FIRST CLEAR THE STATUS all interrupts are enabled or disabled. At each 3851 PORT TO REMOVE PREVIOUS or 3853 device, the individual interrupt line at that OUTS a READY STATUS device is enabled or disabled. This is described in LOOP INS a INPUT STATUS Section 8.2.2. BP LOOP RETURN IF BIT 7 IS a La INS 4 BIT 71S 1.INPUT FIRST DATA 2) More than one device may simultaneously request to BYTE interrupt the 3850 CPU; that is, interrupt request sig- ST STORE IN MEMORY BYTE nals may be true, simultaneously, at more than one ADDRESSED BY DCa device. When this happens, priorities are arbitrated INS 5 INPUT SECOND DATA BYTE as described in Section 8.2.3. ST STORE IN NEXT MEMORY BYTE (ADDRESSED BY DCa) 3) When a valid interrupt request signal is detected by the L1 PI TEST BRANCH TO END OF INPUT 3850 CPU, it ceases current program execution at the TEST conclusion of the instruction currently being executed. L2 BR LOOP RETURN FROM TEST FOR (Certain instructions are exempt, as described below.) MORE INPUT L3 RETURN FROM TEST FOR NO 4) The 3850 CPU sends out an interrupt acknowledge MORE INPUT signal. The way in which this signal is trapped imple- ments interrupt priority when more than one interrupt 8.2 INTERRUPT I/O request line is true, as described in Step 2. Two circumstances under which interrupts are commonly 5) When the 3850 CPU sends out an interrupt acknowl- used to control 1;0 operations are: edge signal. it clears the interrupt enable status within The programmed 110, described in Section 8.1, has the severe the 3850 CPU, thus disabling all subsequent interrupts. disadvantage that the microprocessor system spends a great As described in Section 8.2.4, interrupts must be deal of its time reading a status byte and waiting for the sta- re-enabled, under program control, when such a step tus byte to signal ··ready". If the external device operates at is appropriate to program logic. speeds close to that of the microprocessor, the wasted time may be unavoidable. For example, if the microprocessor can 6) Each device that has an interrupt request line also has only execute ten instructions between each byte transmitted a 16-bit address register which holds the address of or received by the external device, it is probable that these the first instruction to be executed following the inter- ten instructions can be effectively used testing or processing rupt. The 3851 address register is a non-programmable each data byte as it is transferred. On the other hand, if the mask option. The 3853 address register is made up 3850 CPU can execute approximately one hundred instruc- of two I/O ports which are loaded with an address by tions between bytes of data being transmitted to or from the appropriate I/O instructions. As described in Section external device, there is sufficient time between data trans- 8.2.4, bit 7 of the interrupt address will always be 1 fers for the microprocessor to be doing other useful work for an external interrupt. and will always be a for a which mayor may not be related to the data transfer taking local timer interrupt. place. If instead of sending a ready status, the external de- vice transmits an interrupt request signal every time it is The device that traps the interrupt acknowledge sig- ready to transmit or receive a data byte, this signal can be nal output in step 5 responds by transmitting the used by the 3850 CPU to suspend executing whatever pro- contents of its interrupt address register as the next gram was being executed, process a single byte of data, then contents of PCO registers. return to the suspended program. 7) PSU and MI logic, under CPU control, moves the con- The transfer of a sequence of data bytes at a known data rate tents of PCO to PC 1, then loads the address from step 6 constitutes a sequence of predictable events. In many ap- into PC 0; thus a program dedicat,ed to the acknowl- plications an external device's need for access to the micro- edged interrupt request line is executed. 8-3 An interrupt will not be acknowledged at the conclusion of 8.2.3 Interrupt Priorities any of the following instructions: When an F8 microprocessor system has more than one in- PK terrupt line, priorities are determined on the basis of "daisy PI chaining", as illustrated in Figure 8-1. POP JMP OUTS (if not port 0 or 1) OUT (if not port 0 or 1) EI 3850 3851 3851 3853 ETC. CPU psu psu SMI LR W,J An instruction other than one of the above must be executed PIN POUT PIN POUT PIN before an interrupt will be acknowledged. IREQ = COMMON INTERRUPT REQUEST LINE PIN = PRIORITY IN (INTERRUPT ACKNOWLEDGE) When power is first turned on, interrupts are disabled. POUT = PRIORITY OUT (INTERRUPT ACKNOWLEDGE) EACH DEVICE RECEIVING PIN PASSES THE SIGNAL ON AS POUT, UNLESS IT IS REQUESTING AN INTERRUPT, IN WHICH CASE IT TRAPS PIN. 8.2.2 Enabling and Disabling Interrupts Fig. 8-1. Daisy Chaining and Interrupt Priority Determination As described in Section 2.4.3, bit 4 of the 3850 CPU W reg- ister is an Interrupt Control bit. When this bit is set to 1, The daisy chain sequence is a hardware feature of an F8 micro- interrupt requests to the CPU are enabled; when this bit is processor system; when the system is configured, the inter- reset to 0, no interrupt request to the CPU will be acknowl- rupt acknowledge signal from the CPU is chained from one edged. ICB is set to 1 by the EI instruction or by a LR W,J device to the next. This determines interrupt priorities. instruction; it is reset to 0 by the DI instruction or by a LR W,J instruction. The only thing a programmer can do to modify interrupt pri- orities is to disable external interrupts at selected devices by Individual interrupt request lines are controlled at each de- appropriately loading the interrupt control 1/0 port at that vice via an I/O port which is set aside as an interrupt control device with some value other than H'Ol'. (See Section 8.2.2 buffer. and Table 8-1.) For the 3851 PSU's, the interrupt control 1/0 port address is It should be clearly understood that interrupt priorities, as B'xxxxxxl0'; xxxxxx is the 1/0 port select code, which may be described in this section, apply only to interrupt request any number from 1 to H'3F'. The 3853 interrupt control 1/0 signals competing for the 3850 CPU's next interrupt service. port address must be H'OE'. This address is also available on a 3851 PSU; when xxxxxx is H'03', the 3851 interrupt control There is nothing to prevent an interrupt from interrupting a 1/0 port address becomes H'OE'.: previous interrupt; however, this type of nested priority is a function of how programs have been written. Once an in- B'xxxxxxl0' = B'00001110' = H'OE' terrupt has been acknowledged and is being serviced, and When a 3853 SMI device is present, a 3851 PSU with a chip the ICB bit in the CPU is set to 1, the current interrupt service select of H'03' cannot also be present. routine can itself be interrupted. The following two instructions load the interrupt control In order to prevent an interrupt service routine from being 1/0 port: itself interrupted, the ICB bit in the CPU W register must be left at zero until the interrupt service routine has completed LI VAL execution. OUT IPRT Figure 8-2 illustrates the concept of nested interrupts. IPRT must be equated to the interrupt control 1/0 port address. FIRST INTERRUPT VAL must be equated as shown in Table 8-1. Value VAL is I equated to I Effect H'OO' I Interrupts disabled at this device. -I I H'01' External Interrupt enabled, timer interrupt I disabled. H'02' I Interrupts disabled at this device (same as H'OO'). H'03' External interrupts disabled, timer interrupt enabled. Table 8-1 _ Contents of Interrupt Control 1;0 Ports D = INTERRUPTS DISABLED (ICB = 0) I = INTERRUPTS ENABLED BY FIRST INTERRUPT SERVICE ROUTINE (ICB = 1) Timer interrupts are described in Section 8.4. Fig. 8-2. Two Levels of Interrupt The 3853 SMI device will not pass on an interrupt acknowl- 8.2.5 Making 3851 PSU Interrupt Address edge signal; therefore, it must be at the end of the daisy Programmable chain, and will have lowest interrupt priority. The fact that the 3851 PSU's interrupt address is a permanent feature of the device is not a problem in applications where 8.2.4 Program Response to an Interrupt this address may have to be varied. Using a branch table (as described in Section 7.5), a number of possible post-interrupt There are three program steps which may be needed prior service routine execution addresses may be maintained. The to an interrupt in order to prepare to receive interrupts. They following routine shows how an external device may use a are: PSU 1/0 port to provide an index identifying the service rou- tine which must be executed following the interrupt. 1/0 1) If a 3853 SMI device is present, the interrupt address port 4 has been arbitrarily selected as the 1/0 port address. register of the 3853 must be loaded with the address The data byte at 1/0 port 4 selects an address from a branch of the first instruction to be executed after an inter- table, as follows: rupt from the 3853 is acknowledged. As described in Sections 2.7 and 6.16, 1/0 port addresses H'OC' and WaD' have been reserved for the upper and lower interrupt address bytes, respectively; therefore the *POST INTERRUPT SERVICE ROUTINE FOR PSU 1 post-interrupt execution address can be loaded as RC11 LR K,P SAVE RETURN ADDRESS ON follows: THE STACK PI CALL LI ADHI INS 4 INPUT PROGRAM SELECT OUTS H'OC' BYTE LI ADLO LR RX SAVE INDEX VALUE OUTS WOO' PI BRANCH CALL BRANCH TABLE SUB- ROUTINE ADHI and ADLO are symbols which must be equated to the high and low bytes of the selected execution address. Note that the 3851 PSU has the post- 8.2.6 Simple I/O Interrupts interrupt execution address as a permanent feature of the chip mask; therefore, each 3851 PSU has a In Section 8.1.2, a simple application was described, where fixed post-interrupt execution address associated data is input at a keyboard and recorded in 256 byte records with it. on a cassette. 2) Interrupts must be selectively enabled or disabled at A cassette may record data at a rate of approximately 200 3851 and 3853 interrupt control ports, as described bytes/second. With time taken to start and stop the cassette, in Section 8.2.3. two or three seconds may elapse each time a record is out- put to the cassette. Preventing data from being input at the 3) The 3850 CPU master interrupt enable bit (ICB) must keyboard while it is being output to a cassette is both incon- be set to 1, as described in Section 8.2.3. venient and unnecessary. Simple 1/0 interrupts may be used to output data to the cassette, byte-by-byte. These few When an interrupt is acknowledged, events within the 3850 instructions are sufficient to service each interrupt. CPU proceed exactly as if a subroutine had just been called: the content of PCO is moved to PC1, and the content of the selected device's post-interrupt address register is moved to PCO. Interrupts should therefore be handled as though a *PROGRAM TO WRITE ONE BYTE TO A CASSETIE, FOLLOW- subroutine had just been executed, as described in Section *ING AN INTERRUPT 7.3. For example, the first instructions executed following CRW LM LOAD NEXT BYTE an interrupt might be: ADDRESSED BY DCa OUT CASS OUTPUT TO CASSETIE LR K,P SAVE CONTINUATION EI ADDRESS IN K POP RETURN FROM INTERRUPT PI CALL SAVE CONTINUATION ADDRESS IN STACK Returning from an interrupt to the interrupted program is The key concept here is that the F8 is uniquely suited to pro- identical to returning from a subroutine to the calling pro- cessing a large number of simple interrupts. If the post- gram; however, since a program may be interrupted any time interrupt program will not itself be interrupted, and if it will interrupts have been enabled, parameter passing and multi- call no subroutines, then merely ending it with a POP in- ple returns do not apply to post-interrupt programs and should struction turns it into a complete interrupt service routine. not be used. Do not save the return address in the stack; do not call any starting or ending subroutines (e.g., CALL or RTRN). Remember that the first interrupt service routine must enable ICB if second level interrupts are to be allowed (as illustrated in Figure 8-2). For example, see Section 2.8.7. 8-5 8.2.7 A Sample Program S19 L1SU 4 INPUT NEXT EIGHT BYTES FROM KEYBOARD TO Figure 8-3 illustrates a configuration for the key to cassette S20 PI INKB SCRATCHPAD BUFFER 0'47' application described in Section 8.1.2, except that 32 byte TO 0'40' records are to be written to the cassette. ~8UFFER is NOW READY TO 8E OUTPUT TO CASSETTE. S21 LI H'3F' LOAD BUFFER INITIAL ADDRESS S22 LR O,A (0'77') INTO SCRATCHPAD 3851 BYTE 0 3850 PSU DEVICE SELECT S23 LI ONC TURN CASSETTE ON ~ I INTERRUPT 1--_-r-_-+-~.....JtD j""""-- CONTROL S24 OUTS 5 J 0 PORT SELECT S25 BR START RETURN FOR NEXT RECORD '---.---'---r---' 8'000001' *INPUT SUBROUTINE INKB STORES A BYTE OF DATA INPUT STATUS FROM KEYBOARD STATUS FADM CASSEITE *FROM KEYBOARD INTO SCRATCHPAD BYTE ADDRESSED CONTROLS TO CASSETTE °tETvAB~~~~-----.J "BY ISAR ' - - - -.... OATA TO CASSETTE INKB LR K,P SAVE RETURN ADDRESS IN K LO CLR CLEAR PORT 0 Fig. 8-3. Two Devices Servicing a Keyboard to Cassette OUTS 0 Application INPUT STATUS LOOP INS 0 Ll BP LOOP *PROGRAM TO RECEIVE DATA FROM THE KEYBOARD USING L2 INS 1 INPUT DATA *PROGRAMMED I/O L3 LR D,A STORE IN ISAR BUFFER *SCRATCHPAD BYTES 0'40'TO 0'77' MAKE UPTHE 32 BYTE BR7 LO RETURN IF NOT EIGHTH BYTE *BUFFER. L4 PK RETURN *SCRATCHPAD BYTES 0'20' TO 0'37' ARE USED AS A TEM- *INTERRUPT SERVICE ROUTINE, EXECUTED TO WRITE ONE *PORARY BUFFER TO HOLD DATA WHILE THE MAIN BUFFER "BYTE TO CASSETTE. *IS BEING WRITTEN TO CASSETTE ORG H'OOOO' START L1SU 3 INITIALIZE ISAR TO ORG H'0280' Sl L1SL 7 TEMPORARY BUFFER EO LR l,A SAVE ACCUMULATOR IN S2 LIS H'Ol' ENABLE EXTERNAL INTER- SCRATCHPAD BYTE 1 RUPTS AT PSU El LR A,IS SAVE ISAR IN SCRATCHPAD OUTS 6 BYTE 2 EI ENABLE INTERRUPTS E2 LR 2,A S3 PI INKB INPUT NEXT EIGHT BYTES E3 LR A,O LOAD SCRATCHPAD BYTE 0 FROM KEYBOARD CONTENTS INTO ISAR S5 L1SU 2 DECREMENT UPPER DIGIT E4 LR IS,A OF ISAR E5 INS 5 RECEIVE STATUS FROM S6 PI INKB INPUT NEXT EIGHT BYTES CASSETTE, INS SETS STATUS FROM KEYBOARD E7 BZ FO *AFTER INPUTTING 16 BYTES FROM THE KEYBOARD, IT IS E8 LR A,S IF NOT END OF CASSETTE, *ASSUMED THAT ANY RECORD OUTPUT TO THE CASSETTE E9 OUTS 4 OUTPUT NEXT BYTE *IS COMPLETE. MOVE DATA FROM 0'37' - 0'20' TO 0'77'- El0 LR A,IS MOVE ISAR TO A 0'60'. Ell AI H'FF' DECREMENT ALL 6 BITS OF S8 L1SL 7 LOAD FIRST SOURCE BYTE ADDRESS ADDRESS E12 CI 0'37' TEST IF RESULT IS 0'37' S9 L1SU 3 E13 BZ E17 RETURN IF NOT S10 LR A,S LOAD NEXT BYTE E14 LI STOP IF IT IS, ISSUE A STOP Sll L1SU 7 COMMAND S12 LR D,A STORE NEXT BYTE E15 OUTS 4 S13 8R7 S9 iF NOT END OF BUFFER, E16 Li O'77 J RESET TO TOP FOR NEXT RETURN FOR NEXT BYTE OUTPUT S14 L1SU 2 IF END OF F!RST BUFFER, E17 LR O,A SAVE !SAR ADDRESS FOR S15 LR A,S MOVE SECOND BUFFER REPEAT MOVE FOR SECOND 8 BYTE E18 LR A,2 NEXT BYTE BEFORE RETURNING, RESTORE ACCUMULATOR I L1SU 6 BUFFER LR IS,A AND ISAR LR D,A LR A,l BR7 S14 EI S16 L1SU 5 INPUT NEXT EIGHT BYTES POP FROM KEYBOARD TO FO LI REW IF CASSETTE IS FULL, ISSUE S17 PI INKB SCRATCHPAD BUFFER 0'57' OUTS 4 REWIND COMMAND TO 0'50' BR E18 8-6 I The logic of this program is relatively simple. Scratchpad this is the address which must be in the 3851 interrupt bytes 0'77' to 0'40' constitute a 32-byte buffer, the contents address register. of which is output as a record to the cassette. It is assumed that this record can be written to the cassette in less time The symbols STOP and REW in the interrupt service routine than an operator takes to enter 16 digits at the keyboard. must be equated to the actual bit pattern that the cassette Therefore instructions START through S7, input 16 digits into controller logic will interpret as stop and rewind commands, the 16 scratchpad bytes addressed by 0'37' through 0'20'. respectively. Data is input from the keyboard using programmed 1/0 via subroutine INKB. Notice that subroutine INKB saves its return 8.3 LOCAL TIMERS (PROGRAMMABLE address in the K scratchpad registers and uses the PK in- TIMERS) struction to return; therefore a stack register is available for the interrupt. Subroutine INKB is almost identical to the Programmable timers are a more useful microprocessor input subroutine described in Section 8.1.1. The principle programming tool than is initially apparent to a programmer. difference is that separate ports are being used for status and data. Observe that throughout this program data is input Programmable timers are shift registers which, after being into scratch pad bytes, one scratch pad 8-byte buffer at a time. loaded with some initial value, count down to 0, then send an interrupt request signal to the CPU. (See Section 2.5.4.) Once 16 digits have been input from the keyboard, they are The 3851 PSU and the 3853 SMI device both have program- moved from scratchpad bytes 0'37' - 0'20' to 0'77' - 0'60'. mable timers. This entire data movement will take 208 microseconds which is not a noticeable delay to an operator entering data at the Here are some applications for which timers are useful: keyboard. 1) In control applications, such as an operations monitor The next 16 bytes of data entered at the keyboard go directly alarm, to insure that some maximum time interval is into scratchpad bytes 0'57' through 0'50' and 0'47' through not exceeded between consecutive readings from 0'40'. sensitive data inputs. For example, suppose a tem- perature must be measured in a chemical reactor at After 32 bytes have been entered into the scratchpad buffer, least once every second to prevent runaway condi- a buffer counter is initialized in scratchpad byte 0 (instructions tions. 253 maximum time intervals ·on a local timer 21 et. seq.); then the cassette is turned on by instructions approximate 1 second. Whenever a temperature is S23 and S24. ONC is used as a symbol representing the one input, the local timer is reset to start counting tlown byte code which will be recognized by the cassette control one second. If one second is counted down, the pro- logic as a turn-on signal. Once the cassette has been turned gram can be written to output a signal that triggers on, program logic branches back to the start of data entry an audible alarm. for the next record. Notice that nowhere in the main program has the interrupt 2) To activate refresh logic for external devices. For ex- service routine been mentioned. It is assumed that once the ample, a video display may need to be refreshed at cassette has been turned on, cassette control logic will issue fixed time intervals; the refresh sequence may be an interrupt request signal each time it is ready to receive initiated by a local timer. another byte of data from the microprocessor. The interrupt service routine therefore may be executed at any time. It is as though there were a floating call to a subroutine that could 3) To maintain the real time of day in any system that randomly be executed at any point in the program where has to generate clock times. Such devices include interrupts were being allowed. badge readers and numerous small office business systems. Observe that the interrupt service routine has to save the contents of the accumulator and the ISAR in scratchpad bytes because the accumulator and ISAR are going to be needed. 8.3.1 Local Timer I/O Ports The illustrated interrupt service routine is probably somewhat Simpler than most real interrupt service routines would be. Local timer logic uses the local interrupt control 1/0 ports to Control logic associated with the cassette drive is assumed enable local timer interrupts, as described in Section 8.2.2 capable of sending status inputs to the microprocessor telling and Table 8-1. the microprocessor when to rewind the cassette. It is also assumed that housekeeping associated with the start and The interrupt control 1/0 port must have the value H'03'loaded end of each record is handled by the cassette control logic. into it under program control in order to enable local timer In all probability much of this housekeeping could be done interrupts at that one device. Therefore either external inter- by the microprocessor, but to include it in the example would rupts or local timer interrupts, but not both, may be enabled detract from the purpose of the example, which is to show at one device. how an interrupt service routine is handled. If interrupts have been disabled at the 3850 CPU, local timer The origins of the main program and interrupt service routine interrupt requests will be ignored until a subsequent inter- have been randomly selected. Note that since the origin of rupt enable. At this time any interrupt request will still be the interrupt service routine has been selected at H'0280', active unless cleared prior to the interrupt enable. 8-7 The timer 1/0 ports have 1/0 port addresses one higher than The value H'03' must be loaded into a local timer control 1/0 the local interrupt control 1/0 port. Therefore 3851 PSU port port if the associated timer port is to operate. When this addresses are: value is loaded into the control 1/0 port any pending timer interrupt is cleared. Any subsequent zero value of the timer will set the timer interrupt. B'xxxxxx10' for the local interrupt control 1/0 port S'xxxxxx11' for the iocai timer ilO port if the vaiue H'03' is in the controi i/O port before the timer constant is output to the timer 1/0 port, then the timer which For the 3853 SMI, port addresses are: is constantly running may interrupt before being set with a timer constant. Once the timer 1/0 port holds a zero value, H'OE' for the local interrupt control 1/0 port an interrupt request signal will be generated once every H'OF' for the local timer I/O port 3.953 ms (for a 500 ns clock pulse). Providing the ICB bit is 1 within the 3850 CPU, every timer interrupt request will 8.3.2 Programming Local Timers be acknowledged and serviced if the timer interrupt is enabled. Programming a local timer requires the value H'03' to be The program that is executed after a timer interrupt is acknowl- loaded into the selected device's local interrupt control 1/0 edged is a service routine which, like the service routine il- port. A number between 0 and 254, identified as a timer lustrated in Section 8.2.7, is never called or referenced by constant, is loaded into the associated local timer 1/0 port. any other program. The service routine must start executing A value of 255 loaded into the local timer 1/0 port stops the at the memory address provided by the 3851 or 3853 device's clock. interrupt address 1/0 ports; however, recall that the 7 bit of the address is automatically set to 0 for a timer interrupt, or The value loaded into a local timer, as a timer constant, is to 1 for an external interrupt. If the external interrupt service converted (by the assembler) to a binary value, as given in routine is origined at H'0680', as illustrated in Section 8.2.7, Appendix C; that is why numbers should be entered as timer then for the same device, the local timer interrupt service constants. routine will be origined at H'0600'. A local timer interrupt will be generated after the time interval given by the product: 8.3.3 A Programming Example - The Tim.e of Day (system clock pulse interval) * (local timer constant) * 31 The program below creates the time of day by storing hours in scratch pad byte 8, minutes in scratch pad byte 7 and sec- For example, a value of T'200' loaded into a local timer 1/0 onds in scratchpad byte 6. Scratchpad byte 5 is used as a port will generate an interrupt after 3.1 ms if the system counter. clock pulse interval is 500 ns. This program uses the maximum timer interval (3.953 ms between interrupts). The local timer must be initialized with Instructions needed to enable a local timer are as follows: the main program as follows: LIS o ZERO HOURS, MINUTES AND LR 8,A SECONDS PORTS, ASSUM- LR 7,A ING THE DEVICE WILL BE LR 6,A SWITCHED ON EXACTLY AT MIDNIGHT LI 253 INITIALIZE THE LOCAL LI T'200' LOAD TIMER CONSTANT LR 5,A COUNTER TO 253 bUTS 7 OUTPUTTO TIMER 1/0 PORT 7 LI T'O' CLEAR LOCAL TIMER PORT LIS 3 LOAD TIMER INITIATION OUTS 7 CONTROL LIS H'03' ENABLE THE LOCAL TIMER OUTS 6 OUTPUT TO CONTROL 1/0 OUTS 6 PORT INTERRUPTS PORT 6 EI ENABLE INTERRUPTS AT THE CPU The local timer interrupt service routine is assumed to be EI ENABLE INTERRUPTS AT origined at H'0200'. It executes as follows: THE 3850 CPU ORG H'Q?OO' !n the above eX3mp!e, the timer ccnst3nt T'200' has been arbitrarily selected. Any value from T'O' to T'256' could be OS BNZ 5 OUT DECREMENT THE LOCAL COUNTER CONTiNUE iF iT is NOT ZERO (ONE SEC). I used. T'256', remember, will stop the clock. LI 253 IF IT IS ZERO, RESET TO 253 LR 5,A The selection of 1/0 ports 7 and 6 is also arbitrary; any pair LR A,6 INCREMENT THE SECONDS of 1/0 ports with addresses given in Section 8.3.1 could be COUNTER used. Note, however, that the control 1/0 port number is INC always one less than the timer port number it controls. CI 60 TEST IF SECONDS EQUAL 60 I BZ T10 IF THEY DO, ADJUST The maximum data transfer rate supported by programmed MINUTES I/O is not of itself a limiting factor. A 256 byte buffer, for LR 6,A IF THEY DO NOT, END example, can be transferred in 4.86 ms. The problem is that OUT EI this maximum data transfer rate requires external logic that POP processes data at a rate of one byte every 19 J.lS. Most ap- *MINUTES ADJUST BEGINS HERE plications will not meet this requirement, usually because TlO US LR 6,A ° ZERO SECONDS data transfer rates are set by logic considerations beyond the microprocessor system; that is, external logic determines LR A,7 LOAD MINUTES data transfer rates, not the microprocessor system. INC INCREMENT MINUTES CI 60 TEST FOR 60 MINUTES Suppose external logic is inputting data to the microprocessor BZ T20 AT 60 MINUTES, ADJUST system at some rate, which we will label R bytes/second. LR 7,A HOURS OTHERWISE RETURN The time that elapses between each byte transferred will be MINUTES (l,OOO,OOO/R) J.lS. The local timer can be used to generate EI an interrupt shortly before each byte of data is due, in which POP case the local timer interrupt service routine will input the *HOURS ADJUST BEGINS HERE data byte. Assuming that data will always be in the 1/0 port T20 LIS LR 7,A ° ZERO MINUTES before the local timer interrupt service routine is executed, the following service routine will input data bytes from an LI 153 CORRECT 0.392 SECOND 1/0 port: ERROR EVERY HOUR LR 5,A ISRI LR O,A SAVE ACCUMULATOR LR INC A8 LOAD HOURS INCREMENT HOURS XDC CONTENTS IN ° SWITCH DCO AND DCl CI 24 TEST FOR 24 HOURS BNZ LIS no ° AT 24 HOURS, RESET TO OTHERWISE RETURN HOURS ° LI OUTS TCNT 7 RESTART TIMER INS T30 LR EI 8,A ST XDC ° INPUT DATA BYTE SAVE IN MEMORY SWITCH DCO AND DCl POP LR A,O RESTORE ACCUMULATOR 8.4 DIRECT MEMORY ACCESS EI FROM ° ENABLE INTERRUPTS POP RETURN Direct memory access (DMA) allows data to be transferred between any F8 microprocessor system memory and an ex- ternal device, bypassing the 3850 CPU. Data is transferred TCNT is a symbol defined by the equate directive: in parallel with any CPU operations. DMA has been described, as a concept, in Sections 2.6.3 and 2.8. TNCT EQU T'VAL' One 3852 DMI device must be present in a microprocessor system that supports DMA. Up to four 3854 DMA devices where VAL is a number between ° and 255. Each count represents 31 clock periods and the total time is equal to may be present in the system; each 3854 DMA device (l,OOO,OOO/R) but less than 3.953 ms. provides one DMA channel. It will take approximately 38 J.lS for interrupt service routine 8.4.1 When to Use DMA ISRI to execute; this means that approximately 9.7 ms will be required to input 256 bytes of data. This 9.7 ms will be DMA is used to transfer data into, or out of, a microprocessor spread over whatever time interval the external device re- system that has heavy 1/0 requirements. For example, using quires to transfer 256 bytes of data. But there are some programmed 1/0, the theoretically maximum data transfer problems associated with the method of inputting data: rate is implemented by the following instruction sequence for data input: 1) Recall that there are certain privileged instructions LOOP INS INPUT A DATA BYTE VIA which inhibit acknowledgement of an interrupt. It is ST ° PORT ° STORE IN RAM MEMORY quite feasible for a 2 to 4 J.lS delay to randor;lly get inserted between each execution of ISRI if, by chance, DS TEST FOR END OF TRANS- a privileged instruction is being executed at the instant MISSION the local timer times out. Over 256 bytes of data trans- BNZ LOOP RETURN FOR NEXT CHAR- fer, this means that it is feasible for a 500 J.lS slew to ACTER develop, which will result in the loss of a byte of data, if the data transfer rate exceeds 2,000 bytes/so Scratchpad register 1 is assumed to hold the initial character count. 2) If the microprocessor is handling interrupts other These four instructions execute in 9.5 instruction cycles, equal than the local timer, clearly other interrupts must be to 19 /.1S, using a 500 ns clock pulse. Assuming that external serviced by routines which are themselves interrupt- logic is synchronized to input one byte of data every 19 /.1S. able, since one interrupt service routine blocking out the maximum data transfer rate is approximately 50,000 ISRI for any significant period of time would almost bytesl second. c~rtainly create irrecoverable timing errors. 8-9 3) Observe that ISRI uses the DCl register and uses one are given in Table 2-2 for the four 3854 DMA devices scratchpad register to store accumulator contents. that may be present in an F8 microprocessor system. This means that the DCl register and the scratch pad Whether a DMA device uses the first, second, third regis!er cannot be used by any other program that or fourth set of addresses is a function of device hard- is being executed during the same time period. ware configuration and of no concern to the program- mer, so long as the correct port addresses are used. If subroutine ISRI is expanded to include a status test plus 2) ADLO and ADHI represent the low order and high logic to compute the timer constant that will compensate order bytes of the beginning address of the memory for timing slews, the new expanded version of ISRI might buffer into which data will be written, or from which easily take 200 J.LS to execute. Under these circumstances data will be read. the microprocessor system would spend a significant amount of its time merely moving data between memory and an 3) Data buffers may be up to 4,096 bytes long. CTLO I/O port. represents the low order eight bits of the buffer length, as illustrated in Figure 8-4. CTRL provides the controls In all but the simplest I/O transfer applications, therefore, which select DMA options and also the high order four DMA becomes the preferable way of moving data between bits of the buffer length, as illustrated in Figure 8-4. memory and external devices. 8.4.2 Programming DMA The following instructions will initiate 256 bytes of data being written into a memory buffer, where the data rate is con- The actual programming steps required in order to initiate a troiled by the externai device. The memory buffer starting DMA operation are simple, as follows: address is H'A280'. The first DMA channel is used. LI ADLO LOAD BUFFER STARTING OUT BUFA ADDRESS INTO ADDRESS 110 PORTS LI ADHI LI H'80' OUTPUT LOW ORDER BYTE OUT BUFB OF ADDRESS LI CTLO LOAD LOW ORDER BYTE OF OUT H'FO' BYTE COUNT LI H'A2' OUTPUT HIGH ORDER BYTE OUT BUFC OF ADDRESS LI CTRL LOAD HIGH ORDER 4 BITS OUT H'Fl ' OF BYTE COUNT LI H'OO' OUTPUT LOW ORDER BYTE OUT BUFD PLUS CONTROL BITS OF COUNT OUT H'F2' Symbols must be equated as follows: LI H'Cl' OUTPUT HIGH ORDER 4 DIGITS OF COUNT (1) 1) The I/O port addresses, BUFA. BUFB, BUFC and BUFD OUT H'F3' AND CONTROL DIGIT IC). 1/0 PORT BUFD 1/0 PORT BUFC \..'-----'./ 7 6 5 4 3 2 o 7 6 5 4 3 2 o Bit No IIIIIIIII IIIIIIIII tl \ I I III '----- 0 Buffer Length External device c6ntrols data transfer rate. A byte of data will be transferred every available I I 11....-____ 0 ~~: t~~O~sfer halts when the byte count register II 1,_______ 1 o decrements to 0 Data transfer continues until bit 7 is reset to O. Data is transf",rre<1 from memory to an external device ~ ---- 0 Data is transferred from an external device to main memory Ha!! D~.~.~. opere!!0!: Start DMA operation I Fig. 8-4. How BUFC and BUFD are used to Control DMA Operations I 8.4.3 Catching DMA on the Fly Instruction steps to initiate DMA are pClckaged as a subrou- tine labeled DMA. The buffer length output is H'FF'. As this There are many applications in which data will be transferred buffer length is counted down, the number of bytes trans- via DMA at unpredictable rates. For example, in communi- ferred via DMA can, at any time, be determined by reading cations applications, data may come over a telephone line at the contents of I/O port F2 into the accumulator and com~ a fixed baud rate, but the length of messages and the period plementing. The control digit C starts data flow via DMA from when no data is being transferred may be completely random. the external device (assumed to be a communications Under such circumstances it is very useful if a program can interface) to the memory buffer, beginning at H'2000'. start and stop DMA operations or interrogate the buffer counter to find out how much data has been transferred via DMA The main program starts by initializing DMA via a call to since the last interrogation. The following program sequence subroutine DMA. At some later point in the program, in- catches DMA on the fly, in a way that would be well suited structions M1 and M2 are executed in order t6 load the code to random data transfer rates in communications applications: digit 0 into I/O port F3 and thus stop DMA transfers. Instruc- tions M3 through M4 determine the number of bytes that *SUBROUTINE TO INITIALIZE DMA WITH H'FF' IN THE BYTE have been transferred via DMA, since DMA was initiated, *COUNTER. THE DATA BUFFER STARTS AT H'2000' and loads this byte count into scratch pad register O. Instruc- DMA LI H'oo' OUTPUT BUFFER STARTING tions will now follow to move the number of bytes received ADDRESS to some other memory location where the data can be pro- OUT H'FO' cessed. Subroutine DMA will then be recalled to re-initialize LI H'20' DMA data transfers. After data has been processed execution OUT H'F1 ' will branch back to instruction M1 and so the program will LI H'FF' OUTPUT BYTE COUNTER continue processing whatever data has been transferred in OUT H'F2' each time interval. LI H'CO' S2 OUT H'F3' POP "MAIN PROGRAM TO HANDLE COMMUNICATIONS DATA *TRANSFERRED VIA DMA PI DMA INITIALIZE DMA M1 LIS 0 STOP DMA DATA TRANSFER M2 OUT H'F3' M3 IN H'F2' LOAD BYTE COUNT INTO COM SCRATCHPAD BYTE 0 M4 LR O,A (instructions to process data follow here) 8-11 I ·1 I PROGRAM OPTIMIZATION Optimizing a program is not a routine mechanical task; rather, In the following sub-sections, program optimization informa- it is a function of application requirements and hardware tion is presented in the following sequence: configuration. Most microprocessor programs are written 1) The concept of counting memory bytes and execution either to maximize execution speed, or to minimize the cycles is described. amount of memory used. 2) Some basic techniques that will always make Fa programs more efficient are listed. Consider a simple example. A microprocessor has 1024 bytes of program memory. An application may only use half of the 3) Some examples of execution speed versus memory available memory, but may be too slow to meet product speci- utilization tradeoffs are given. fications. Converting every subroutine to a macro will speed up program execution time, but may double the size of the 9.1 COUNTING CYCLES AND BYTES program. Since program memory comes in finite increments, The Fa instruction set is summarized in Appendix D, where the economizing on program storage requirements is only mean- number of object program bytes is listed for every instruction. ingful when it reduces the number of devices required by a microprocessor system; therefore, increasing program stor- Consider the data movement program described in Figure age requirements from 500 bytes to 1000 bytes carries no 5-1. This program is reproduced in Figure 9-1, along with penalty. number of execution cycles and memory bytes required by each instruction. In practice, programming for minimum use of program stor- Counting bytes is usually unnecessary, since the assembler age should be the goal of microprocessor programmers. listing prints the memory location where each object pro- Microprocessor instruction sets are very versatile. Many gram byte will be stored. Thus subtracting memory addresses variations of a program can be written to implement any yields the length of any program, program segment or problem; but some programs will be more efficient than subroutine. others. A novice microprocessor programmer may well write programs that occupy 50% more memory than is really neces- 9.2 ELEMENTARY OPTIMIZATION sary. Inefficiencies of this type are not important in mini- TECHNIQUES computer systems, which usually include bulk storage devices There are a number of instruction choices where one selec- such as disk units. The only penalty paid for having unneces- tion is always preferable. These obvious instruction choices sarily long programs is a few extra milliseconds, making are described in the following sub-sections. otherwise unnecessary transfers of program segments be- tween disk and memory. Unnecessarily long programs are 9.2.1 Scratch pad and RAM Memory very uneconomical in microprocessor systems, where the Always fill up the scratchpad before using RAM memory to entire program sits in one or more memory devices. If a store constants or data buffers. It takes one cycle to move a microprocessor system has two more memory devices than byte of data between the accumulator and a scratch pad byte; the most compact program would require, these two memory it takes 2.5 cycles to move a byte of data between the accu- devices can become 20,000 memory devices, if the micro- mulator and external RAM. Both sets of instructions generate processor system is to be reproduced 10,000 times. one byte of object code. In many ways, the logic designer will find it easier to be- 9.2.2 Immediate Instructions come an efficient microprocessor programmer than will a systems analyst. who has gained experience programming Immediate instructions are 2 or 3-byte instructions that spec- minicomputers and larger systems. The systems analyst has ify data in the instruction operand. continuously striven to write programs which are general purpose. For example, a subroutine that performs multibyte Consider the 2-byte immediate instructions; these instruc- addition must be able to add two number buffers of any length, tions specify a 1-byte operand, which is combined with the located anywhere in memory, storing the result in a third contents of the accumulator in some way. An instruction number buffer. Such a multibyte addition subroutine, once such as: written, could be frequently reused in almost any applica- tion, thus reducing future programming expenses. This is 1M LI CNT LOAD COUNTER INTO economical thinking in the world of minicomputers, but it ACCUMULATOR is very uneconomical thinking in the world of microprocessors. A microprocessor application may be able to define two executes in 2.5 cycles and occupies two bytes of memory. If number buffers of specific length, in specific areas of memory, this instruction occurs identically (with the same operand) as the only number buffers which will ever be involved in many times in a program, consider loading CNT into a scratch- mathematical operations. A multibyte addition subroutine, pad register, as follows: working within these restrictions, may have to be rewritten for every new microprocessor application, but the subroutine ONE LI CNT that results may use less than half of the memory storage TWO LR 1,A requirements demanded by the equivalent g~neral purpose routine. When microprocessor systems are likely to be re- produced tens of thousands of times, extra front-end pro- gramming expense becomes trivial compared to the cost of THRE LR A,1 LOAD COUNTER INTO extra memory devices, multiplied ten thousand fold. ACCUMULATOR 9-1 Cycles Bytes a a TITLE "SAMPLE PROGRAM TO MOVE DATA BETWEEN BUFFERS" a a MAXC:Pl.I 50 liMIT OF 50 S!:CONDS CPt.! T!ME SPEC!!=!ED 0 0 SYMBOL A SYMBOL TABLE WILL FOLLOW SOURCE PROGRAM a a XREF SYMBOLS CROSS LISTING WILL FOLLOW SOURCE PROGRAM a a BASE HEX HEXADECIMAL NUMBERS SPECIFIED FOR ASSEMBLY LISTING a a BUFA EQU H'0800' SET THE VALUE OF SYMBOL BUFA a a BUFB EQU H'08AO' SET THE VALUE OF SYMBOL BUFB a a ORG H'Ol00' 6 3 ONE DCI BUFA SET DCa TO BUFA STARTING ADDRESS 2 1 TWO XDC STORE IN DCl 6 3 THREE DCI BUFB SET DCa TO BUFB STARTING ADDRESS 2.5 2 FOUR LI H'80' LOAD BUFFER LENGTH INTO ACCUMULATOR 1 1 FIVE LR 1,A SAVE BUFFER LENGTH IN SCRATCHPAD BYTE 1 2.5 LOOP LM LOAD CONTENTS OF MEMORY BYTE ADDRESSED BY DCa 2 SIX XDC EXCHANGE DCa AND DCl 2.5 SEVEN ST STORE ACCUMULATOR IN MEMORY BYTE ADDRESSED BY DCa 2 1 EIGHT XDC EXCHANGE DCa AND DCl 1.5 1 NINE DS DECREMENT SCRATCH PAD BYTE 1 3.5 2 BNZ LOOP IF SCRATCHPAD BYTE 1 !S NOT ZERO, RnURN TO LOOP a a END ill 17 * BNZ will usually return to LOOP Total Bytes = 17 Total Cycles = 31.5 Total Cycles within iterative loop = 14 Assuming 2 /-IS cycle time, time to move 128 bytes = 2*(14*128+17.5) =3619/-1s Fig. 9-1. Counting Cycles and Bytes Instructions ONE and TWO execute in 3.5 cycles and occupy 9.2.4 Use of OS Instruction to Decrement and Test three bytes of memory. Instruction THRE executes in one Recall that when a OS instruction is used, the decremented cycle, occupies one byte of memory and replaces instruction 1M. scratchpad byte may be tested for '·decrement-from-zero". Clearly instruction 1M is better than ONE, TWO and THRE, if Since the OS instruction adds H'FF' to the designated scratch- 1M occurs just once; however, if instruction 1M occurs iden- pad byte contents, the carry status will always be set unless tically n times, then it accumulates 2.5n cycles and 2n bytes of memory, whereas ONE, TWO and THRE accumulate (3.5+n) ° the scratch pad byte contained before it was decremented. Therefore the instruction sequence: cycles and (3+n) bytes of memory, respectively. Therefore ONE, TWO and THRE will execute faster when: OS n BC BACK 2.5n > 3.5 + n or 1.5n > 3.5 will decrement scratch pad byte n, return to BACK if byte n or n > 2.33 did not contain 0, but continue if byte n did contain 0. ONE, TWO and THRE occupy less memory when: 9.2.5 Use of the BR7 Instruction 2n > (3 + n) The BR7 instruction is very useful whe!""! manipulating data or n> 3 buffers in scratch pad memory, as described in Section 7.1. In conclusion, if a 2-byte immediate instruction occurs iden- 9.3 PROGRAMMING FOR SPEED OR MEMORY tically (same operand) three or more times in a program, it ECONOMY is more efficient to load the immed!ate opera!""!d !!""!!c a scra!ch- In the foHo'..I'!!!1g subsections, progr~mm;ng techniques that pad byte out of which it is referenced (providing a scratch pad tradeoff between execution speed and the amount of memory byte is available). used are described. 9.2.3 Short Instructions 9.3.1 Macros and Subroutines Always go over a source program, making sure that the short To gain execution speed, possibly with a heavy increase in instructions US, INS and OUTS have been used wherever the amount of memory required, convert subroutines into the operand is small enough. macros as described in Section 7.4. I Always carefully examine subroutines, particularly those *ONE OF EIGHT DECODER PROGRAM USING TABLE which are infrequently called or receive parameters from the *LOOKUPS calling program, to see if converting the subroutine into a LKUP DC 0 macro would save memory bytes and, at the same time, DC 2 increase execution speed. DC 4 DC 8 As described in Section 7.3, programs can be made much DC 16 faster and will require less memory if subroutine nesting is DC 32 limited to a first level. If a main program calls a subroutine, DC 64 the subroutine can then call another subroutine. However, DC 128 a subroutine cannot call another subroutine if it was, itself, called by a subroutine. Limiting subroutine nesting to a level of one means that return addresses can be stored in the stack register (PC1) and in the K registers of the scratchpad, INS 0 INPUT OCTAL CODE eliminating the need for memory stacks. DCI LKUP LOAD TABLE BASE ADDRESS 9.3.2 Table Lookups Versus Data Manipulation ADC ADD INPUT CODE TO BASE Program execution speed can frequently be increased by ADDRESS looking up data out of tables in ROM. LM LOAD OUTPUT OUTS OUTPUT RESULT The concept is illustrated below, for the simple case of a 1- of-8 decoder. Efficiencies compare as follows: An octal digit is input into the low order three bits of I/O port Non-Table Lookup Table Lookup O. The CPU must output, via I/O port 1, a data byte as follows: Instructions 10 5 Memory bytes 13 15 Execution cycles min: 15 15 Input From Port 0 Output At Port 1 max: 69.5 15 00000001 00000001 00000010 00000010 00000011 00000100 00000100 00001000 00000110 00100000 00000111 01000000 OOOOOOOO 10000000 *ONE OF EIGHT DECODER PROGRAM, NOT USING TABLE *LOOKUP INS o INPUT OCTAL CODE BNZ 110 INPUT IS NOT ZERO LIS 8 LOOP COUNTER 110 LR O.A TO LOOP COUNTER LIS 1 LOAD OUTPUT FOR 1 LOOP DS o DECREMENT INPUT BZ OUT BRANCH OUT IF END SL 1 SHIFT LEFT ONE BIT IF NOT END BR LOOP OUT OUTS 1 OUTPUT RESULT 9-3 I I I SOME USEFUL PROGRAMS Some generally useful programs are given in this section. If scratch pad byte 0 is not, available, any other byte may be Programs are not shown as subroutines or as macros. The used for data storage. instructions implementing required logic are given, making it easy to incorporate an example into a program as a sub- routine, a macro or directly as a section of main memory. If scratch pad byte 1 is not available, any other scratchpad These programs are intended to show programming techniques, byte, or the immediate instruction: rather than to demonstrate optimum program efficiency. AI H'30' 10.1 GENERATING TEXT may be used. 10.1.1 Simple and Dedicated Text Programs 10.1.3 VariableText It is possible to have a text generation program in ROM that The simplest text generation logic takes characters out of a outputs variable text, temporarily stored in RAM. In other memory buffer and outputs them via an 1/0 port. The 1/0 words, a fixed ROM program outputs messages of variable operation may be under program control, or interrupt 1/0 may length and content. This is useful in word processing or human be used. In each case, text is fetched via an elementary dialog applications. For example, an Fa microprocessor may instruction sequence such as: drive a CRT used to collect data from convention attendees; the text program described below allows the dialog that will DCI TEXT LOAD TEXT BUFFER be displayed to be changed at any time, without changing the STARTING ADDRESS text generation program. LOOP LM LOAD NEXT TEXT BYTE *TEST FOR END-OF-RECORD CHARACTER. INSTRUCTIONS The text table (labeled TEXT below) contains characters in *FOR THIS TEXT ARE NOT SHOWN, SINCE THEY ARE A FUNe- any mixed sequence. *TION OF THE APPLICATION. OUT PRTN OUTPUT CHARACTER VIA PORT N The index table (labeled TIND below) consists of the following BR LOOP RETURN FOR NEXT 3-byte sequence: CHARACTER 10.1.2 Unpacking Decimal Digits This variable text generation program uses two data tables: a text table and an index table. A byte containing two BCD digits is converted into two ASCII digits as follows: LM LOAD BYTE WITH TWO BCD DIGITS Bytes 1 and 2 - Displacement from TEXT to first character LR O,A SAVE BYTE IN SCRATCHPAD to be output. If Byte 1 = H'FF', end of mes- BYTE 0 sage is indicated. Byte 1 displacement SL 4 cannot be H'FF'. SR 4 ISOLATE LOW ORDER DIGIT Byte 3 - Number of characters to be printed. AS 1 ADD HIGH ORDER FOUR ASCII BITS LR 2,A SAVE IN SCRATCHPAD BYTE 2 Messages are identified by number, starting at 1. A mes- LR AO LOAD TWO BCD DIGITS sage's number is its sequential location, as identified by H'FF' SR 4 ISOLATE HIGH ORDER DIGIT codes in TIND. AS 1 ADD HIGH ORDER FOUR BITS *CHARACTER OUTPUT SEQUENCE FOLLOWS HERE Consider the following very simple example. The following four messages are to be generated: This instruction sequence assumes that scratch pad byte 0 is available for temporary storage and that scratch pad byte 1 contains H'30'. Refer to Appendix B. A decimal digit becomes 1) ENTER PRODUCT NUMBER: an ASCII character as follows: 2) NO SUCH PRODUCT RE-ENTER: 3) NUMBER OF UNITS: 4) PRODUCT SHIP DATE: 7 6 5 4 3 2 1 0 Bit No. 0011XXXX The following TEXT table will be needed: -"--"-L rL Decimal digit, 0000 through 1001 RE-ENTERkSPRODUCT kSNUMBER:kSNOkSSUCH kSOFkSUNITS:SHIPkSD This code identifies an ASCII decimal digit ATE:kS 10-1 The following TrIO table will be needed: LR 10,A LR OC,H Byte No. Contents L3 LM LOAD NEXT CHARACTER TO (Hexadecimal) (Hexadecimal) BE OUTPUT PI COUT OUTPUT CHARACTER ~\ 0 Message 1 is 20 1 characters, starting at *ANY OUTPUT CODE MAY REPLACE THE CALL TO SUB- Z 14 ; character 4 "ROUTINE COUT 3 FF End of message 1 DS 2 DECREMENT CHARACTER COUNTER ~l 4 5 NO SUCH BNZ L3 RETURN FOR MORE 6 08 CHARACTERS XDC AT END OF MESSAGE ~l 7 8 PRODUCT BR T10 SEGMENT, RESTORE TIND 9 08 ADDRESS TO DCO OUT END OF PROGRAM. ANY ~l A B RE-ENTER OTHER INSTRUCTIONS MAY C FOLLOW HERE 0 FF End of message 2 ~l E F NUMBER 10 06 TINO ORG X'08OO' ORIGIN ARBITRARILY SELECTED ~l 11 12 OF UNITS DC H'oo' DISPLACEMENT TO HIGH 13 OA BYTE 14 FF End of message 3 DC H'03' DISPLACEMENT TO LOW BYTE ~l 15 16 PRODUCT DC H'16' NUMBER OF CHARACTERS 17 08 IN THIS SEGM.ENT DC H'FF' END OF MESSAGE 1 ~l 18 19 SHIP DATE: 1A OB 1B FF End of message 4 DC H'OB' The following program assumes that the message number DC H'FF' is in the accumulator. The program generates the specified message. TGEN LR O,A SAVE MESSAGE NUMBER 10.2 MULTIBYTE ADDITION AND IN BYTE 0 SUBTRACTION DCI TIND LOAD TEXT INDEX STARTING ADDRESS 10.2.1 16-Bit. Binary Addition and Subtraction L1 DS 0 DECREMENT MESSAGE COUNTER The following program adds a 16-bit value in scratchpad BZ T10 MESSAGE FOUND bytes 1 (high) and 0 (low) to another 16-bit value in scratch- L2 LM SEEK NEXT H'FF' BYTE IN pad bytes 3 (high) and 2 (low), as follows: TIND COM BNZ L2 BYTE LOADED IS NOT H'FF' BR L1 BYTE LOADED IS H'FF' LR A.O LOAD LOW ORDER T10 LM MESSAGE FOUND. LOAD AUGEND BYTE LR O,A NEXT THREE BYTES OF TIND AS 2 ADD LOW ORDER COM AND SAVE IN SCRATCHPAD ADDEND BYTE BZ OUT BYTES 0, 1 AND 2. TEST LR 2,A SAVE ANSWER LM FIRST BYTE FOR H'FF' LR A,1 LOAD HIGH ORDER SIGNIFYING END OF AUGEND BYTE MESSAGE LNK ADD ANY CARRY LR 1,A BNO A1 IF NO OVERFLOW, LM CONTINUE LR 2,A BR ERROR MAKE ERROR EXIT FOR XDC SAVE T!ND ADDRESS!N DC1 CARRY DCI TEXT LOAD TEXT ADDRESS INTO A1 AS 3 ADD HIGH ORDER DCO ADDEND BYTE LR A,O ADD SCRATCH PAD BYTES LR 3,A SAVE ANSWER ADC 1 AND 0 TO DCO BNO NEXT IF NO OVERFLOW, LR H,DC CONTINUE LR A,10 BR ERROR MAKE ERROR EXIT FOR AS 1 CARRY I To perform 16-bit binary subtraction, the two's complement To perform multibyte decimal subtraction, the routine should of the 16-bit value in scratch pad bytes 1 and 0 is added to be changed as follows: the 16-bit value in H. Instructions required are as follows: LR DC,H MOVE SUBTRAHEND TO DC BUFA EQU H'0838' THE CONTENTS OF BUFA LR AO LOAD LOW ORDER BYTE BUFB EQU H'0920' AND BUFB ARE ADDED. THE OF MINUEND BUFC EQU H'077C' RESllLT IS STORED IN BUFC. COM COMPLEMENT IT CNT H'OA' 10 B','TE BUFFERS ARE ADC ADD TO SUBTRAHEND ASSUMED. LIS ADD 1 TO SUBTRAHEND ADC LR H,DC RESTORE PARTIAL SUM TO H LR A1 LOAD HIGH ORDER BYTE ONE LIS CNT USE SCRATCHPAD OF MINUEND TWO LR O,A REGISTER 0 AS A COUNTER COM COMPLEMENT THREE DCI BUFC SAVE THE ANSWER BUFFER AS 10 ADD HU TO ACCUMULATOR FOUR LR Q,DC STARTING ADDRESS IN Q LR 10,A STORE ANSWER BACK FIVE DCI BUFA SAVE THE SOURCE BUFFER SIX XDC ADDRESSES IN DCO AND DC1 10.2.2 Multibyte Binary or Decimal Addition and Subtraction SEVEN DCI BUFB Subroutine MADD, in any of the forms and variations de- EIGHT LI H'66' LOAD IMMEDIATE H'66' scribed in Section 7, performs multibyte binary addition. LR 2,A AND SAVE FOR LATER USE LIS 1 INITIALLY SET CARRY TO 1 LOOP LR 8,A SCRATCHPAD BYTE 8 USED To perform multibyte binary subtraction make changes as TO SAVE CARRY follows. (Refer to the program version in Section 7.2.2): LM LOAD SUBTRAHEND INTO ACCUMULATOR Replace COM ELEV XDC ADDRESS MINUEND EIGHT COM INITIALLY CLEAR THE AMD ADD MINUEND CARRY BIT LR J,W SAVE STATUS LR J,W AS 8 ADD PRIOR BYTE'S CARRY LOOP LM ASD 2 DECIMAL CORRECT BY LR W,J ADDING H'66' NINE LNK NNTN BNC TWTY+1 TEST IF DECIMAL CORRECT CREATES A CARRY with: TWTY LR J,W IF IT DOES, SAVE CARRY THRT XDC READDRESS AUGEND EIGHT LI H'FF' INITIALLY SET THE CARRY BUFFER INC BIT BY LOADING H'FF' INTO A, THEN INCREMENTING FRTN LR H,DC SAVE AUGEND ADDRESS LR J,W SAVE STATUS TO FORCE IN H TWOS COMPLEMENT FFTN LR DC,Q LOAD ANSWER BUFFER LOOP LM LOAD NEXT BYTE ADDRESS COM COMPLEMENT THE SXTN ST STORE THE ANSWER ACCUMULATOR SVTN LR Q,DC SAVE ANSWER BUFFER LR W,J RESTORE STATUS ADDRESS IN Q NINE LNK ADD CARRY, IF PRESENT EGTN LR DC,H MOVE AUGEND ADDRESS BACK TO H LIS 2 LOAD CARRY FROM AMD NS 9 OR ASD AND WITH SAVED To perform multibyte decimal addition, referring again to the STATUS IN J multibyte addition program as described in Section 7.2.2, SR SAVE IN SCRATCHPAD replace BYTE 1 TWT1 DS 0 DECREMENT COUNTER BNZ LOOP RETURN FOR MORE TWEL AM ADD CORRESPONDING ADDEND BYTE 10.3 MULTIPLICATION There are a number of possible multiplication routines. with: Consider first the binary multiplication of two 8-bit, positive TWEL AI H'66' PRIME AUGEND FOR numbers (in scratch pad bytes 0 and 1) to give a 16-bit prod- DECIMAL ADDITION duct in scratchpad bytes 7 (high) and 6 (low). The following AMD ADD ADDEND DECIMAL program performs the required multiplication: 10-3 *BINARY MULTIPLY SUBROUTINE TABX+80 81 8283848586878889 8A 8B 8C 80 8E 8F *SCRATCH REG 1 CONTAINS MULTIPLIER holds: 00 08 16 24 32 40 48 56 64 72 Not Used *SCRATCH REG 2 CONTAINS MULTIPLICAND "SCRATCH REGS 6 AND 7 CONTAIN PRODUCT (SR7=MSB) TABX+90 91 9293949596979899 9A 9B 9C 90 9E 9F BMPY LIS 8 INITIALIZE COUNTER TO 8 holds: 00 09 1827 3645 5463 72 81 Not Used LR 5,A US 0 ZERO PRODUCT LR 6,A All numbers above are hexadecimal. Suppose TABX is equated LR 7,A to H'2000'; then byte H'2oo8' contains H'OO'; byte H'2024' BMP1 LR A6 SHIFT PARTIAL contains H'08'; byte H'2094' contains H'36'; etc. AS 6 PRODUCT LEFT 1 LR 6,A LR A7 The table lookup proceeds as follows: LNK AS 7 7,A LR A,O ISOLATE MULTIPLIER LR LR A1 SHIFT MULTIPLIER SL 4 LOW ORDER DIGIT AS 1 LEFT 1, BY ADD SR 4 LR 2,A STORE IN BYTE 2 LR 1,A IF CARRY IF SET LR A1 LOAD MULTIPLICAND BNC BMP2 ADD MULTIPLICAND TO PRODUCT SL 4 ISOLATE LOW ORDER DIGIT LR ADD AS 2 ADD MULTIPLIER LOW A2 ORDER DIGIT X16 AS 6 MULTIPLICAND DCI TABX LOAD TABLE BASE LR 6,A TO ADDRESS LR A7 PRODUCT LR H,DC SAVE BASE FOR FURTHER LNK LR 7,A USE ADC ADD ACCUMULATOR INDEX BMP2 OS 5 DECREMENT COUNT LM LOAD PRODUCT FROM BNZ BMP1 NOT FINI, REPEAT TABLE LR 6,A STORE IN LOW ORDER BYTE OF ANSWER The above program occupies 26 bytes and executes in a maxi- LR A,O LOAD MULTIPLIER mum of 373 MS. Contrast this with the program in Section SR 4 ISOLATE HIGH ORDER DIGIT 9.3.3 which occupies just 12 bytes, but executes in between LR 3,A SAVE IN BYTE 3 20 M sand 1800.5 MS. LR A,1 LOAD MULTIPLICAND SR 4 ISOLATE HIGH ORDER DIGIT Very fast decimal multiplication can be achieved using table SL 4 lookups. Consider a 2-digit decimal number in scratch pad AS 3 ADD MULTIPLIER HIGH byte 0, multiplied by a 2-digit decimal number in scratch pad ORDER DIGIT byte 1, to give a 4-digit answer in scratchpad bytes 7 (high) LR DC,H LOAD TABLE BASE and 6 (low). The routine uses 100 bytes of ROM, to hold the ADDRESS following table: ADC ADD ACCUMULATOR INDEX . LM LOAD PRODUCT FROM TABX+OO 01 0203040506070809 OA OB OC 00 OE OF TABLE holds: 00 00 00 00 00 00 00 00 00 00 Not Used LR 7,A STORE IN HIGH ORDER BYTE OF ANSWER TABX + 10 11 12 13 14 15 1 6 17 18 19 1A 1 B 1C 10 1E 1 F LR A,1 LOAD LOW ORDER DIGIT OF holds: 00 01 02 03 04 05 06 07 08 09 Not Used SL 4 MULTIPLICAND AS 3 ADD HIGH ORDER DIGIT OF TABX+20 21 2223242526272829 2A 2B 2C 20 2E 2F MULTIPLIER holds: 00 02 04 06 08 10 1 2 14 16 18 Not Used LR DC,H OBTAIN PRODUCT ADC TABX+30 31 3233343536373839 3A 3B 3C 3D 3E 3F. LM holds: 00 03 06 09 12 15 18 21 24 27 Not Used LR 3,A SAVE iN BYTE 3 TABX+40 41 4243444546474849 4A 4B 4C 40 4E 4F SL AI 4 H'66' ADD LOW ORDER DIGIT TO I holds: 00 04 08 12 16 20 24 28 32 36 Not Used TABX+fiO 51 52 53 54 55 56 57 58 59 5,6, 58 5C 5D 5E 5F holds: 00 05 10 15 20 25 30 35 40 45 Not Used ASD ...... 'n LR 6 1'''1 ..J,vv 6,A HIGH ORDER DIGIT OF BYTE 6 I LR A3 ISOLATE HIGH ORDER DIGIT TABX+60 61 6263 64656667 68 69 6A 6B 6C 6D 6E 6F SR 4 OF PRODUCT IN LOW holds: 00 06 12 18 24 30 36 42 48 54 Not Used ORDER POSITION LR W,J TABX+70 71 72 73 74757677 78 79 7A 7B 7C 7D 7E 7F LNK OF ACCUMULATOR. ADD holds: 00 07 14 21 28 35 42 49 56 63 Not Used LINK IVA I AI H'66' LR W,J ASD 7 ADD HIGH ORDER BYTE OF LNK OF ACCUMULATOR. ANSWER ADD LINK LR 7,A RESTORE HIGH ORDER BYTE AI H'66' OF ANSWER ASD 7 ADD HIGH ORDER BYTE LR A,1 LOAD HIGH ORDER DIGIT OF ANSWER SR 4 OF MULTIPLICAND LR 7,A RESTORE HIGH ORDER SL 4 BYTE OF ANSWER AS 2 Al - 'c-OW ORDER DIGIT OF MULTIPLIER More compact versions of this program could be written, but LR DC,H OBTAIN PRODUCT they would take longer to execute. ADC LM SAVE IN BYTE 3 10.4 DIVISION LR 3,A Division of positive numbers can be performed by a program SL 4 ADD LOW ORDER DIGIT TO using successive subtraction as follows: AI H'66' ASD 6 HIGH ORDER DIGIT OF 1) Zero the answer BYTE 6 2) Subtract the divisor from the dividend LR J,W 3) Test for a negative result LR 6,A 4) For a positive result, increment the answer and return LR A,3 ISOLATE HIGH ORDER DIGIT to 2 SR 4 OF PRODUCT IN LOW ORDER 5) For a negative result, the division is finished. Add the POSITION divisor to the dividend to obtain remainder. 10-5 I I I APPENDIX A - BINARY NUMBER SYSTEM The binary number system is a system of counting which The octal number system includes the following digits: utilizes the digits 1 and a to represent numeric quantities. The binary digits, referred to as BITs, are arranged in a se- 0, 1, 2, 3, 4, 5, 6, 7. quence of decreasing significance based upon powers of two. Each bit is numbered. By convention, the most significant Binary numbers are transposed into octal numbers by arrang- bit is on the left, and the least significant bit is on the right. ing the bits into groups of three as illustrated below: For example, consider the binary number: 101001 Binary number, Binary number a 1 1 a a 1 101 001 -.- -.- Bit number 5 4 3 2 1 a Power of base two 2 5 24 2 3 22 2' 2 0 5 Octal number Significance 32 16 8 4 2 1 The Indirect Scratchpad Address Register (ISAR) uses two As in any number system, the quantity represented by a bi- octal digits to address 64 scratch pad registers. nary number is calculated by multiplying each digit by its significance, then summing products. Octal numbers are written within quotation marks preceded by an 0 as follows: The binary number example is evaluated as follows: 0'27', 0'3', 0'3270' Quantity = 0*25+1 *24+1 *23+0*22+0*2'+1 *20 = a+ 16 + 8 + + a a + 1 Table A-1 illustrates the relationship between binary, decimal. = 25 hexadecimal and octal numbers. Binary numbers may be used to represent any real number positive or negative. BINARY DECIMAL HEXADECIMAL OCTAL 0000 a a a Non-integer numbers are represented in the same binary aaa 1 1 1 1 format shown above except that the significance of the bits aa a1 2 2 2 changes. To indicate the correct interpretation of a binary aa 1 1 3 3 3 number, a "binary point" (which is analogous to a decimal a aa 1 4 4 4 point in the decimal number system) is inserted. Consider a a 1 1 5 5 5 the binary number below: a a 1 1 6 6 6 a 1 1 1 7 7 7 Binary number a 1 1 a a 1 1 1 000 8 8 10 Bit number 6 5 4 3 2 1 a 1 aa 1 9 9 11 Power of base two 2 5 24 2 3 22 2' 2 0 2-' 1 1 a a 10 A 12 Significance 32 16 8 4 2 1 V2 1 011 11 B 13 1 1 aa 12 C 14 The number is evaluated as follows: 1 1 1a 13 D 15 1 1 1 a 14 E 16 Quantity = 0*25+1 *24+1 *23+0*22+0*2'+1 *20+1 *2-' 1 1 1 1 15 F 17 = a + 16 + 8 + + + a a a + .5 = 25.5 Table A-1. Binary, Decimal, Hexadecimal and Octal Numbers The bits of a binary number may be grouped in fours and trans- posed into the hexadecimal number system which includes THE BYTE the following digits: The Fairchild F8 microprocessor is an 8-bit device, which means that data is handled in eight binary digit (or one byte) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. units. An 8-bit byte may represent 256 (2 8 ) possible permu- tations of eight digits. The following example illustrates the procedure: When referencing the 8-bit byte, this manual has established the following conventions. 10011100 Binary number The bits are numbered from right to left with numbers a 10011100 -.--- through 7. The most significant bit is on the left; the least significant bit is on the right. 9 A Hexadecimal number Bit Number 7 6 543 2 1 a In this manual, hexadecimal numbers are written within quo- I I IIIIIII tation marks and preceded by an H. Consider the example: H'27', H'AE1 0', H'F' t Most significant bit t Least significant bit A-l An 8-bit byte may represent an instruction object code, an bit of the next (higher order) byte as follows: ASCII code or a data word. H'13E2' 000 1 001 1 11100010 An 8-bit data word may be interpreted as a signed binary +H'4747' o1 000 1 1 1 o 1 000 1 1 1 number with a value of from 127 to -128 as illustrated in H'5B29' o 1 0 1 1 0 1 ~/1 0010100 1 Tabl~ A-2 o"fo--T'~r-o~lT It will become clear after reading the sections which follow on binary arithmetic, that the signed binary number system Binary Number Subtraction is a natural fallout of two's complement subtraction. Subtracting a binary number is the same as adding the two'~ complement of the number. BINARY DECIMAL HEXADECIMAL 10000000 -128 The two's complement of a number is generated by comple- 80 10000001 -127 81 menting the number (replacing 0 with 1 and 1 with 0) and 10000010 -126 82 adding one to the complement. Here is an example: - - - - H'3C' 0 0 1 1 1 1 0 0 one's complement 1 1 0 0 0 0 1 1 - - 11111110 -2 FE 1 11111111 two's complement 0 0 0 1 0 0 -1 FF OOOOOOOO 0 0 00000001 1 1 Observe that negative numbers in Table A-2 are the two's 00000010 2 complement of their positive equivalents. In this fashion, an 2 - - 8-bit number can contain sign and value information for - - numbers between 128 and -127. - - 01111101 +125 When adding signed binary numbers, care must be taken to 70 01111110 +126 7E indicate when the result exceeds the boundaries of the two's 01111111 +127 7F complement notation. " Table A-2. Signed Binary Numeric Interpretations To exemplify the need for such indicators, consider some simple examples using the set Of 3-bit signed binarynumbers from 3 to -4. Binary Number Addition Addition of binary numbers is accomplished by following Signed Binary Numbers Decimal three rules. 011 3 010 2 1) 1 bit 001 1 + 1 bit 000 o 0 bit + a carry bit to the next significant bit 111 -1 110 -2 2) bit 101 -3 + 0 bit ,- bit 100 -4 Any number greater than 3 or less than -4 is outside the 3) 0 bit boundaries of the set of 3-bit signed binary numbers. + 0 bit 0 bit -fhe addition of two numbers within this set may result in a number which is not defined as part of the set. Consider the addition of two positive 8-bit binary numbers: Consider the addition of two numbers with like signs: Bit Number H'93' "'H'AS' 7 6 5 432 1 0 100 1 001 1 1 0 0 0 0 0 1) Bit No. 2 210 010 2) Bit No. 3 210 011 I H'3B' [!] • 0 0 1 1 1 0 1 1 + 1 3 001 01T + 1 4 /100 001 I I Carry Bit no carry carry 3) Bit No. 210 4) Bit No. 210 The carry bit is set to indicate that the results of the addition -3 101 -3 101 cannot be represented in the existing 8-bits. However, if the -1 111 -2 110 carry bit represents the next higher significant bit. the results are valid. =4 1~0 -5 1-..011 two carries carry In a multiple byte addition, the carry bit from the most signif- In example 1, no carry out of the two high order bits occured. , icant bit position of a byte is added to the least significant The result is defined and valid. A,-2 In example 2, carry out from the bit which precedes the sign Division of binary numbers may be accomplished by repetitive bit (carry out from bit 2) occurred. The result is undefined subtraction of one operand from another, or by an operation and therefore invalid. similar to long hand division: In example 3, a carry from bit 2 and 3 occurred. The result 7 111 is defined and valid. 3~ 11) 10101 11 In example 4, a carry from the sign bit occurred. The result 100 is undefined and invalid. 11 11 The explanation of the four examples illustrates the rules 11 which govern the error indication mechanism in the Fairchild --0 F8 microprocessor. If the addition of two 8-bit numbers causes a result which is outside the boundary defined for 8-bit signed binary numbers, (illustrated in Table A-1), an overflow status COMPUTER LOGIC bit is set. Assembly language instructions exist which perform logical The overflow status bit is defined as the EXCLUSIVE-OR of the operations on operands. Three such logical operations are carry out of bit 6 and the carry out of bit 7. (EXCLUSIVE-OR is described below (logical-OR, AND, and EXCLUSIVE-OR). defined later in this appendix.) The logical-OR operation is illustrated for the two operands I and J with the statement: Consider binary number subtraction, (the addition of a binary number to a two's complement number). If I or J equals 1, then the result is 1. Otherwise, the result 1) Bit No. 7 6 543 2 1 a is zero. H'52' a1a1aa1a two's complement 1010111 a The symbol used to indicate the logical-OR operation is the sign (V). Consider the logical-OR of two binary numbers: H'34' aa1 1a1aa -H'52' 1 a 1 a 1 1 1 a A V B = C (read A "or" B equals C) -H'18' @] 1 1 1 a a a 1 a A 11010 two's complement H'18' aaa1 1aaa B 01100 C 11110 2) Bit No. 7 6 543 2 1 a H'2A' aa1a1a1a The logical AND operation is illustrated for the two operands two's complement 1101011 a I and J with the following statement: H'B6' a11a1 a If both I and J are 1, then the result is 1. Otherwise, the -H'2A' 1 a 1 a 1 1 a result is zero. H'8A' IT] aaa1 1aa The symbol used for the logical AND operation is (A). In example 1, the subtrahend is larger than the minuend, indicating a negative answer. In unsigned binary number Consider the logical AND of two binary numbers: arithmetic, a negative result is indicated by no carry out of the most significant bit and is in two's complement form. A A B = C (read A "and" B equals C) There is no overflow because there is no carry out of either bit 6 or bit 7. A 11010 B 01100 In example 2, the subtrahend is smaller than the minuend C 01000 indicating a positive answer. In unsigned binary arithmetic, a positive result is indicated by a carry from the most signif- The logical EXCLUSIVE-OR operation is illustrated for the op- icant bit pOSition and is in straight binary form. There is no erands I and J with the following statement: overflow because there is a carry out of both bit 6 and bit 7. If both I and J equal 1 or both I and J equal 0, the result is zero, otherwise the result is 1. Multiplication of binary numbers may be performed in two ways: repetitive addition or in the fashion illustrated below, The symbol used to indicate the logical EXCLUSIVE-OR which is similar to the long hand method for multiplying operation is a circled sign ( CD ). decimal numbers: Decimal Binary Consider the logical EXCLUSIVE-OR of two binary numbers: 91 a1 a11 x 5 1 a 1 A CD B = C (read A "EXCLUSIVE-OR" with B equals C) 455 1 a 1 1 a 1 1 0000000 A 11010 a11a11 B 01100 11000111 C 10110 A-3 I APPENDIX B - ASCII CODES GRAPHIC OR ASCII GRAPHIC OR ASCII GRAPHIC OR ASCII CONTROL (HEXADECIMAL) CONTROL (HEXADECIMAL) CONTROL (HEXADECIMAL) NULL 00 ACK 7C 1 31 SaM 01 Alt. Mode 7D 2 32 EOA 02 Rubout 7F 3 33 EOM 03 21 4 34 EaT 04 22 5 35 WRU 05 # 23 6 36 RU 06 $ 24 7 37 BELL 07 % 25 8 38 FE 08 & 26 9 39 H. Tab 09 27 A 41 Line Feed OA 28 B 42 v. Tab OB 29 C 43 Form OC 2A D 44 Return OD + 2B E 45 SO OE 2C F 46 SI OF 2D G 47 DCa 10 2E H 48 X-On 11 / 2F I 49 Tape Aux. On 12 3A J 4A X-Off 13 3B K 4B Tape Aux. Off 14 < 3C L 4C Error 15 3D M 4D Sync 16 > 3F N 4E LEM 17 3F a 4F SO 18 [ 5B p 50 S1 19 5C Q 51 S2 1A "-] 5D R 52 S3 1B t 5E S 53 S4 1C 5F T 54 S5 1D @ 40 U 55 S6 1E blank 20 V 56 S7 1F 0 30 W 57 X 58 Y 59 Z 5A 8-1 I APPENDIX C - CONVERSION TABLESjTlMER COUNTS POWE RS 0 F TWO 1 0 1.0 2 1 0.5 4 2 0.25 8 3 0.125 16 4 0.062 5 32 5 0.031 25 64 6 0.015 625 128 7 0.007 812 5 256 8 0.003 906 25 512 9 0.001 953 125 1 024 10 0.000 976 562 5 2 048 11 0.000 488 281 25 4 096 12 0.000 244 140 625 8 192 13 0.000 122 070 312 5 16 384 14 0.000 061 035 156 25 32 768 15 0.000 030 517 578 125 65 536 16 0.000 015 258 789 062 5 131 072 17 0.000 007 629 394 531 25 262 144 18 0.000 003 814 697 265 625 524 288 19 0.000 001 907 348 632 812 1 048 576 20 0.000 000 953 674 316 406 25 2 097 152 21 0.000 000 476 837 158 203 125 4 194 304 22 0.000 000 238 418 579 101 562 5 8 388 608 23 0.000 000 119 209 289 550 781 25 16 777 216 24 0.000 000 059 604 644 775 390 625 33 554 432 25 0.000 000 029 802 322 387 695 312 5 67 108 864 26 0.000 000 014 901 161 193 847 656 25 134 217 728 27 0.000 000 007 450 580 596 923 828 125 268 435 456 28 0.000 000 003 725 290 298 461 914 062 536 870 912 29 0.000 000001 862 645 149 230 957 031 25 1 073 741 824 30 0.000 000 000 931 322 574 615 478 515 625 2 147 483 648 31 0.000 000 000 465 661 287 307 739 257 812 5 4 294 967 296 32 0.000 000 000 232 830 643 653 869 628 906 25 8 589 934 592 33 0.000 000 000 116 415 321 826 934 814 453 125 17 179 869 184 34 0.000 000 000 058 207 660 913 467 407 226 562 5 34 359 738 368 35 0.000 000 000 029 103 830 456 733 703 613 281 25 68 719 476 736 36 0.000 000 000 014 551 915 228 366 851 806 640 625 137 438 953 472 37 0.000 000 000 007 275 957 614 183 425 903 320 312 5 274 877 906 944 38 0.000 000 000 003 637 978 807 091 712 951 660 156 25 549 755 813 888 39 0.000 000 000 001 818 989 403 545 856 475 830 078 125 1 099 511 627 776 40 0.000 000 000 000 909 494 701 772 928 237 915 039 062 5 2 199 023 255 552 41 0.000 000 000 000 454 747 350 886 464 118 957 519 531 25 4 398 046 511 104 42 0.000 000 000 000 227 373 675 443 232 059 478 759 765 625 8 796 093 022 208 43 0.000 000 000 000 113 686 837 721 616 029 739 379 882 812 5 17 592 186 044 416 44 0.000 000 000 000 056 843 418 860 8D8 014 869 689 941 406 25 35 184 372 088 832 45 0.000 000 000 000 028 421 709 430 404 007 434 844 970 703 125 70 368 744 177 664 46 0.000 000 000 000 014 210 854 715 202 003 717 422 485 351 562 5 140 737 488 355 328 47 0.000 000 000 000 007 105 427 357 601 001 858 711 242 675 781 25 281 474 976 710 656 48 0.000 000 000 000 003 552 713 678 800 500 929 355 621 337 890 625 562 949 953 421 31 2 49 0.000 000 000 000 001 776 356 839 400 250 464 677 810 668 945 312 5 1 125 899 906 842 624 50 0.000 000 000 000 000 888 178 419 700 125 232 338 905 334 472 656 25 2 251 799 813 685 248 51 0.000 000 000 000 000 444 089 209 850 062 616 169 452 667 236 328 125 4 503 599 627 370 496 52 0.000 000 000 000 000 222 044 604 925 031 308 084 726 333 618 164 062 5 9 007 199 254 740 992 53 0.000 000 000 000 000 111 022 302 462 515 654 042 363 166 809 082 031 25 18 014 398 509 481 984 54 0.000 000 000 000 000 055 511 151 231 257 827 021 181 583 404 541 015 625 36 028 797 018 963 968 55 0.000 000 000 000 000 027 755 575 615 628 913 510 590 791 702 270 507 812 5 72 057 594 037 927 936 56 0.000 000 000 000 000 013 877 787 807 814 456 755 295 395 851 135 253 906 25 144 115 188 075 855 872 57 0.000 000 000 000 000 006 938 893 903 907 228 377 647 697 925 567 676 950 125 288 230 376 151 711 744 58 0.000 000 000 000 000 003 469 446 951 953 614 188 823 848 962 783 813 476 562 5 576 460 752 303 423 488 59 0.000 000 000 000 000 001 734 723 475 976 807 094 411 924 481 391 906 738 281 25 1 152 921 504 606 846 976 60 0.000 000 000 000 000 000 867 361 737 988 403 547 205 962 240 695 953 369 140 625 2 305 843 009 213 693 952 61 0.000 000 000 000 000 000 433 680 868 994 201 773 602 981 120 347 976 684 570 312 5 4611686018427387904 62 0.000000000000 000 000 216 840 434 49710088680149056017398834228515625 9 223 372 036 854 775 808 63 0.000 000 000 000 000 000 108 420 217 248 550 443 400 745 280 086 994 171 142 578 125 C-l TABLE OF POWERS OF SIXTEEN IO n 16 n 1 o 0.10000 00000 00000 00000 x 10 16 0.62500 00000 00000 00000 x 10- 1 256 2 0.39062 50000 00000 00000 X 10- 2 4 096 3 0.24414 06250 00000 00000 x 10- 3 65 536 4 0.15258 78906 25000 00000 x 10-4 1 048 576 5 0.95367 43164 06250 00000 x 10-6 7 16 777 216 6 0.59604 64477 53906 25000 x 10- 268 435 456 7 0.37252 90298 46191 40625 x 10-8 4 294 967 296 8 0.23283 06436 53869 62891 x 10- 9 68 719 476 736 9 0.14551 91522 83668 51807 x 10- 10 099 511 627 776 10 0.90949 47017 72928 23792 x 10- 12 17 592 186 044 416 11 0.56843 41886 08080 14870 x 10-\3 281 474 976 710 656 12 0.35527 13678 80050 09294 x 10- 14 4 503 599 627 370 496 13 0.22204 46049 25031 30808 x 10- 15 72 057 594 037 927 936 14 0.13877 78780 78144 56755 x 10- 16 152 921 504 606 846 976 15 0.86736 17379 88403 54721 x 10- 18 TABLE OF POWERS OF 10 16 o 1.0000 0000 0000 0000 A 1 0.1999 9999 9999 999A 64 2 0.28F5 C28F 5C28 F5C3 x 16- 1 3E8 3 0.4189 374B C6A7 EF9E x 16- 2 2710 4 0.680B 8BAC 710C B296 X 16- 3 86AO 5 0.A7C5 AC47 lB47 8423 X 16- 4 F 4240 6 0.10C6 F7 AO B5EO 8037 X 16-4 98 9680 7 0.1.AD7 F29A BCAF 4858 X 16- 5 5F5 El00 8 0.2AF3 10C4 6118 73BF X 16-6 3B9A CAOO 9 0.44B8 2FAO 9B5A 52CC X 16- 7 2 540B E400 10 0.60F3 7F67 SEF6 EAOF X 16 8 17 4876 E800 11 O.AFEB FFOB CB24 AAFF X 16- 9 E8 04A5 1000 12 0.1197 9981 20EA 1119 X 16- 9 918 4E72 AOOO 13 0.lC25 C268 4976 81C2 X 16- 10 5AF3 107A 4000 14 0.2009 3700 4257 3604 X 16- 11 3 807E A4C6 8000 15 0.480E BE7B 9058 5660 X 16- 12 23 8652 6FCl 0000 16 0.734A CA5F 6226 FOAE X 16- 13 163 4578 508A 0000 17 0.B877 AA32 36A4 B449 X 16- 14 OEO B6B3 A764 0000 18 0.1272 5001 0243 ABAl X 16 -14 8AC7 2304 89E8 0000 19 0.1083 C94F B602 AC35 X 16- 15 l.-L HEXADECIMAL-DECIMAL INTEGER CONVERSION The table below provides for direct conversions between hexadecimal integers in the range O-FFF and decimal integers in the range 0-4095. For conversion of larger integers, the table values may be added to the following figures: Hexadecimal Decimal. Hexadecimal Decimal 01000 4096 20000 131072 02 000 8192 30 000 196608 03 000 12288 40 000 262 144 04000 16384 50 000 327680 05000 20 480 60 000 393216 06 000 24576 70 000 458752 07 000 28672 80 000 524288 08 000 32768 90 000 589824 09 000 36864 AO 000 655360 OAOOO 40 960 BO 000 720 896 OB 000 45 056 CO 000 786432 OCOOO 49152 DO 000 851 968 00 000 53248 EO 000 917504 OE 000 57344 Fa 000 983040 OF 000 61440 100 000 1 048576 10 000 65536 200 000 2 097 152 11000 69632 300 000 3 145728 12000 73728 400 000 4194304 13 000 77 824 500 000 5242880 14000 81 920 600000 6291 456 15000 86 016 700000 7340032 16000 90112 800 000 8388608 17000 94208 900000 9437 184 18000 98304 AOO 000 10 485760 19000 102400 BOO 000 11 534336 lAOOO 106496 COO 000 12582912 lB 000 110592 000 000 13631 488 lC 000 114688 EOO 000 14680064 10 000 118784 Faa 000 15728640 1E 000 122880 1 000 000 16777216 1 F 000 126976 2000 000 33554432 a 1 2 3 4 5 6 7 8 9 A B C 0 E F 000 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 010 0016 0017 0018 0019 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 0030 0031 020 0032 0033 0034 0035 0036 0037 0038 0039 0040 0041 0042 0043 0044 0045 0046 0047 030 0048 0049 0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 0060 0061 0062 0063 040 0064 0065 0066 0067 0068 0069 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 050 0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 0090 0091 0092 0093 0094 0095 060 0096 0097 0098 0099 0100 0101 0102 0103 0104 0105 0106 0107 0108 0109 0110 0111 070 0112 0113 0114 0115 0116 0117 0118 0119 0120 0121 0122 0123 0124 0125 0126 0127 080 0128 0129 0130 0131 0132 0133 0134 0135 0136 0137 0138 0139 0140 0141 0142 0143 090 0144 0145 0146 0147 0148 0149 0150 0151 0152 0153 0154 0155 0156 0157 0158 0159 OAO 0160 0161 0162 0163 0164 0165 0166 0167 0168 0169 0170 0171 0172 0173 0174 0175 OBO 0176 0177 0178 0179 0180 0181 0182 0183 0184 0185 0186 0187 0188 0189 0190 0191 OCO 0192 0193 0194 0195 0196 0197 0198 0199 0200 0201 0202 0203 0204 0205 0206 0207 000 0208 0209 0210 0211 0212 0213 0214 0215 0216 0217 0218 0219 0220 0221 0222 0223 OEO 0224 0225 0226 0227 0228 0229 0230 0231 0232 0233 0234 0235 0236 0237 0238 0239 OFO 0240 0241 0242 0243 0244 0245 0246 0247 0248 0249 0250 0251 0252 0253 0254 0255 C·3 HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cont'd) o 123 4 5 6 7 8 9 A 8 C o E F 100 0256 0257 0258 0259 0260 0261 0262 0263 0264 0265 0266 0267 0268 0269 0270 0271 110 0272 0273 0274 0275 0276 0277 0278 0279 0280 0281 0282 0283 0284 0285 0286 0287 120 I 130 I 0288 0304 0289 0290 0291 0305 0306 0307 0292 0308 0293 0309 0794 07% ~.- 0310 0311 -- 0?Q6 0312 - n29 7 0313 0298 0314 0299 0315 0300 n')n1 0316 0317 V~Vf 0302 I"\~.n~ VJUJ I 0318 0319 140 0320 0321 0322 0323 0324 0325 0326 0327 0328 0329 0330 0331 0331 0333 0334 0335 150 0336 0337 0338 0339 0340 0341 0342 0343 0344 0345 0346 0347 0348 0349 0350 0351 160 0352 0353 0354 0355 0356 0357 0358 0359 0360 0361 0362 0363 0364 0365 0366 0367 170 0368 0369 0370 0371 0372 0373 0374 0375 0376 0377 0378 0379 0380 0381 0382 0383 180 0384 0385 0386 0387 0388 0389 0390 0391 0392 0393 0394 0395 0396 0397 0398 0399 190 0400 0401 0402 0403 0404 0405 0406 0407 0408 0409 0410 0411 0412 0413 0414 0415 lAO 0416 0417 0418 0419 0420 0421 0422 0423 0424 0425 0426 0427 0428 0429 0430 0431 180 0432 0433 0434 0435 0436 0437 0438 0439 0440 0441 0442 0443 0444 0445 0446 0447 lCO 0448 0449 0450 0451 0452 0453 0454 0455 0456 0457 0458 0459 0460 0461 0462 0463 100 0464 0465 0466 0467 0468 0469 0470 0471 0472 0473 0474 0475 0476 0477 0478 0479 1EO 0480 0481 0482 0483 0484 0485 0486 0487 0488 0489 0490 0491 0492 0493 0494 0495 lFO 0496 0497 0498 0499 0500 0501 0502 0503 0504 0505 0506 0507 0508 0509 0510 0511 200 0512 0513 0514 0515 0516 0517 0518 0519 0520 0521 0522 0523 0524 0525 0526 0527 210 0528 0529 0530 0531 0532 0533 0534 0535 0536 0537 0538 0539 0540 0541 0542 0543 220 0544 0545 0546 0547 0548 0549 0550 0551 0552 0553 0554 0555 0556 0557 0558 0559 230 0560 0561 0562 0563 0564 0565 0566 0567 0568 0569 0570 0571 0572 0573 0574 0575 240 0576 0577 0578 0579 0580 0581 0582 0583 0584 0585 0586 0587 0588 0589 0590 0591 250 0592 0593 0594 0595 0596 0597 0598 0599 0600 0601 0602 0603 0604 0605 0606 0607 260 0608 0609 0610 0611 0612 0613 0614 0615 0616 0617 0618 0619 0620 0621 0622 0623 270 0624 0625 0626 0627 0628 0629 0630 0631 0632 0633 0634 0635 0636 0637 0638 0639 280 0640 0641 0642 0643 0644 0645 0646 0647 0648 0649 0650 0651 0652 0653 0654 0655 290 0656 0657 0658 0659 0660 0661 0662 0663 0664 0665 0666 0667 0668 0669 0670 0671 2AO 0672 0673 0674 0675 0676 0677 0678 0679 0680 0681 0682 0683 0684 0685 0686 0687 280 0688 0689 0690 0691 0692 0693 0694 0695 0696 0697 0698 0699 0700 0701 0702 0703 1 2CO 0704 0705 0706 0707 0708 0709 0710 0711 0712 0713 0714 0715 0716 0717 0718 0719 200 0720 0721 0722 0723 0724 0725 0726 0727 0728 0729 0730 0731 0732 0733 0734 0735 1 2EO 0736 0737 0738 0739 0740 0741 0742 0743 0744 0745 0746 0747 0748 0749 0750 0751 2FO 0752 0753 0754 0755 0756 0757 0758 0759 0760 0761 0762 0763 0764 0765 0766 0767 300 0768 0769 0770 0771 0772 0773 0774 0775 0776 0777 0778 0779 0780 0781 0782 0783 310 0784 0785 0786 0787 0788 0789 0790 0791 0792 0793 0794 0 7 95 0796 0797 0798 0799 320 0800 0301 0802 0803 0804 0805 0806 0807 0808 0809 0810 0811 0812 0813 0814 0815 330 0816 0817 0818 0819 0820 0821 0822 0823 0824 0825 0826 0827 0828 0829 0830 0831 340 0832 0833 0834 0835 0836 0837 0838 0839 0840 0841 0842 0843 0844 0845 0846 0847 /350 / 0848 0849 0850 0851 0852 0853 0854 0855 0856 0857 0858 0859 0860 0861 0862 0863/ 360 0864 0865 0866 0867 0868 0869 0870 0871 0872 0873 0874 0875 0876 0877 0878 0879 1370 1 0880 0881 0882 0883 0884 0885 0886 0887 0888 0889 0890 0891 0892 0893 0894 0895 1 1380 1 0896 0897 0898 0899 0900 0901 0902 0903 0904 0905 0906 0907 0908 0909 0910 0911 1 I;: 1~~; 380 0944 0913 0929 0945 0914 0930 0946 09i5 0931 0947 0916 0917 0932 0933 0948 0949 0918 0919 0934 0935 0950 0951 0920 0936 0952 0921 0937 0953 0922 0938 0954 0923 0939 0955 0924 0925 0940 0941 nncc V;;;J;"JU nnl:"l' U::J;.JI 0926 0927 0942 0943 U::KIO 0959 1 3CO 0960 0961 0962 0963 0964 0965 0966 0967 0968 0969 0970 0971 0972 0973 0974 0975 300 0976 0977 0978 0979 0980 0981 0982 0983 0984 0985 0986 0987 0988 0989 0990 0991 3EO 0992 0993 0994 0995 0996 0997 0998 0999 1000 1001 1002 1003 1004 1005 1006 1007 3FO 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 r_d HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cont'd) 0 1 2 3 4 5 6 7 8 9 A 8 C D E F 400 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 410 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 420 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 430 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 440 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 450 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 460 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 470 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 480 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 490 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 4AO 1184 1 H~5 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 480 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 4CO 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 4DO 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 4EO 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 4FO 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 500 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 510 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 520 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 530 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 540 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 550 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 560 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 570 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 580 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 590 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 5AO 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 580 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 5CO 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 5DO 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 5EO 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 5FO 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 600 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 610 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 620 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 630 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 640 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 650 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 660 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 670 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 680 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 690 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 6AO 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 680 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 6CO 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 6DO 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 6EO 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 6FO 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 C-5 HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cont'd) o 2 3 4 5 6 7 8 9 A 8 C D E F 700 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 18071 710 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 I 720 I 1824 1825 1826 1827 1828 1829 1830 lR~l ,- 1R3?- 1B33 1834 1835 1836 1837 1838 -_ ........ - iR1y, 730 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 740 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 750 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 760 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 770 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 780 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 790 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 7AO 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 780 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 7CO 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 7DO 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 7EO 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 7FO 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 800 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 810 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 820 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 830 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 840 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 850 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 860 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 87(1 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 880 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 890 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 8AO 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 8BO 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 8CO 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 8DO 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 8EO 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 8FO 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 900 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 910 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 920 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 930 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 940 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 950 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 960 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 970 1 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2471) 2427 2428 2429 2430 2431 980 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 990 1 2448 2449 2450 245j 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 9AO 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 980 1 2480 74Rl 2482 2483 2484 2485 7486 2487 2488 2489 2490 " ... n1 L'"+::>I 2492 2493 2494 249b 9CO 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 9DO 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 9EO 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 9FO 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 r:-o HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cont'd) 0 1 2 3 4 5 6 7 8 9 A B C D E F AOO 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 Al0 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 A20 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 A30 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 A40 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 A50 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 A60 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 A70 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 A80 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 A90 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 AAO 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 ABO 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 ACO 2752 2753 2754 2755 2756 2757 2758 2759 2760 4761 2762 2763 2764 2765 2766 2767 ADO 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 AEO 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 AFO 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 BOO 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 Bl0 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 B20 2848 2849 2850 3851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 B30 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 B40 2880 2881 2882 2883 2884 2885 2866 2887 2888 2889 2890 2891 2892 2893 2894 2895 B50 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 B60 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 B70 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 B80 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 B90 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 BAO 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 B80 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 BCO 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 BDO 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 BEO 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 t3FO 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 COO 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 Cl0 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 C20 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 C30 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 C40 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 C50 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 C60 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 C70 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 C80 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 C90 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 CAO 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 CBO 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 CCO 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 CDO 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 CEO 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 CFO 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 C-7 HEXADECIMAL-DECIMAL INTEGER CONVERSION (Cont'd) 0 1 2 3 4 5 6 7 8 9 A B C D E F DOO 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 Dl0 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 D20 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3::175 , , D30 13376 ""1"\""''''I .l.ll 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 D40 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 D50 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 D60 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 D7e 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 D80 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 D90 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 DAO 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 DBO 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 DCO 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 CCO 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 OEO 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 DFO 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 EOO 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 El0 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 E20 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 E30 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 E40 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 E50 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 E60 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 E70 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 E80 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 E90 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 EAO 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 EBO 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 1 ECO 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 EDO 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 EEO 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 EFO 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 FOO 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 FlO 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 F20 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 F30 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 F40 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 I 1= ,50 I 3920 392,1 3922 3923 ".l924 3920 ~ 3920 ~ 3927 3928 3929 3930 3931 3932 3933 3934 3935 F60 I 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 1 3964 3965 3966 1 I, F70 13952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3967 1 F80 13968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 F90 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 ~aaa 1 FAO 14000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 ~~;~ 1 FBO 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 FCO 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 FDO 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 FEO 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 FFO 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 r-R TIMER COUNTS CONTENTS COUNTS CONTENTS COUNTS CONTENTS COUNTS CONTENTS COUNTS OF TO OF TO OF TO OF TO COUNTER INTERRUPT COUNTER INTERRUPT COUNTER INTERRUPT COUNTER INTERRUPT FE 254 40 189 02 124 9F 59 FD 253 9A 188 A5 123 3D 58 F8 252 34 187 48 122 7C 57 F7 251 69 186 96 121 F8 56 EE 250 03 185 20 120 Fl 55 DC 249 A7 184 58 119 E2 54 88 248 4F 183 87 118 C5 53 71 247 9E 182 6E 117 8A 52 E3 246 3C 181 DO 116 15 51 C7 245 78 180 8A 115 2A 50 8E 244 FO 179 75 114 55 49 10 243 EO 178 E8 113 AA 48 38 242 Cl 177 06 112 54 47 76 241 82 176 AD 111 A8 46 ED 240 04 175 5A 110 50 45 OA 239 09 174 85 109 AO 44 84 238 12 173 6A 108 41 43 68 237 24 172 05 107 83 42 01 236 48 171 A8 106 06 41 A3 235 90 170 56 105 00 40 47 234 21 169 AC 104 lA 39 8F 233 42 168 58 103 35 38 IF 232 85 167 81 102 68 37 3F 231 OA 166 62 101 07 36 7E 230 14 165 C4 100 AF 35 FC 229 28 164 88 99 5E 34 F9 228 51 163 11 98 80 33 F3 227 A2 162 22 97 78 32 E6 226 45 161 44 96 F6 31 CD 225 88 160 89 95 EC 30 98 224 17 159 13 94 08 29 36 223 2E 158 26 93 80 28 60 222 50 157 4C 92 60 27 08 221 88 156 98 91 CO 26 86 220 77 155 30 90 80 25 6C 219 EF 154 61 89 00 24 09 218 DE 153 C2 88 01 23 82 217 8C 152 84 87 03 22 64 216 79 151 03 86 07 21 C8 215 F2 150 10 85 OF 20 91 214 E4 149 20 84 lE 19 23 213 C9 148 40 83 3D 18 46 212 93 147 81 82 7A 17 80 211 27 146 02 81 F4 16 18 210 4E 145 05 80 E8 15 37 209 9C 144 08 79 DO 14 6F 208 38 143 16 78 Al 13 OF 207 70 142 2C 77 43 12 8E 206 El 141 59 76 87 11 70 205 C3 140 83 75 OE 10 FA 204 86 139 66 74 lC 9 F5 203 OC 138 CC 73 39 8 EA 202 18 137 99 72 72 7 04 201 31 136 32 71 E5 6 A9 200 63 135 65 70 C8 5 52 199 C6 134 CA 69 97 4 A4 198 8C 133 95 68 2F 3 49 197 19 132 28 67 5F 2 92 196 33 313 57 66 8F 1 25 195 67 130 AE 65 7F 0 4A 194 CE 129 5C 64 FE 254 94 193 90 128 89 63 29 192 3A 127 73 62 53 191 74 126 E7 61 A6 190 E9 125 CF 60 C-9 APPENDIX D - INSTRUCTION SUMMARY ACCUMULATOR GROUP INSTRUCTIONS BYTES OF OP OPER- OBJECT STATUS BITS OBJECT INTERRUPT 1) DMA 2 SLOTS ) CODE AND(S) CODE FUNCTION OVF ZERO CARRY SIGN CYCLES CODE PRIVILEGE SR 12 SHIFT RIGHT ONE 0 1/0 0 SR 4 14 SHIFT RIGHT ONE 0 1/0 0 1 SL 1 13 SHIFT LEFT ONE 0 1/0 0 1/0 SL 4 15 SHIFT LEFT FOUR 0 1/0 0 1/0 COM 18 ACC (ACC) G) 0 1/0 0 1/0 H'FF' LNK 19 ACC -(ACC) + CB 1/0 1/0 1/0 1/0 INC 1F ACC -(ACC) + 1 1/0 1/0 1/0 1/0 LIS 7i ACC-H'i' CLR 70 ACC-H'OO' 1 1 1 LI 20 ACC--H'ii' 2.5 2 2 NI 21 ACC --(ACC)AH'ii' 0 1/0 0 1/0 2.5 2 2 01 22 ACC -(ACC) V H'ii' 0 1/0 0 1/0 2.5 2 2 XI 23 ACC -(ACC) G) H'ii' 0 1/0 0 1/0 2.5 2 2 AI 24 ACC-(ACC) + H'ii' 1/0 .1/0 110 1/0 2.5 2 2 (Binary Add) CI 25 H'ii' + (ACC)+1 1/0 1/0 1/0 1/0 2.5 2 2 1) An interrupt request cannot be acknowledged until an instruction without interrupt privilege has completed execution. 2) This number of bytes can be transferred via DMA dUring the instruction's execution. SCRATCHPAD REGISTER INSTRUCTIONS BYTES OF OP OPER- OBJECT STATUS BITS OBJECT INTERRUPT 1) DMA 2 CODE AND(S) CODE FUNCTION OVF ZERO CARRY SIGN CYCLES CODE PRIVILEGE SLOTS ) LR y,x GENERAL LOAD REGISTER FORMAT ALLOWABLE OPER- ANDS LISTED BELOW A,r* 4r ACC--(r) A,KU 00 ACC--tr12) A,KL 01 ACC--ir13) A,QU 02 ACC--tr14) A.QL 03 ACC-ir15) rA 5r r--{ACC) KU,A 04 r12.-...(ACC) KLA 05 r13.-...(ACC) QUA 06 r14--(ACC) QLA 07 r15.-...(ACC) AS Cr ACC-(ACC)+(rXBinary) 1/0 1/0 1/0 1/0 1 ASD Dr ACC-(ACC)+(r) 1/01/0 1/0 1/0 2 2 (Decimal) NS Fr ACC-(ACC)A(r) 0 1/0 0 1/0 1 XS Er ACC-(ACC) G) (r) 0 1/0 0 1/0 1 OS 3r r _(r)+H 'FF'(Decrement) 1/01/0 1/0 1/0 1.5 * Operand r formats are: Direct Addressing Indirect Addressing o through 11 (Decimal Form) S or 12 H'O' through H'B' (hexadecimal form) I or 13 o or 14 0-1 DATA COUNTER INSTRUCTIONS BYTES OF OP OPER- OBJECT STATUS BITS OBJECT INTERRUPT 1) DMA 2 CODE ANDIS) CODE FUNCTION OVF ZERO CARRY SIGN CYCLES CODE PRIVILEGE SLOTS ) LR ..... "r- \.t,L/\.... OE r14---(DCU), r15--(DCL) 4 3 LR H,DC 11 r1 O--(DCU) ; r11 --- (DCL) 4 3 LR DC,Q OF DCU--(r14); DCL ---(r15) 4 3 LR DC,H 10 DCU--(r10); DCL ---(r11) 4 3 ADC 8E DC ---(DC) + (ACC) 2.5 1 2 DCI iiii 2A DC---H'iiii' 6 3 5 XDC 2C - DC ---> DC1 2 2 [Memory Interface Circuit Only] INDIRECT SCRATCHPAD ADDRESS REGISTER INSTRUCTIONS BYTES OF OP OPER- OBJECT STATUS BITS OBJECT INTERRUPT 1 \ DMA 2 SLOTS ) CODe ANDISj CODE FUNCTiON OVF ZERO CARRY SiGN CYCLES CODE PRIVILEGE· , LR A,IS OA ACC-(lSAR) LR ISA OB ISAR-(ACC) LlSU a 01100a* ISARu-a LlSL a 01101 a* ISARL_a .. a is 3 bits MEMORY REFERENCE INSTRUCTIONS BYTES OF OP OPER- OBJECT STATUS BITS OBJECT INTERRUPT 1) DMA 2 SLOTS ) CODE ANDIS) CODE FUNCTION OVF ZERO CARRY SIGN CYCLES CODE PRIVILEGE LM 16 ACC ---((DC)) 2.5 2 ST 17 (DC) ---(ACC) 2.5 1 AM 88 ACC~(AC;C)T((DC)) 1/0 1/0 1/0 I/O 2.5 2 (Binary) AMD 89 ACC -..(ACC)+((DC)) I/O I/O 1/0 I/O 2.5 2 (Decimal) NM 8A ACC ___ (ACC) 1\ ((DC)) 0 I/O 0 1/0 2.5 2 OM 8B ACC -..(ACC) V ((DC)) 0 1/0 0 liO 2.5 2 XM 8C ACC ---(ACC) E>((DC)) 0 I/O 0 I/O 2.5 2 CM 80 ((DC)) + (ACe) + 1) 1/0 I/O I/O I/O 2.5 2 STATUS REGISTER INSTRUCTIONS BYTES OF OP OPER- OBJECT STATUS BITS OBJECT INTERRUPT 1) DMA 2 CODE ANDIS) CODE FUNCTION OVF ZERO CARRY SIGN CYCLES CODE PRIVILEGE SLOTS ) LR W,J 10 W __ (r9) 2 Yes' 2 W4 W3 W2 W1 Wo liNT i OVF i ZERO i CARRY ISIGN I (Privileged Instruction)' LR J,W 1E r9 ___ (W) , As a result of a privileged instruction execution, a request for Interrupt service is not acknowledged by the CPU until a subsequent non-privileged instruction is executed. MISCELLANEOUS INSTRUCTIONS r- i BYTES OF OP OPER- OBJECT STATUS BITS OBJECT INTERRUPT 1) DMA 2 CODE AND(S) CODE FUNCTION OVF ZERO CARRY SIGN CYCLES CODE PRIVILEGE SLOTS ) NOP 2B NO OPERATION 0-2 PROGRAM COUNTER INSTRUCTIONS BYTES OF OP OPER- OBJECT STATUS BITS OBJECT INTERRUPT 1) DMA CODE AND(S) CODE FUNCTION OVF ZERO CARRY SIGN CYCLES CODE 2 PRIVILEGE SLOTS ) LR K,P 08 r12-(PC1U); r13--(PC1 L) 4 3 LR P,K 09 PC1U-(r12); PC1L--(r13) 4 3 LR PO,Q OD PCOU-(r14); PCOL--(r15) 4 3 PK OC PCOU-(r12) ; PCOL--(r13) 4 Yes* 3 and PC1-(PCO) Privileged Instruction* PI aaaa** 28 PC,-(PCO); PCO_H'aaaa' 6.5 3 Yes* 5 Privileged Instruction* POP lC PCO--(PC1) 2 Yes* 2 Privileged Instruction* BRANCH INSTRUCTIONS BYTES OF OP OPER- OBJECT STATUS BITS OBJECT INTERRUPT 1) DMA 2 CODE ANDIS) CODE FUNCTION OVF ZERO CARRY SIGN CYCLES CODE PRIVILEGE SLOTS ) BR aa 90 PCO-((PCO)+l) + H'aa' 3.5 2 3 aa JMP aaaa 2 29 PCO-H'aaaa' 5.5 3 Yes 1 4 aa aa Privileged Instruction* BT t,aa 4 8t 4 PCO-((PCO)+ H'aa' 3.53 2 3 aa if any test is true or PCO-(PCO)+ 2 if no test is true 3.0 STATUS BIT TESTS 22 2' 20 I I ZERO CARRY SIGN i I BP aa 81 PCO-((PCO)+l)+ H'aa' 3.5 2 3 if SIGN=l aa PCO-(PCO)+ 2 if SIGN=O 3.0 BC aa 82 PCO-((PCO)+l)+ H'aa' if CARRY=l 3.5 2 3 aa PCO-(PCO)+ 2 if CARRY=O 3.0 BZ aa 84 PCO-((PCO)+1) H'aa' if ZERO=1 3.5 2 3 aa PCO-(PCO)+ 2 if ZERO=O 3.0 BM aa 91 PCO-((PCO)+1)+ H'aa' if SIGN=O 3.5 2 3 aa PCO-(PCO)+ 2 if SIGN=1 3.0 BNC aa 92 PCO-((PCO)+1)+ H'aa' if CARRY=O 3.5 2 3 aa PCO-(PCO)+ 2 if CARRY=1 3.0 BNZ aa 94 PCO-((PCO)+1)+ H'aa' If ZERO-=O 3.5 aa PCO-(PCO)+ 2 if ZERO=l 3.0 BF t 5,aa 9t5 PCO-((PCO)+1)+ H'aa' 3.5 2 2 3 aa if selected status bits are all "0" PCO--(PCO)+2 if any status bit is 1 3.0 TEST CONDITIONS 23 22 2' 2° IOVF I I ZERO CARRY SIGN I I BNO aa 98 PCO--((PCO)+1)+ H'aa' if OVF=O 3.52 2 3 aa PCO--(PCO)+ 2 if OVF=l 3.0 BRZ aa 8F PCO.-((PCO)+1)+ H'aa' if ISARi7 2.52 2 2 aa PCO.-(pCO)+ 2 if ISAR=7 2.0 1. As a result of a privileged instruction execution, a request for interrupt service is not acknowledged by the CPU until a subsequent non-privileged instruction is executed. 2. The contents of the accumulator are destroyed. 3. 3,5 cycles if branch is taken. 3.0 cycles if branch is not taken. 4. t is only 3 bits 5. t is four bits 6. 2.5 cycles if branch is taken. 2.0 cycles if branch is not taken. D-3 INTERRUPT CONTROL INSTRUCTIONS BYTES OF OP OPER- OBJECT STATUS BITS OBJECT INTERRUPT,) DMA 2 CODE ANDIS) CODE FUNCTION OVF ZERO CARRY SIGN CYCLES CODE PRIVILEGE SLOTS ) Di iA DiSABLE iNTERRUPT 2 EI lB ENABLE INTERRUPT YES* 2 Pnvlleged InstructIon'" INPUT/OUTPUT INSTRUCTIONS BYTES OF OP OPER- OBJECT STATUS BITS OBJECT INTERRUPT,) DMA 2 CODE ANDIS) CODE FUNCTION OVF ZERO CARRY SIGN CYCLES CODE PRIVILEGE SLOTS ) INS a Aa ACC -(INPUT PORT a) 0 1/0 0 1/0 4** 3 Input Ports 00 to OF only I~I II~ aa 26 ACC --(INPUT PORT aa) 0 1/0 0 I IV 4 2 3 aa Input Ports 04 through FF only OUTS a Ba OUTPUT PORT a-lACe) 4** YES"" 3 Output Ports 00 to OF only OUT aa 27 OUTPUT PORT aa -(ACe) 4 2 YES* 3 aa Output Ports 04 through FF only * As a result of a privileged instruction execution, a request for interrupt service is not acknowledged by the CPU until a subsequent non-privileged instruction is executed. ** 2 cycles when I/O port address is "0" or "1" I I