home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / dec20 / assembler-guide.txt next >
Text File  |  2020-01-01  |  473KB  |  11,878 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.                      DECSYSTEM-20 Assembly Language Guide
  27.  
  28.  
  29.                                   Edited by:
  30.  
  31.                                 Frank da Cruz
  32.                                  Chris Ryland
  33.  
  34.              Columbia University Center for Computing Activities
  35.                            New York, New York 10027
  36.  
  37.  
  38.                                  3 July 1980
  39.  
  40. Assembly Language Guide                                                 Page 1
  41.  
  42.                                    Preface
  43.  
  44. This document is intended to be a comprehensive introduction to assembly
  45. language programming on the DECSYSTEM-20.  It consists of excerpts from
  46. various DEC manuals and other documents, with the addition of programming
  47. examples and some original material.  Appropriate credit is given in each
  48. chapter or section in which the material is not original.
  49.  
  50. Chapter 8 attempts to present a programming standard for Macro programs; in a
  51. sense it is the most important chapter because unless a program is clear and
  52. understandable, it will not be adaptable to new circumstances, and its
  53. usefulness and lifetime will be limited.
  54.  
  55.        This is a draft.  Various sections still need to be filled in or
  56.     refined, and more material added.  This will be done from time to
  57.     time.  Comments are welcome.
  58. Introduction                                                           Page 2
  59.  
  60.                                1. Introduction
  61.  
  62.  
  63. Assembly language is a tool for writing computer programs consisting, at the
  64. source (program text) level, of actual machine instructions.  It is sometimes
  65. desirable or necessary to use assembly language for two reasons:
  66.  
  67.    1. Only in assembly language can you write a program that can take
  68.       advantage of all the features of a given machine.  Higher-level
  69.       languages purposely conceal the machine from programmers so that
  70.       programs may be transported from one machine to another.
  71.  
  72.    2. You have maximum control over every aspect of the operation of your
  73.       program, especially storage allocation and efficiency.
  74.  
  75. In order to use an assembler, you must first be familiar with the machine's
  76. instruction set.  This is described in Chapter 2.  You will notice that this
  77. chapter actually describes three different machines: the KA10, the KI10, and
  78. the KL10.  You should be aware that DEC-20's are KL10's (2020's are KS10's,
  79. but these are identical to KL10's for all practical purposes).
  80.  
  81. There are several assemblers suitable for use on the DEC-20.  These include
  82. Macro-20 (the standard DEC assembler), Midas (an alternative from MIT), and
  83. Fail (a fast 1-pass block structured assembler from Stanford).  Only Macro-20
  84. is supported by DEC, but the other two have certain distinct advantages.
  85. Macro-20 is described in Chapter 3.
  86.  
  87. Another thing that assembly-language programmers need to know about is monitor
  88. calls.  On a timesharing system, such as the DECSYSTEM-20, there are many
  89. things that you cannot do even in assembly language, such as issue
  90. input/output instructions; only the monitor can do such things.  You can ask
  91. the monitor to perform services for you by issuing a monitor call (a DEC-20
  92. monitor call is called a 'JSYS' (Jump to SYStem)), which amounts to calling a
  93. subroutine in the monitor.  Information about DEC-20 monitor calls is given in
  94. Chapters 4 and 5
  95.  
  96. There are various aids available to assembly language programmers; these
  97. include libraries of helpful macros and routines (Chapters 6, 7), and
  98. interactive, symbolic debugging facilities (Chapter 10).  In addition, there
  99. are chapters on how to write, run, and debug programs on the DECSYSTEM-20 (9),
  100. and some sample programs (11).  And, as pointed out in the Preface, a very
  101. important Chapter on programming style and standards (8).
  102.  
  103. The major intent of this guide is to provide a consolidated resource for those
  104. who wish to write assembly language programs, not assembly language
  105. subroutines to be called from higher-level languages; such subroutines can
  106. only be written with detailed knowledge of the calling conventions and
  107. internal data representations of the given language.
  108.  
  109. The reader should have some knowledge of programming and some familiarity with
  110. DECSYSTEM-20 commands and procedures.
  111. Introduction                                                           Page 3
  112.  
  113. 1.1. Basic Concepts
  114.  
  115. Before we can proceed with descriptions of the instruction set, assembler, and
  116. monitor calls, some terminology and a few basic concepts of machine
  117. organization must be introduced.
  118.  
  119.  
  120.  
  121. 1.1.1. Terminology
  122.  
  123. Timesharing     One way of running a computer.  Timesharing allows many users
  124.                 to use the computer at once, seated at terminals, and to
  125.                 converse via the terminal with various programs on the
  126.                 computer.
  127.  
  128. DECSYSTEM-20    A timesharing computer system, the subject of this manual.
  129.  
  130. DEC             Digital Equipment Corporation.  The manufacturer of the
  131.                 DECSYSTEM-20, and of its predecessors, the PDP-10 and PDP-6.
  132.  
  133. Operating System A program, or set of programs, that controls the operation of
  134.                 the computer.  On a timesharing computer, the operating system
  135.                 functions include scheduling among users, allocating resources
  136.                 to users, controlling devices, and performing various other
  137.                 services for users that could not be done by the users
  138.                 themselves.
  139.  
  140. Tops-20         Timesharing OPerating System-20.  This is the name of the
  141.                 DECSYSTEM-20's operating system.
  142.  
  143. Monitor         One component of Tops-20.  It is a program that is always
  144.                 running, and that performs most operating system functions.
  145.  
  146. Exec            Another component of Tops-20.  It is the program by which
  147.                 users communicate their desires to the monitor, and through
  148.                 which the monitor communicates to the user.
  149.  
  150.  
  151.  
  152. 1.1.2. Machine Organization
  153.  
  154. The computer consists of various entities.  You must be aware of what some of
  155. them are in order to program in assembly language:
  156.  
  157. Memory          This is a device that allows the computer to store and
  158.                 retrieve a limited amount of data very quickly.  It is not
  159.                 permanent storage.  It is often referred to as "core" memory
  160.                 (it is sometimes made from magnetic cores), to differentiate
  161.                 it from registers, disks, and other kinds of memory.  Whether
  162.                 it's made from cores or not, it is solid-state memory, i.e. it
  163.                 has no moving parts.
  164.  
  165. Register        (Also called an Accumulator) This is a special kind of solid-
  166.                 state memory that is much faster than ordinary memory, and
  167.                 that allows operations such as arithmetic to be performed on
  168.                 data that is stored there.  The DECSYSTEM-20 has 16 registers.
  169.  
  170. Disk            A kind of mechanical memory that is much slower than registers
  171. Introduction                                                           Page 4
  172.  
  173.                 or core memory, but which allows long-term storage of data in
  174.                 files whose names are kept in directories.  Disks can hold
  175.                 much more data than core memory.
  176.  
  177. CPU             Central Processing Unit.  This is the part of the computer
  178.                 that does most of the work, and where the major "intelligence"
  179.                 is to be found.  It consists of the registers and the logic to
  180.                 move data to and from the registers, as well as logic to
  181.                 operate on the data in the registers (e.g. to do arithmetic).
  182.  
  183. Instruction     An instruction is a code to activate some function of the CPU.
  184.                 Typically, it specifies what operation to perform, what data
  185.                 to operate on, and where to put the result.  Typical
  186.                 operations include arithmetic (add, subtract, etc.), transfer
  187.                 of control, comparison of numbers, etc.  Assembly language
  188.                 programs consist of a sequence of instructions.  When the
  189.                 program is being executed, the instructions are kept in
  190.                 memory.
  191.  
  192. Address         An address is a number that expresses the location of a
  193.                 quantity (instruction or data) in memory.  Used as a verb,
  194.                 "address" means to "refer to".
  195.  
  196. Bit             (BInary Digit) The smallest unit of storage in memory.  A bit
  197.                 is a quantity whose value can be 0 or 1.
  198.  
  199. Word            The major unit of storage in memory.  In the DECSYSTEM-20,
  200.                 each word consists of 36 bits, and has its own address.  You
  201.                 can address 262144 words of memory on the DECSYSTEM-20.
  202.  
  203. Byte            An intermediate unit of storage; any sequence of bits within a
  204.                 word.  A byte is often the unit of storage for a character.
  205.  
  206. Input/Output    This is the act of transferring data between memory and some
  207.                 device, typically a disk or a terminal.
  208.  
  209.  
  210.  
  211. 1.1.3. Instructions and Addressing Modes
  212.  
  213. [ this is mostly taken care of in Ch. 2 ]
  214.  
  215.  
  216.  
  217. 1.1.4. Internal Representation of Numbers
  218.  
  219.  
  220.  
  221. 1.1.4.1. Binary Numbers
  222.  
  223. [ to be filled in ]
  224. Introduction                                                           Page 5
  225.  
  226. 1.1.4.2. Two's Complement Representation
  227.  
  228. [ to be filled in ]
  229.  
  230.  
  231.  
  232. 1.1.4.3. Integers
  233.  
  234. [ to be filed in ]
  235.  
  236.  
  237.  
  238. 1.1.4.4. Floating Point Numbers
  239.  
  240. [ to be filled in ]
  241.  
  242.  
  243.  
  244. 1.1.5. Arithmetic
  245.  
  246. [ to be filled in ]
  247.  
  248.  
  249.  
  250. 1.1.5.1. Integer Arithmetic
  251.  
  252. [ to be filled in ]
  253.  
  254.  
  255.  
  256. 1.1.5.2. Floating Point Arithmetic
  257.  
  258. [ to be filled in ]
  259.  
  260.  
  261.  
  262. 1.1.6. Logical Operations
  263.  
  264. [ to be filled in ]
  265.  
  266.  
  267.  
  268. 1.1.7. Character String Manipulation
  269.  
  270. [ to be filled in ]
  271.  
  272.  
  273.  
  274. 1.1.8. Elementary Data Structures
  275.  
  276.  
  277.  
  278. 1.1.8.1. Tables (Arrays) and Indexing
  279.  
  280. [ to be filled in ]
  281. Introduction                                                           Page 6
  282.  
  283. 1.1.8.2. Stacks
  284.  
  285. [ to be filled in ]
  286. Instruction Set                                                        Page 7
  287.  
  288.                   2. The PDP-10/DECSYSTEM-20 Instruction Set
  289.  
  290.  
  291.  
  292. 2.1. Introduction
  293.  
  294.        This chapter was written by Ralph E. Gorin at Stanford University
  295.     and modified slightly at Columbia.
  296.  
  297. The PDP-10 is a general purpose stored program computer.  There are four
  298. different processors (computers) in the PDP-10 family:  the PDP-6, the KA10,
  299. the KI10 and the KL10.  The newest of these is the KL10 which is the central
  300. processor in various DECsystem-10 and DECSYSTEM-20 configurations.  (The KS10,
  301. found only in the DECSYSTEM-2020, is nearly identical to the KL10.)  In
  302. general, we shall discuss the KL10 processor.
  303.  
  304. There are three principal aspects of assembly language programming: the
  305. machine instructions, the assembler, and the operating system.  The machine
  306. instructions are the primitive operations with which we write programs.
  307. Learning the instruction set means learning what operations are performed by
  308. each instruction.  Programming is the art or science of combining these
  309. operations to accomplish some particular task.
  310.  
  311. The machine instructions, like everything else in a computer, are in binary.
  312. The assembler is a program that translates the mnemonic names by which we
  313. refer to instructons into the binary form that the computer recognizes.  The
  314. assembler also does a variety of other chores that are essentially
  315. bookkeeping.
  316.  
  317. The operating system, or "monitor", is a special program that handles all
  318. input and output and which schedules among user programs.  For its own
  319. protection and the protection of other users the operating system places
  320. various restrictions on user programs.  User mode programs are resticted to
  321. memory assigned to them by the operating system; they may not perform any
  322. machine input-output instructions, nor can they perform several other
  323. restricted operations (e.g., HALT instruction).  To facilitate user
  324. input-output and core allocation the operating system provides various monitor
  325. calls ( or JSYS operations) by which a user program can communicate its wishes
  326. to the system.  Essentially all programs except the operating system itself
  327. are run as user mode programs.  Editors, assemblers, compilers, utilities, and
  328. programs that you write yourself are all user mode programs.
  329.  
  330. The PDP-10 is a word oriented machine.  Words contain 36 data bits, numbered
  331. (left to right) 0 to 35.  Every machine instruction is one word.  There are
  332. two formats for machine instructions.
  333.  
  334. Most instructions have the format:
  335.  
  336.  
  337.     Bit      000000000 0111 1 1111 112222222222333333
  338.  Position    012345678 9012 3 4567 890123456789012345
  339.              ________________________________________
  340.             |         |    | |    |                  |
  341.             |   OP    | AC |I| X  |        Y         |
  342.             |_________|____|_|____|__________________|
  343.  
  344. In the diagram the field names are:
  345. Instruction Set                                                        Page 8
  346.  
  347.    - OP = operation code
  348.  
  349.    - AC = accumulator field
  350.  
  351.    - I = indirect bit
  352.  
  353.    - X = index field
  354.  
  355.    - Y = address field
  356.  
  357. Some example intructions are:
  358.  
  359.  
  360.         move 1, @100            ; MOVE is the OP.  AC is 1.
  361.                                 ;  @ sets the I bit.
  362.                                 ;  X is zero, Y is 100.
  363.  
  364.         hrrz 17, 1(3)           ; HRRZ is the OP. AC is 17,
  365.                                 ;  Y = 1, X = 3, I = 0
  366.  
  367.         sos foo                 ; SOS is OP, FOO is symbolic
  368.                                 ;  for the Y field.  AC, X, I
  369.                                 ;  are 0.
  370.  
  371.  
  372. All instructions without exception calculate an "effective address".  The
  373. effective address may itself be used as data or it may be used to address the
  374. data or result word for a particular instruction.  The effective address
  375. computation is described by the following program.  MA means memory address.
  376. means program counter.  C(MA) means contents of the word addressed by MA.
  377.  
  378.  
  379.  
  380.     Effective Address Calculation:
  381.  
  382.     IFETCH: MA := PC
  383.             OP := Bits  0:8  of C(MA);
  384.             AC := Bits  9:12 of C(MA);
  385.     EACOMP: I  := Bit  13    of C(MA);
  386.             X  := Bits 14:17 of C(MA);
  387.             Y  := Bits 18:35 of C(MA);
  388.             E  := Y;
  389.             IF X <> 0 then E := Bits 18:35 of E+C(X);
  390.             IF I=0 then go to DONE;
  391.             MA := E;
  392.             go to EACOMP
  393.     DONE:
  394.  
  395. The effective address is an 18 bit quantity.  If the I and X fields of the
  396. instruction are zero then the effective address is simply the address (Y)
  397. field of the instruction.  If X isn't zero, then the contents of the word
  398. addressed by X (i.e., the contents a register serving as the index register
  399. for this instruction) are added to the contents of the Y field (the sum is
  400. truncated to 18 bits).  This sum serves as the effective address, unless the
  401. indirect (I) bit is set.  If the I bit is set, a word is read from the address
  402. specified by X and Y, and the I, X, and Y fields of that new word are used for
  403. repeating the effective address calculation.  Note that this calculation will
  404. loop until a word is read in which the I field is zero.
  405. Instruction Set                                                        Page 9
  406.  
  407. The result of the effective address calculation may be thought of as an
  408. instruction word where bits 0:12 are copied from the original instruction,
  409. bits 13:17 are zero, and 18:35 contain the effective address.
  410.  
  411. In programming the PDP-10 it is convenient to imagine that your program
  412. occupies contiguous virtual memory locations from 0 to some maximum address.
  413. All memory locations are equivalent for most purposes (but some operating
  414. systems reserve some of your space for their own purposes).
  415.  
  416. Sixteen memory locations (addresses 0 to 17 - note that addresses will appear
  417. in octal) are distinguished by their use as general purpose registers (also
  418. called accumulators or index registers).  Most PDP-10 instructions address one
  419. memory operand and one accumulator (so-called "one and a half address"
  420. architecture).  This means that nearly all instructions affect some
  421. accumulator.  These registers are actually implemented in high speed solid
  422. state memory rather than in slower main memory.  For any purpose where it is
  423. convenient to do so, a user may reference an accumulator as memory.
  424.  
  425. Instruction classes are formed by a mnemonic class name and one or more
  426. modifier letters.  The modifiers usually signify some transformation on the
  427. data or the direction of data movement or the skip or jump condition.  Some
  428. functional duplications and some no-ops result from this scheme.  However,
  429. despite these drawbacks, this notion of instruction classes and modifiers
  430. makes the instruction set easy to learn.
  431.  
  432.  
  433.  
  434. 2.2. Full Word Instructions
  435.  
  436. These are the instructions whose basic purpose is to move one or more full
  437. words of data from one location to another, usualy from an accumulator to a
  438. memory location or vice versa.  In some cases, minor arithmetic operations are
  439. performed, such as taking the magnitude or negative of a word.
  440.  
  441.  
  442.  
  443. 2.2.1. MOVE
  444.  
  445. The MOVE class of instructions perform full word data transmission between an
  446. accumulator and a memory location.  There are sixteen instructions in the MOVE
  447. class.  All mnemonics begin with MOV.  The first modifier specifies a data
  448. transformation operation; the second modifier specifies the source of data and
  449. the destination of the result.
  450.  
  451.  
  452.      |E no modification |  from memory to AC
  453. MOV  |N negate source   |I Immediate. Source is 0,,E to AC
  454.      |M magnitude       |M from AC to memory
  455.      |S swap source     |S to self.  If AC<>0 to AC also
  456.  
  457. C(E) signifies contents of E (effective address) prior to the execution of the
  458. instruction.  C(AC) signifies contents of the AC specified.  CS(E) and CS(AC)
  459. signify the contents of E or AC with left and right halves swapped.  CR(AC)
  460. and CL(AC) signify the 18 bit right and left contents of the AC.  PC signifies
  461. the 18 bit contents of the program counter.
  462. Instruction Set                                                       Page 10
  463.  
  464.  
  465. MOVE     C(AC) := C(E)
  466. MOVEI    C(AC) := 0,,E
  467. MOVEM    C(E)  := C(AC)
  468. MOVES    C(E)  := C(E); if AC<>0 then C(AC) := C(E)
  469.  
  470. MOVN     C(AC) := -C(E)
  471. MOVNI    C(AC) := -E
  472. MOVNM    C(E)  := -C(AC)
  473. MOVNS    C(E)  := -C(E); if AC<>0 then C(AC) := -C(E)
  474.  
  475. MOVM     C(AC) := |C(E)|
  476. MOVMI    C(AC) := 0,,E
  477. MOVMM    C(E)  := |C(AC)|
  478. MOVMS    C(E)  := |C(E)|; if AC<>0 then C(AC) := |C(E)|
  479.  
  480. MOVS     C(AC) := CS(E)
  481. MOVSI    C(AC) := E,,0
  482. MOVSM    C(E)  := CS(AC)
  483. MOVSS    C(E)  := CS(E); if AC<>0 then C(AC) := CS(E)
  484.  
  485.  
  486.  
  487. 2.2.2. EXCH - Exchange
  488.  
  489. EXCH exchanges the contents of the selected ac with the contents of the
  490. effective address.
  491.  
  492.     EXCH     C(AC):=:C(E)
  493.  
  494.  
  495.  
  496. 2.2.3. BLT - Block Transfer
  497.  
  498. The instruction copies words from memory to memory.  The left half of the
  499. selected AC specifies the first source address.  The right half of the AC
  500. specifies the first destination address.  The effective address specifies the
  501. last destination address.  Words are copied, one by one, from the source to
  502. the destination, until a word is stored in an address greater than or equal to
  503. the effective address of the BLT.
  504.  
  505.        Caution: BLT clobbers the specified AC.  Don't use the BLT AC in
  506.     address calculation for the BLT, results will be random.  If source
  507.     and destination overlap, remember that BLT moves the lowest source
  508.     word first.  If the destination of the BLT includes the BLT AC, then
  509.     the BLT AC better be the last destination address.
  510.  
  511.  
  512.  
  513. 2.2.4. Programming Examples Using Fullword Instructions
  514.  
  515. In these examples, several standard PDP-10 assembly languange notations are
  516. used:
  517.  
  518. []              Square brackets enclose a "literal".  The contents of the
  519.                 brackets are assembled in another place, and the bracketed
  520.                 expression is replaced by the address of that place.
  521. Instruction Set                                                       Page 11
  522.  
  523. <>              Angle brackets enclose an expression.
  524.  
  525. ,,              Separates left- and right-half quantities in a word.  In
  526.                 <a,,b>, a is right-adjusted in bits 0:17, and b is right-
  527.                 adjusted in bits 18:35.  If either quantity is too big, it is
  528.                 truncated on the left.
  529.  
  530. ()              Parentheses enclose an expression which denotes an index
  531.                 register.
  532.  
  533. .               (pronounced "dot") Denotes the current location.
  534.  
  535.  
  536. ; Save all the accumulators:
  537.  
  538.         movem 17, savac+17
  539.         movei 17, savac         ; Source is 0, destination
  540.         blt 17, savac+16        ;  is SAVAC.
  541.  
  542. ; Restore all the accumulators:
  543.  
  544.         movsi 17, savac         ; Source is SAVAC,
  545.         blt 17, 17              ;  destination is 0.
  546.  
  547. ; Zero 100 words starting at TABLE.
  548.  
  549.         setzm table
  550.         move t1, [table,,table+1] ; Source and
  551.         blt t1, table+77        ;  destination overlap
  552.  
  553. ; Move 77 words from TABLE thru TABLE+76 to TABLE+1 thru
  554. ;  table+77: BLT can't be done here because the source and
  555. ;  destination overlap.  (See the description of POP.)
  556.  
  557.         move t1, [400076,,table+76]
  558.         pop t1, 1(t1)           ; Store TABLE+76 into
  559.         jumpl t1, .-1           ;  table+77, etc.
  560.  
  561.  
  562.  
  563. 2.3. Stack Instructions
  564.  
  565. These two instructions insert and remove full words in a pushdown list.  The
  566. address of the top of the list is kept in the right half of the AC referenced
  567. by these instructions.  The program may keep a control count in the left half
  568. of the AC.  There are also two subroutine calling instructions (PUSHJ and
  569. POPJ) that use this same format pushdown list.
  570.  
  571.  
  572.  
  573. 2.3.1. PUSH - Push on Stack
  574.  
  575.     PUSH C(AC):=C(AC)+<1,,1>; C(CR(AC)):=C(E)
  576.  
  577. The specified accumulator is incremented by adding 1 to each half (in the KI10
  578. and KL10 carry out of the right half is suppressed).  If, as result of the
  579. addition, the left half of the AC becomes positive, a pushdown overflow
  580. condition results (but the instruction procedes to completion).  The word
  581. Instruction Set                                                       Page 12
  582.  
  583. addressed by the effective address is fetched and stored on the top of the
  584. stack which is addressed by the right half of the (incremented) accumulator.
  585.  
  586.  
  587.  
  588. 2.3.2. POP - Pop Stack
  589.  
  590.     POP C(E):=C(CR(AC)); C(AC):=C(AC)-<1,,1>
  591.  
  592. POP undoes PUSH as follows: the word at the top of the stack (addressed by the
  593. right half of the selected AC) is fetched and stored at the effective address.
  594. Then the AC is decremented by subtracting 1 from both halves (in the KI10 and
  595. KL10 carry out of bit 18 is suppressed).  If the AC becomes negative as a
  596. result of the subtraction a pushdown overflow results.
  597.  
  598. Often the accumulator used as the pushdown pointer is given the symbolic name
  599. P. To initialize a pushdown pointer (e.g., for N words starting at PDLIST),
  600. one might do the following:
  601.  
  602.     move p, [iowd n, pdList]
  603.  
  604. where the IOWD pseudo op assembles -N,,PDLIST-1.  Elsewhere in the program
  605. should appear:
  606.  
  607.     pdList:  block n
  608.  
  609. which defines the symbolic label PDLIST and reserves N words following it for
  610. the stack.
  611.  
  612.  
  613.  
  614. 2.3.3. ADJSP - Adjust Stack Pointer
  615.  
  616.     ADJSP CL(AC) := CL(AC)+E; CR(AC) := CR(AC)+E
  617.  
  618. E is added algebraically, with bit 18 acting as the sign bit, to both halves
  619. of AC.  If a negative E changes the count in AC left from positive or zero to
  620. negative, or a positive E changes the count from negative to positive or zero,
  621. set trap 2.
  622.  
  623.  
  624.  
  625. 2.4. Halfword Instructions
  626.  
  627. The halfword class of instructions perform data transmission between one half
  628. of an accumulator and one half of a memory location.  There are sixty-four
  629. halfword instructions.  Each mnemonic begins with H and has four modifiers.
  630. The first modifier specifies which half of the source word; the second
  631. specifies which half of the destination.  The third modifier specifies what to
  632. do to the other half of the destination.  The fourth modifier specifies the
  633. source of data and the destination of the result.
  634. Instruction Set                                                       Page 13
  635.  
  636.  
  637. H halfword from |R right  of source
  638.                 |L left
  639.  
  640.                   |R right  of destination
  641.                   |L left
  642.  
  643.                     |  no modification of other half
  644.                     |Z zero other half
  645.                     |O set other half to ones
  646.                     |E sign extend source to other half
  647.  
  648.                       |  from memory to AC
  649.                       |I Immediate
  650.                       |M from AC to memory
  651.                       |S to self. If AC<>0 to AC also.
  652.  
  653.  
  654.  
  655. 2.4.1. HR - Halfword Right
  656.  
  657. HRR      CR(AC) := CR(E)
  658. HRRI     CR(AC) := E
  659. HRRM     CR(E)  := CR(AC)
  660. HRRS     CR(E)  := CR(E); if AC<>0 then CR(AC) := CR(E)
  661.  
  662. HRRZ     C(AC) := 0,,CR(E)
  663. HRRZI    C(AC) := 0,,E
  664. HRRZM    C(E)  := 0,,CR(AC)
  665. HRRZS    C(E)  := 0,,CR(E); if AC<>0 then C(AC) := 0,,CR(E)
  666.  
  667. HRRO     C(AC) := 777777,,CR(E)
  668. HRROI    C(AC) := 777777,,E
  669. HRROM    C(E)  := 777777,,CR(AC)
  670. HRROS    C(E)  := 777777,,CR(E);
  671.                   if AC<>0 then C(AC) := 777777,,CR(E)
  672.  
  673. HRRE     C(AC) := 777777*C18(E),,CR(E)
  674. HRREI    C(AC) := 777777*E18,,E
  675. HRREM    C(E)  := 777777*C18(AC),,CR(AC)
  676. HRRES    C(E)  := 777777*C18(E),,CR(E);
  677.                  if AC<>0 then C(AC) := 777777*C18(E),,CR(E)
  678.  
  679. HRL      CL(AC) := CR(E)
  680. HRLI     CL(AC) := E
  681. HRLM     CL(E)  := CR(AC)
  682. HRLS     CL(E)  := CR(E); if AC<>0 then CL(AC) := CR(E)
  683.  
  684. HRLZ     C(AC) := CR(E),,0
  685. HRLZI    C(AC) := E,,0
  686. HRLZM    C(E)  := CR(AC),,0
  687. HRLZS    C(E)  := CR(E),,0;
  688.                   if AC<>0 then C(AC) := CR(E),,0
  689. Instruction Set                                                       Page 14
  690.  
  691.  
  692. HRLO     C(AC) := CR(E),,777777
  693. HRLOI    C(AC) := E,,777777
  694. HRLOM    C(E)  := CR(E),,777777
  695. HRLOS    C(E)  := CR(E),,777777;
  696.                   if AC<>0 then C(AC) := CR(E),,777777
  697.  
  698. HRLE     C(AC) := CR(E),,777777*C18(E)
  699. HRLEI    C(AC) := E,,777777*E18
  700. HRLEM    C(E)  := CR(AC),,777777*C18(AC)
  701. HRLES    C(E)  := CR(E),,777777*C18(E);
  702.                  if AC<>0 then C(AC) := CR(E),,777777*C18(E)
  703.  
  704.  
  705.  
  706. 2.4.2. HL Halfword Left
  707.  
  708. HLR      CR(AC) := CL(E)
  709. HLRI     CR(AC) := 0
  710. HLRM     CR(E)  := CL(AC)
  711. HLRS     CR(E)  := CL(E); if AC<>0 then CR(AC) := CL(E)
  712.  
  713. HLRZ     C(AC) := 0,,CL(E)
  714. HLRZI    C(AC) := 0
  715. HLRZM    C(E)  := 0,,CL(AC)
  716. HLRZS    C(E)  := 0,,CL(E);
  717.                   if AC<>0 then C(AC) := 0,,CL(E)
  718.  
  719. HLRO     C(AC) := 777777,,CL(E)
  720. HLROI    C(AC) := 777777,,0
  721. HLROM    C(E)  := 777777,,CL(AC)
  722. HLROS    C(E)  := 777777,,CL(E);
  723.                   if AC<>0 then C(AC) := 777777,,CL(E)
  724.  
  725. HLRE     C(AC) := 777777*C0(E),,CL(E)
  726. HLREI    C(AC) := 0
  727. HRREM    C(E)  := 777777*C0(AC),,CL(AC)
  728. HRRES    C(E)  := 777777*C0(E),,CL(E);
  729.                   if AC<>0 then C(AC) := 777777*C0(E),,CR(E)
  730.  
  731. HLL      CL(AC) := CL(E)
  732. HLLI     CL(AC) := 0
  733. HLLM     CL(E)  := CL(AC)
  734. HLLS     CL(E)  := CL(E); if AC<>0 then CL(AC) := CL(E)
  735.  
  736. HLLZ     C(AC) := CL(E),,0
  737. HLLZI    C(AC) := 0
  738. HLLZM    C(E)  := CL(AC),,0
  739. HLLZS    C(E)  := CL(E),,0;
  740.                   if AC<>0 then C(AC) := CL(E),,0
  741.  
  742. HLLO     C(AC) := CL(E),,777777
  743. HLLOI    C(AC) := 0,,777777
  744. HLLOM    C(E)  := CL(E),,777777
  745. HLLOS    C(E)  := CL(E),,777777;
  746.                   if AC<>0 then C(AC) := CL(E),,777777
  747. Instruction Set                                                       Page 15
  748.  
  749.  
  750. HLLE     C(AC) := CL(E),,777777*C0(E)
  751. HLLEI    C(AC) := 0
  752. HLLEM    C(E)  := CL(AC),,777777*C0(AC)
  753. HLLES    C(E)  := CL(E),,777777*C0(E);
  754.                   if AC<>0 then C(AC) := CL(E),,777777*C0(E)
  755.  
  756.  
  757.  
  758. 2.5. Arithmetic Testing
  759.  
  760.  
  761.  
  762. 2.5.1. AOBJ - Add One to Both Halves and Jump
  763.  
  764. The AOBJx (Add One to Both halves of AC and Jump) instructions allow forward
  765. indexing through an array while maintaining a control count in the left half
  766. of an accumulator.  Use of AOBJN and AOBJP can reduce loop control to one
  767. instruction.
  768.  
  769.  
  770.     AOBJN   C(AC):=C(AC)+<1,,1>; if C(AC)<0 then PC:=E
  771.     AOBJP   C(AC):=C(AC)+<1,,1>; if C(AC)>=0 then PC:=E
  772.  
  773.  
  774. Example.  Add 3 to N words starting at location TAB:
  775.  
  776.  
  777.         movsi 1, -N             ; Initialize register 1 to -N,,0.
  778.         movei 2, 3              ; Register 2 gets the constant 3.
  779.         addm 2, tab(1)          ; Add 3 to one array element.
  780.         aobjn 1, .-1            ; Increment both the index and the
  781.                                 ;  control.  Loop until the ADDM has
  782.                                 ;  been done N times.
  783.  
  784. By the way, for the sake of consistency, AOBJN should have been called AOBJL
  785. and AOBJP should have been called AOBJGE.  However, they weren't.
  786.  
  787.  
  788.  
  789. 2.5.2. JUMP
  790.  
  791. The JUMP instructions compare the selected accumulator to zero and jump (to
  792. the effective address of the instruction) if the specified relation is true.
  793.  
  794.  
  795. JUMP     Jump never.
  796. JUMPL    if C(AC) <  0 then PC:=E
  797. JUMPLE   if C(AC) <= 0 then PC:=E
  798. JUMPE    if C(AC) =  0 then PC:=E
  799. JUMPN    if C(AC) <> 0 then PC:=E
  800. JUMPGE   if C(AC) >= 0 then PC:=E
  801. JUMPG    if C(AC) >  0 then PC:=E
  802. JUMPA    PC:=E
  803. Instruction Set                                                       Page 16
  804.  
  805. 2.5.3. SKIP
  806.  
  807. The SKIP instructions compare the contents of the effective address to zero
  808. and skip the next instruction if the specified relation is true.  If a
  809. non-zero AC field appears, the selected AC is loaded from memory.
  810.  
  811.  
  812. SKIP     if AC<>0 then C(AC):=C(E); don't skip
  813. SKIPL    if AC<>0 then C(AC):=C(E);
  814.             if C(E) < 0 then skip
  815. SKIPLE   if AC<>0 then C(AC):=C(E);
  816.             if C(E) <= 0 then skip
  817. SKIPE    if AC<>0 then C(AC):=C(E);
  818.             if C(E) = 0 then skip
  819. SKIPN    if AC<>0 then C(AC):=C(E);
  820.             if C(E) <> 0 then skip
  821. SKIPGE   if AC<>0 then C(AC):=C(E);
  822.             if C(E) >= 0 then skip
  823. SKIPG    if AC<>0 then C(AC):=C(E);
  824.             if C(E) > 0 then skip
  825. SKIPA    if AC<>0 then C(AC):=C(E);  skip
  826.  
  827.  
  828.  
  829. 2.5.4. AOS - Add One and Skip
  830.  
  831. The AOS (Add One to memory and Skip) instructions increment a memory location,
  832. compare the result to zero to determine the skip condition, If a non-zero AC
  833. field appears then the AC selected will be loaded (with the incremented data).
  834.  
  835.  
  836. AOS      C(E) := C(E)+1;  if AC<>0 then C(AC):=C(E)
  837. AOSL     C(E) := C(E)+1;  if AC<>0 then C(AC):=C(E);
  838.                  if C(E) < 0 then skip
  839. AOSLE    C(E) := C(E)+1;  if AC<>0 then C(AC):=C(E);
  840.                  if C(E) <= 0 then skip
  841. AOSE     C(E) := C(E)+1;  if AC<>0 then C(AC):=C(E);
  842.                  if C(E) = 0 then skip
  843. AOSN     C(E) := C(E)+1;  if AC<>0 then C(AC):=C(E);
  844.                  if C(E) <> 0 then skip
  845. AOSGE    C(E) := C(E)+1;  if AC<>0 then C(AC):=C(E);
  846.                  if C(E) >= 0 then skip
  847. AOSG     C(E) := C(E)+1;  if AC<>0 then C(AC):=C(E);
  848.                  if C(E) > 0 then skip
  849. AOSA     C(E) := C(E)+1;  if AC<>0 then C(AC):=C(E);
  850.                  skip
  851.  
  852.  
  853.  
  854. 2.5.5. SOS - Subtract One and Skip
  855.  
  856. The SOS (Subtract One from memory and Skip) instructions decrement a memory
  857. location, compare the result to zero to determine the skip condition, If a
  858. non-zero AC field appears then the AC selected will be loaded (with the
  859. decremented data).
  860. Instruction Set                                                       Page 17
  861.  
  862.  
  863. SOS      C(E) := C(E)-1;  if AC<>0 then C(AC):=C(E)
  864. SOSL     C(E) := C(E)-1;  if AC<>0 then C(AC):=C(E);
  865.                  if C(E) < 0 then skip
  866. SOSLE    C(E) := C(E)-1;  if AC<>0 then C(AC):=C(E);
  867.                  if C(E) <= 0 then skip
  868. SOSE     C(E) := C(E)-1;  if AC<>0 then C(AC):=C(E);
  869.                  if C(E) = 0 then skip
  870. SOSN     C(E) := C(E)-1;  if AC<>0 then C(AC):=C(E);
  871.                   C(E) <> 0 then skip
  872. SOSGE    C(E) := C(E)-1;  if AC<>0 then C(AC):=C(E);
  873.                  if C(E) >= 0 then skip
  874. SOSG     C(E) := C(E)-1;  if AC<>0 then C(AC):=C(E);
  875.                  if C(E) > 0 then skip
  876. SOSA     C(E) := C(E)-1;  if AC<>0 then C(AC):=C(E);
  877.                  skip
  878.  
  879.  
  880.  
  881. 2.5.6. AOJ - Add One and Jump
  882.  
  883. The AOJ (Add One to AC and Jump) instructions increment the contents of the
  884. selected accumulator.  If the result bears the indicated relation to zero then
  885. the instruction will jump to the effective address.
  886.  
  887.  
  888. AOJ      C(AC) := C(AC)+1;
  889. AOJL     C(AC) := C(AC)+1; if C(AC) <  0 then PC:=E
  890. AOJLE    C(AC) := C(AC)+1; if C(AC) <= 0 then PC:=E
  891. AOJE     C(AC) := C(AC)+1; if C(AC) =  0 then PC:=E
  892. AOJN     C(AC) := C(AC)+1; if C(AC) <> 0 then PC:=E
  893. AOJGE    C(AC) := C(AC)+1; if C(AC) >= 0 then PC:=E
  894. AOJG     C(AC) := C(AC)+1; if C(AC) >  0 then PC:=E
  895. AOJA     C(AC) := C(AC)+1; PC:=E
  896.  
  897.  
  898.  
  899. 2.5.7. SOJ - Subtract One and Jump
  900.  
  901. The SOJ (Subtract One from AC and Jump) instructions decrement the contents of
  902. the selected accumulator.  If the result bears the indicated relation to zero
  903. then the instruction will jump to the effective address.
  904.  
  905.  
  906. SOJ      C(AC) := C(AC)-1
  907. SOJL     C(AC) := C(AC)-1; if C(AC) <  0 then PC:=E
  908. SOJLE    C(AC) := C(AC)-1; if C(AC) <= 0 then PC:=E
  909. SOJE     C(AC) := C(AC)-1; if C(AC) =  0 then PC:=E
  910. SOJN     C(AC) := C(AC)-1; if C(AC) <> 0 then PC:=E
  911. SOJGE    C(AC) := C(AC)-1; if C(AC) >= 0 then PC:=E
  912. SOJG     C(AC) := C(AC)-1; if C(AC) >  0 then PC:=E
  913. SOJA     C(AC) := C(AC)-1; PC:=E
  914. Instruction Set                                                       Page 18
  915.  
  916. 2.5.8. CAM - Compare Accumulator to Memory
  917.  
  918. The CAM (Compare Accumulator to Memory) class compare the contents of the
  919. selected accumulator to the contents of the effective address.  If the
  920. indicated condition is true, the instruction will skip.  The CAM instruction
  921. is suitable for arithmetic comparision of either fixed point quantities or
  922. normalized floating point quantities.  Needless to say, for the comparison to
  923. be meaningful both C(AC) and C(E) should be in the same format (i.e., either
  924. both fixed or both floating).
  925.  
  926.  
  927. CAM      no op (references memory)
  928. CAML     if C(AC) <  C(E) then skip
  929. CAMLE    if C(AC) <= C(E) then skip
  930. CAME     if C(AC) =  C(E) then skip
  931. CAMN     if C(AC) <> C(E) then skip
  932. CAMGE    if C(AC) >= C(E) then skip
  933. CAMG     if C(AC) >  C(E) then skip
  934. CAMA     skip
  935.  
  936.  
  937.  
  938. 2.5.9. CAI - Compare Accumulator Immediate
  939.  
  940. The CAI (Compare Accumulator Immediate) class compare the contents of the
  941. selected accumulator to the effective address.  If the indicated condition is
  942. true, the instruction will skip.  Note than an effective address is an 18 bit
  943. quantity that is always considered to be positive.
  944.  
  945.  
  946. CAI      no op
  947. CAIL     if C(AC) <  E then skip
  948. CAILE    if C(AC) <= E then skip
  949. CAIE     if C(AC) =  E then skip
  950. CAIN     if C(AC) <> E then skip
  951. CAIGE    if C(AC) >= E then skip
  952. CAIG     if C(AC) >  E then skip
  953. CAIA     skip
  954.  
  955.  
  956. Skipping instructions can be combined to achieve ANDing or ORing of logical
  957. expressions, e.g. the sequence
  958.  
  959.  
  960.         cail t1, 1
  961.          caile t1, 1000
  962.          jrst bad
  963.  
  964.  
  965. is equivalent to
  966.  
  967.     if C(t1) < 1 or C(t1) > 1000 then go to BAD
  968. Instruction Set                                                       Page 19
  969.  
  970. 2.6. Fixed Point Arithmetic
  971.  
  972. In positive numbers bit 0 is zero.  Bit 1 is most significant; bit 35 is least
  973. significant.  Negative numbers are the two's complement of positive numbers.
  974. Results (of ADD, SUB or IMUL) outside the range -2^35 to 2^35-1 will set
  975. overflow ( PC bit 0).
  976.  
  977.  
  978.  
  979. 2.6.1. ADD
  980.  
  981. ADD     C(AC) := C(AC) + C(E)
  982. ADDI    C(AC) := C(AC) + E
  983. ADDM    C(E)  := C(AC) + C(E)
  984. ADDB    C(AC) := C(AC) + C(E);  C(E) := C(AC)
  985.  
  986.  
  987.  
  988. 2.6.2. SUB - Subtract
  989.  
  990. SUB     C(AC) := C(AC) - C(E)
  991. SUBI    C(AC) := C(AC) - E
  992. SUBM    C(E)  := C(AC) - C(E)
  993. SUBB    C(AC) := C(AC) - C(E);  C(E) := C(AC)
  994.  
  995.  
  996.  
  997. 2.6.3. IMUL - Single-Word Multiply
  998.  
  999. The IMUL instructions are for multiplying numbers where the product is
  1000. expected to be representable as one word.
  1001.  
  1002.  
  1003. IMUL    C(AC) := C(AC) * C(E)
  1004. IMULI   C(AC) := C(AC) * E
  1005. IMULM   C(E)  := C(AC) * C(E)
  1006. IMULB   C(AC) := C(AC) * C(E);  C(E) := C(AC)
  1007.  
  1008.  
  1009.  
  1010. 2.6.4. IDIV - Single-Word Divide
  1011.  
  1012. The IDIV instructions are for divisions in which the dividend is a one word
  1013. quantity.  AC+1 signifes the quantity (AC+1 modulo 20 octal).  If the divisor
  1014. is zero set overflow and no divide; don't change AC or memory operands.  The
  1015. remainder will have the same sign as the dividend.
  1016.  
  1017.  
  1018. IDIV    C(AC) := C(AC) / C(E);  C(AC+1) := remainder
  1019. IDIVI   C(AC) := C(AC) / E;     C(AC+1) := remainder
  1020. IDIVM   C(E)  := C(AC) / E
  1021. IDIVB   C(AC) := C(AC) / C(E);  C(AC+1) := remainder;
  1022.          C(E) := C(AC)
  1023. Instruction Set                                                       Page 20
  1024.  
  1025. 2.6.5. MUL - Multiply
  1026.  
  1027. The MUL instructions produce a double word product.  A double word integer has
  1028. 70 bits of significance.  Bit 0 of the high order word is the sign bit.  In
  1029. data, Bit 0 of the low order word is ignored by the hardware.  In results, bit
  1030. 0 of the low word is the same as bit 0 in the high word.  MUL will set
  1031. overflow if both operands are -2^35.
  1032.  
  1033.  
  1034. MUL     C(AC AC+1) := C(AC) * C(E)
  1035. MULI    C(AC AC+1) := C(AC) * E
  1036. MULM    C(E)  := high word of product of C(AC) * C(E)
  1037. MULB    C(AC AC+1) := C(AC) * C(E);  C(E) := C(AC)
  1038.  
  1039.  
  1040.  
  1041. 2.6.6. DIV - Divide
  1042.  
  1043. The DIV instructions are for divisions in which the dividend is a two word
  1044. quantity (such as produced by MUL).  If C(AC) is greater than the memory
  1045. operand then set overflow and no divide.
  1046.  
  1047.  
  1048. DIV     C(AC) := C(AC AC+1) / C(E); C(AC+1) := remainder
  1049. DIVI    C(AC) := C(AC AC+1) / E;    C(AC+1) := remainder
  1050. DIVM    C(E)  := C(AC AC+1) / E
  1051. DIVB    C(AC) := C(AC AC+1) / C(E); C(AC+1) := remainder;
  1052.                        C(E) := C(AC)
  1053.  
  1054.  
  1055.  
  1056. 2.7. Double Word Move Instructions (KI10 and KL10)
  1057.  
  1058. There are four double word move instructions.  These are suitable for
  1059. manipulating KI10 and KL10 double precision floating point numbers, and for
  1060. KL10 double precision integers.
  1061.  
  1062.  
  1063. DMOVE   C(AC AC+1) := C(E E+1)
  1064. DMOVEM  C(E E+1) := C(AC AC+1)
  1065. DMOVN   C(AC AC+1) := -C(E E+1)
  1066. DMOVNM  C(E E+1) := -C(AC AC+1)
  1067.  
  1068.        Note that the DMOVN and DMOVNM are NOT to be used for KA10 double
  1069.     precision floating point numbers!
  1070.  
  1071. If a program is written that may be have to be run on a KA10, the use of all
  1072. double word instructions should be avoided.
  1073.  
  1074.  
  1075.  
  1076. 2.8. Double Precision Integer Arithmetic (KL10 only)
  1077.  
  1078. There are four instructions for double precision integer arithmetic.  None of
  1079. these instructions have any modifier: they all operate on double (or
  1080. quadruple) accumulators and double words in memory with results to double (or
  1081. quadruple) accumulators.
  1082. Instruction Set                                                       Page 21
  1083.  
  1084. The format for a double word integer is the same as that produced by MUL,
  1085. i.e., a 70 bit integer in two's complement, with bit 0 of the most significant
  1086. word is the sign; in operands, bit 0 of the low order word is ignored.  A
  1087. quadruple word has 140 bits; bit 0 of the most significant word is the sign;
  1088. in operands, bit 0 in all other words is ignored.  In double (and quadruple)
  1089. arithmetic results bit 0 of the low order word(s) is stored with the same
  1090. value as bit 0 of the high order word.
  1091.  
  1092.  
  1093. DADD    C(AC AC+1) := C(AC AC+1) + C(E E+1)
  1094. DSUB    C(AC AC+1) := C(AC AC+1) - C(E E+1)
  1095. DMUL    C(AC AC+1 AC+2 AC+3) := C(AC AC+1) * C(E E+1)
  1096. DDIV    C(AC AC+1) := C(AC AC+1 AC+2 AC+3) / C(E E+1)
  1097.          C(AC+2 AC+3) := remainder
  1098.  
  1099.  
  1100.  
  1101. 2.9. Floating Point Arithmetic
  1102.  
  1103. Single precision floating point numbers are represented in one 36 bit word as
  1104. follows:
  1105.  
  1106.  
  1107.    Bit      0 00000000 011111111112222222222333333
  1108. Position    0 12345678 901234567890123456789012345
  1109.             ______________________________________
  1110.            | |        |                           |
  1111.            |S|  Exp   |        Fraction           |
  1112.            |_|________|___________________________|
  1113.  
  1114. If S is zero, the sign is positive.  If S is one the sign is negative and the
  1115. word is in two's complement format.  The fraction is interpreted as having a
  1116. binary point between bits 8 and 9.  The exponent is a power of 2 represented
  1117. in excess 200 (octal) notation.  In a normalized floating point number bit 9
  1118. is different from bit 0, except in a negative number bits 0 and 9 may both be
  1119. one if bits 10:35 are all zero.  A floating point zero is represented by a
  1120. word with 36 bits of zero.  Floating point numbers can represent numbers with
  1121. magnitude within the range 0.5*2^-128 to (1-2^-27)*2^127, and zero.
  1122.  
  1123. A number in which bit 0 is one and bits 9-35 are zero can produce an incorrect
  1124. result in any floating point operation.  Any word with a zero fraction and
  1125. non-zero exponent can produce extreme loss of precision if used as an operand
  1126. in a floating point addition or subtraction.
  1127.  
  1128. In KI10 (and KL10) double precision floating point, a second word is included
  1129. which contains in bits 1:35 an additional 35 fraction bits.  The additional
  1130. fraction bits do not significantly affect the range of representable numbers,
  1131. rather they extend the precision.
  1132.  
  1133. The KA10 lacks double precision floating point hardware, but there are several
  1134. instructions by which software may implement double precision.  These
  1135. instructions are DFN, UFA, FADL, FSBL, FMPL, and FDVL.  Users of the KL10 are
  1136. strongly advised to avoid using these intructions.
  1137.  
  1138. In the PDP-6 floating point is somewhat different.  Consult an wizard.
  1139. Instruction Set                                                       Page 22
  1140.  
  1141.  
  1142. F floating
  1143.  
  1144.     |AD add                       |  result to AC
  1145.     |SB subtract  |R rounded      |I Immediate. result to AC
  1146.     |MP multiply  |               |M result to memory
  1147.     |DV divide    |               |B result to memory and AC
  1148.                   |
  1149.                   |
  1150.                   |  no rounding  |  result to AC
  1151.                                   |L Long mode
  1152.                                   |M result to memory
  1153.                                   |B result to memory and AC
  1154.  
  1155.  
  1156.                    |AD add
  1157. DF double floating |SB subtract
  1158.                    |MP multiply
  1159.                    |DV divide
  1160.  
  1161.        Note: In immediate mode, the memory operand is <E,,0>.  In long
  1162.     mode (except FDVL) the result appears in AC and AC+1.  In FDVL the AC
  1163.     operand is in AC and AC+1 and the quotient is stored in AC with the
  1164.     remainder in AC+1.
  1165.  
  1166.  
  1167.  
  1168. 2.10. Other Floating Point Instructions
  1169.  
  1170.  
  1171.  
  1172. 2.10.1. FSC - Floating Scale
  1173.  
  1174. FSC (Floating SCale) will add E to the exponent of the number in AC and
  1175. normalize the result.  One use of FSC is to convert an integer in AC to
  1176. floating point (but FLTR, available in the KI and KL is better).  To use FSC
  1177. to float an integer, set E to 233 (excess 200 and shift the binary point 27
  1178. bits).  The integer being floated must not have more than 27 significant bits.
  1179. FSC will set AROV and FOV if the resulting exponent exceeds 127.  FXU (and
  1180. AROV and FOV) will be set if the exponent becomes smaller than -128.
  1181.  
  1182.  
  1183.  
  1184. 2.10.2. FIX - Convert Floating Point to Integer
  1185.  
  1186. FIX will convert a floating point number to an integer.  If the exponent of
  1187. the floating point number in C(E) is greater than (decimal) 35 (which is octal
  1188. 243) then this instruction will set AROV and not affect C(AC).  Otherwise,
  1189. convert C(E) to fixed point by the following procedure: Move C(E) to AC,
  1190. copying bit 0 of C(E) to bits 1:8 of AC (sign extend).  Then ASH AC by X-27
  1191. bits (where X is the exponent from bits 1:9 of C(E) less 200 octal).  FIX will
  1192. truncate towards zero, i.e., 1.9 is fixed to 1 and -1.9 is fixed to -1.
  1193. Instruction Set                                                       Page 23
  1194.  
  1195. 2.10.3. FIXR - Fix and Round
  1196.  
  1197. FIXR (Fix and round) will convert a number to an integer by rounding.  If the
  1198. exponent of the floating point number in C(E) is greater than (decimal) 35
  1199. (which is octal 243) then this instruction will set AROV and not affect C(AC).
  1200. Otherwise, convert C(E) to fixed point by the following procedure:  Move C(E)
  1201. to AC, copying bit 0 of C(E) to bits 1:8 of AC (sign extend).  Then ASH AC by
  1202. X-27 bits (where X is the exponent from bits 1:9 of C(E) less 200 octal).  If
  1203. X-27 is negative (i.e., right shift) then the rounding process will consider
  1204. the bits shifted off the right end of AC.  If AC is positive and the discarded
  1205. bits are >=1/2 then 1 is added to AC.  If AC is negative and the discarded
  1206. bits are >1/2 then 1 is added to AC.  Rounding is always in the positive
  1207. direction:  1.4 becomes 1, 1.5 becomes 2, -1.5 becomes -1, and -1.6 becomes
  1208. -2.
  1209.  
  1210.  
  1211.  
  1212. 2.10.4. FLTR - Float and Round
  1213.  
  1214. FLTR (FLoaT and Round) will convert C(E), an integer, to floating point and
  1215. place the result in AC.  The data from C(E) is copied to AC where its is
  1216. arithmetic shifted right 8 places (keeping the bits that fall off the end) and
  1217. the exponent 243 is inserted in bits 1:8.  The resulting number is normalized
  1218. until bit 9 is significant (normalization may result in some or all of the
  1219. bits that were right shifted being brought back into AC).  Finally, if any of
  1220. the bits that were right shifted still remain outside the AC the result is
  1221. rounded by looking at the bit to the right of the AC.
  1222.  
  1223.  
  1224.  
  1225. 2.11. Shift Instructions
  1226.  
  1227. The following instructions shift or rotate the AC or the formed by AC and
  1228. AC+1.  The number of places to shift is specified by the effective address
  1229. which is considered to be a signed number modulo 256 in magnitude.  That is,
  1230. the effective shift is the number composed of bit 18 (the sign) of the
  1231. effective address and bits 28:35 of the effective address.  If E is positive,
  1232. a left shift occurs.  If E is negative a right shift occurs.
  1233.  
  1234. LSH             Logical Shift.  C(AC) is shifted as specified by E. Zero bits
  1235.                 are shifted into the AC.
  1236.  
  1237. LSHC            Logical Shift Combined.  C(AC AC+1) is shifted as a 72 bit
  1238.                 quantity.  Zero bits are shifted in.
  1239.  
  1240. ASH             Arithmetic Shift.  Bit 0 is not changed.  In a left shift zero
  1241.                 bits are shifted into the right end of AC.  In a left shift,
  1242.                 if any bit of significance is shifted out of bit 1, AROV
  1243.                 ( overflow) is set.  In a right shift, bit 0 is shifted into
  1244.                 bit 1.
  1245.  
  1246. ASHC            Arithmetic Shift Combined.  AC bit 0 is not changed.  If E is
  1247.                 non zero, AC bit 0 is copied to AC+1 bit 0.  C(AC AC+1) is
  1248.                 shifted as a 70 bit quantity.  In a left shift zero bits are
  1249.                 shifted into the right end of AC+1.  In a left shift, if any
  1250.                 bit of significance is shifted out of AC bit 1 then AROV is
  1251.                 set.  In a right shift AC bit 0 is shifted into AC bit 1.
  1252. Instruction Set                                                       Page 24
  1253.  
  1254. ROT             Rotate.  The 36 bit C(AC) is rotated.  In a left rotate bits
  1255.                 shifted out of bit 0 are shifted into bit 35.  In a right
  1256.                 rotate, Bit 35 is shifted into bit 0.
  1257.  
  1258. ROTC            Rotate Combined.  AC and AC+1 are rotated as a 72 bit
  1259.                 quantity.  In a left rotate AC bit 0 shifts into AC+1 bit 35
  1260.                 and AC+1 bit 0 shifts into AC bit 35.  In a right rotate, AC+1
  1261.                 bit 35 shifts into AC bit 0, etc.
  1262.  
  1263.  
  1264.  
  1265. 2.12. Byte Instructions
  1266.  
  1267. In the PDP-10 a "byte" is some number of contiguous bits within one word.  A
  1268. byte pointer is a word that describes the byte.  There are three parts to the
  1269. description of a byte: the word (i.e., address) in which the byte occurs, the
  1270. position of the byte within the word, and the length of the byte.
  1271.  
  1272. A byte pointer has the following format:
  1273.  
  1274.  
  1275.    Bit     000000 000011 1 1 1111 112222222222333333
  1276.  Position  012345 678901 2 3 4567 890123456789012345
  1277.            _________________________________________
  1278.           |      |      | | |    |                  |
  1279.           | POS  | SIZE |U|I| X  |        Y         |
  1280.           |______|______|_|_|____|__________________|
  1281.  
  1282.    - POS is the byte position: the number of bits remaining in the word
  1283.      to the right of the byte.
  1284.  
  1285.    - SIZE is the byte size in bits.
  1286.  
  1287.    - The U field is reserved for future use and must be zero.
  1288.  
  1289.    - I, X, and Y are the same as in an instruction.
  1290.  
  1291.  
  1292.  
  1293. 2.12.1. LDB - Load Byte
  1294.  
  1295. The contents of the effective address of the LDB instruction is interpreted as
  1296. a byte pointer.  The byte described there is loaded, right adjusted, into the
  1297. AC.  The rest of the AC is cleared.
  1298.  
  1299.  
  1300.  
  1301. 2.12.2. DPB - Deposit Byte
  1302.  
  1303. The contents of the effective address of the DPB instruction is interpreted as
  1304. a byte pointer.  The byte described there is deposited from the byte of the
  1305. same size at the right end of the AC.  AC and the remainder of the word into
  1306. which the byte is deposited are left unchanged.
  1307. Instruction Set                                                       Page 25
  1308.  
  1309. 2.12.3. IBP - Increment Byte Pointer
  1310.  
  1311. The AC field must be zero.  The contents of the effective address are fetched.
  1312. The POS field is changed by subtracting the size field from it.  If the result
  1313. of the subtraction is greater than or equal to zero, store the difference in
  1314. the POS field.  If the difference is negative, add 1 to the Y field (in the
  1315. KA10 and PDP-6 if Y contains 777777 then this will carry into the X field; in
  1316. the KI10 and KL10 the carry out is suppressed) and set POS field to 44-SIZE
  1317. (44 is octal).  The effect of this is to modify the byte pointer to address
  1318. the next byte (of the same size) that follows the byte addressed by the
  1319. original pointer, skipping over any bits that may be left over at the end of a
  1320. word (when the bytesize does not divide evenly into the wordsize, 36).
  1321.  
  1322.  
  1323.  
  1324. 2.12.4. ILDB - Increment and Load Byte
  1325.  
  1326. Increment the byte pointer contained at the effective address.  Then perform a
  1327. LDB function using the updated byte pointer.
  1328.  
  1329.  
  1330.  
  1331. 2.12.5. IDPB - Increment and Deposit Byte
  1332.  
  1333. Increment the byte pointer contained at the effective address.  Then perform a
  1334. DPB function using the updated byte pointer.
  1335.  
  1336.  
  1337.  
  1338. 2.12.6. ADJBP - Adjust Byte Pointer
  1339.  
  1340. Fetch the byte pointer at the effective address, increment or decrement it by
  1341. the number of bytes specified in the AC, then place the adjusted byte pointer
  1342. in the AC.  The original byte pointer is unchanged.
  1343.  
  1344.  
  1345.  
  1346. 2.12.7. POINT - Construct a Byte Pointer
  1347.  
  1348. For convenience, the Macro assembler (and Fail) has a pseudo op for creating
  1349. byte pointers.  The POINT pseudo op has three parameters: size, address, and
  1350. position.  In the POINT pseudo op, the position argument specifies the bit
  1351. number of the right most bit in the byte.  If the position field is omitted,
  1352. bit number "-1" is assumed (this assembles 44 in the POS field) which doesn't
  1353. address any byte, but which, when incremented once, will address the first
  1354. byte in the specified word.
  1355.  
  1356.  
  1357.         POINT 7, 100(1)                 440701,,100
  1358.         POINT 36, @2000,35              004420,,2000
  1359.         POINT 7, FOO                    440700,,foo
  1360.  
  1361. Instruction Set                                                       Page 26
  1362.  
  1363. 2.13. Logical Testing and Modification
  1364.  
  1365. The TEST instructions are for testing and modifying bits in an accumulator.
  1366. There are 64 instructions.  Each mnemonic begins with a T and is followed by
  1367. three modifiers.
  1368.  
  1369.  
  1370. Test accumulator
  1371.  
  1372.  |R right half immediate
  1373.  |L left half immediate
  1374.  |D direct mask
  1375.  |S swapped mask
  1376.  
  1377.         |N no modification
  1378.         |Z zero selected bits
  1379.         |O set selected bits to One
  1380.         |C complement selected bits
  1381.  
  1382.                 |  never skip
  1383.                 |N skip unless all selected bits are zero
  1384.                 |E skip if all selected bits are zero
  1385.                 |A skip always
  1386.  
  1387. The test operation considers two 36 bit quantities.  One of these is the
  1388. contents of the selected AC.  The other quantity, called the mask, depends on
  1389. the first modifier letter.  For R the mask is <0,,E>; for L it is <E,,0>.  For
  1390. D the mask is C(E), and for S the mask is CS(E), the swapped contents of E.
  1391.  
  1392.    - If the skip condition N is specified, then the test instruction will
  1393.      skip if the AND of the mask and the AC operand is Not equal to zero.
  1394.  
  1395.    - If the skip condition E is specified, then the test instruction will
  1396.      skip if the AND of the mask and the AC operand is Equal to zero.
  1397.  
  1398.    - If the modification code Z appears then bits that are one in the
  1399.      mask are made zero in the AC.
  1400.  
  1401.    - If the modification code O appears then bits that are one in the
  1402.      mask are made one in the AC.
  1403.  
  1404.    - If the modification code C appears then bits that are one in the
  1405.      mask are complemented in the AC.
  1406.  
  1407. Note that the skip condition is determined on the basis of the contents of the
  1408. AC before it is modified.
  1409.  
  1410. The principle use for the Test instructions is in testing and modifying single
  1411. bit flags that are kept in an accumulator.
  1412.  
  1413.  
  1414.  
  1415. 2.14. Boolean Logic
  1416.  
  1417. There are 16 possible boolean functions of 2 variables.  The PDP-10 has 16
  1418. instruction classes (each with 4 modifiers) that perform these operations.
  1419. Each boolean function operates on the 36 bits of AC and memory as individual
  1420. bits.
  1421. Instruction Set                                                       Page 27
  1422.  
  1423.  
  1424. Table of the Boolean functions
  1425.  
  1426. C(AC)   0    0    1     1
  1427. C(E)    0    1    0     1
  1428.  
  1429. SETZ    0    0    0     0    SET to Zero
  1430. AND     0    0    0     1    AND
  1431. ANDCM   0    0    1     0    AND with Complement of Memory
  1432. SETA    0    0    1     1    SET to AC
  1433. ANDCA   0    1    0     0    AND with Complement of AC
  1434. SETM    0    1    0     1    SET to Memory
  1435. XOR     0    1    1     0    eXclusive OR
  1436. IOR     0    1    1     1    Inclusive OR
  1437. ANDCB   1    0    0     0    AND with Complements of Both
  1438. EQV     1    0    0     1    EQuiValence
  1439. SETCM   1    0    1     0    SET to Complement of Memory
  1440. ORCA    1    0    1     1    OR with Complement of Memory
  1441. SETCA   1    1    0     0    SET to Complement of AC
  1442. ORCA    1    1    0     1    OR with Complement of AC
  1443. ORCB    1    1    1     0    OR with Complements of Both
  1444. SETO    1    1    1     1    SET to One
  1445.  
  1446. Each of the 16 instructions above have four modifiers that specify where to
  1447. store the result.  No modifier means result to AC.  Modifier I means
  1448. Immediate: the memory data is <0,,E> and the result goes to AC.  M as a
  1449. modifier means result should be stored in memory.  B means store the results
  1450. in both memory and AC.
  1451.  
  1452.  
  1453.  
  1454. 2.15. PC Format
  1455.  
  1456. JSR, JSP, and PUSHJ all store a full word that contains the PC (Program
  1457. Counter) and various flags.
  1458.  
  1459. The format of a PC word is:
  1460.  
  1461.  
  1462.  0 0 0 0 0 0 0 0 0 0 1 1 1 11111 112222222222333333
  1463.  0 1 2 3 4 5 6 7 8 9 0 1 2 34567 890123456789012345
  1464.  __________________________________________________
  1465. |A|C|C|F|F|U|I|P|A|T|T|F|D|     |                  |
  1466. |R|R|R|O|P|S|O|U|F|R|R|X|C|00000|       PC         |
  1467. |O|Y|Y|V|D|E|T|B|I|A|A|U|K|     |                  |
  1468. |V|0|1| | |R| |L| |P|P| | |     |                  |
  1469. | | | | | | | | | |2|1| | |     |                  |
  1470. |_|_|_|_|_|_|_|_|_|_|_|_|_|_____|__________________|
  1471.  
  1472.  
  1473. AROV, ARithmetic OVerflow, is set by any of the following:
  1474.  
  1475.    - A single instruction has set one of CRY0 or CRY1 without setting
  1476.      them both.
  1477.  
  1478.    - An ASH or ASHC has left shifted a significant bit out of AC bit 1.
  1479.  
  1480.    - A MULx instruction has multiplied -2^35 by itself.
  1481. Instruction Set                                                       Page 28
  1482.  
  1483.    - A DMUL instruction has multiplied -2^70 by itself.
  1484.  
  1485.    - An IMULx instruction has produced a product less than -2^35 or
  1486.      greater than 2^35-1.
  1487.  
  1488.    - A FIX or FIXR has fetched an operand with exponent greater than 35.
  1489.  
  1490.    - FOV (Floating Overflow) has been set.
  1491.  
  1492.    - DCK (Divide ChecK) has been set.
  1493.  
  1494.    - CRY0, CaRrY 0, if set without CRY1 being set will set AROV.  This
  1495.      indicates any of the following conditions:
  1496.  
  1497.         1. An ADDx has added two negative numbers with sum less than
  1498.            -2^35.
  1499.  
  1500.         2. A SUBx has subtracted a positive number from a negative number
  1501.            and produced a result less than -2^35.
  1502.  
  1503.         3. A SOSx or SOJx has decremented -2^35.
  1504.  
  1505.    - If CRY0 and CRY1 are both set, this indicates that one of the
  1506.      following non-overflow events has occurred:
  1507.  
  1508.         1. In ADDx both summands were negative, or their signs differed
  1509.            and the postive one was greater than or equal to the magnitude
  1510.            of the negative summand.
  1511.  
  1512.         2. In SUBx the sign of both operands was the same and the AC
  1513.            operand was greater than or equal to the memory operand, or
  1514.            the AC operand was negative and the memory operand was
  1515.            positive.
  1516.  
  1517.         3. An AOJx or AOSx has incremented -1.
  1518.  
  1519.         4. SOJx or SOS has decremented a nonzero number other than -2^35.
  1520.  
  1521.         5. A MOVNx has negated zero.
  1522.  
  1523.    - CRY1, CaRrY 1, if set without CRY0 being set will set AROV.  This
  1524.      indicates any of the following conditions:
  1525.  
  1526.         1. An ADDx has added two positive number with a sum greater than
  1527.            2^35-1.
  1528.  
  1529.         2. A SUBx has subtracted a negative number from a positive number
  1530.            to form a difference greater than 2^35-1.
  1531.  
  1532.         3. An AOSx or AOJx instruction has incremented 2^35-1.
  1533.  
  1534.         4. A MOVNx or MOVMx has negated -2^35.
  1535.  
  1536.         5. A DMOVNx has negated -2^70
  1537.  
  1538. The following conditions are also indicated in the PC word:
  1539.  
  1540.    - FOV, Floating point OVerflow, is set by any of:
  1541. Instruction Set                                                       Page 29
  1542.  
  1543.         1. In a floating point instruction other than FLTR, DMOVNx, or
  1544.            DFN the exponent of the result exceeds 127.
  1545.  
  1546.         2. FXU (Floating eXponent Underflow) has been set.
  1547.  
  1548.         3. DCK ( Divide ChecK) has been set by FDVx, FDVRx, or DFDV.
  1549.  
  1550.    - FPD, First Part Done, is set when the processor responds to a
  1551.      priority interrupt, after having completed the first part of a two
  1552.      part instruction (e.g., ILDB).  This flag is not usually of interest
  1553.      to the programmer.
  1554.  
  1555.    - USER is set while the processor is in user mode.  In user mode,
  1556.      various instruction and addressing restrictions are in effect.
  1557.  
  1558.    - IOT, User IN-Out mode, (also called IOT User), is a special mode in
  1559.      which some of the user mode instruction (but not addressing)
  1560.      restrictions are removed.  In this mode a user program may perform
  1561.      the hardware I/O instructions.
  1562.  
  1563.    - PUBL, Public mode, signifies that the processor is in user public
  1564.      mode or in exec supervisor mode [KI10, KL10 only].
  1565.  
  1566.    - AFI, Address Failure Inhibit, if this flag is set, address break is
  1567.      inhibited for during the execution of the next instruction [KI10,
  1568.      KL10 only].
  1569.  
  1570.    - TRAP2 - if bit 10 is not also set, pushdown overflow has occurred.
  1571.      If traps are enabled, setting this flag immediately causes a trap.
  1572.      At present no hardware condition sets both TRAP1 and TRAP2
  1573.      simultaneously.  [KI10 KL10 only]
  1574.  
  1575.    - TRAP1 - if bit 9 is not also set, arithemetic overflow has occurred.
  1576.      If traps are enabled, setting this flag immediately causes a trap.
  1577.      At present no hardware condition sets both TRAP1 and TRAP2
  1578.      simultaneously.  [KI10 KL10 only]
  1579.  
  1580.    - FXU, Floating eXponent Underflow, is set to signify that in a
  1581.      floating instruction other than DMOVNx, FLTR, or DFN, the exponent
  1582.      of the result was less than -128 and AROV and FOV have been set.
  1583.  
  1584.    - DCK, Divide ChecK, signifies that one of the following conditions
  1585.      has set AROV:
  1586.  
  1587.         1. In a DIVx the high order word of the dividend was greater than
  1588.            or equal to the divisor.
  1589.  
  1590.         2. In an IDIVx the divisor was zero.
  1591.  
  1592.         3. In an FDVx, FDVRx, or DFDV, the divisor was zero, or the
  1593.            magnitude of the dividend fraction was greater than or equal
  1594.            to twice the magnitude of the divisor fraction.  In either
  1595.            case, FOV is also set.
  1596.  
  1597. Bits 13 through 17 of the PC word are always zero to facilitate the use of
  1598. indirect addressing to return from a subroutine.
  1599.  
  1600. Bits 18 through 35 store an address that is one greater than the address of
  1601. Instruction Set                                                       Page 30
  1602.  
  1603. the instruction that stores the PC.  Thus, the PC word points at the
  1604. instruction immediately following the subroutine call.
  1605.  
  1606.  
  1607.  
  1608. 2.16. Program Control
  1609.  
  1610.  
  1611.  
  1612. 2.16.1. JSR - Jump to Subroutine
  1613.  
  1614.     JSR      C(E):=<flags,,PC>; PC:=E+1
  1615.  
  1616. JSR, Jump to SubRoutine, stores the PC in the word addressed by the effective
  1617. address and jumps to the word following the word where the PC is stored.  This
  1618. is the only PDP-10 instruction that stores the PC and flags without modifying
  1619. any ACs; however, it is non-reentrant, so PUSHJ is favored in most cases.  The
  1620. usual return from a subroutine called by a JSR is via JRST (or JRST 2,)
  1621. indirect through the PC word.  (See JRST)
  1622.  
  1623.  
  1624.  
  1625. 2.16.2. JSP - Jump & Save PC
  1626.  
  1627.     JSP      C(AC):=<flags,,PC>; PC:=E
  1628.  
  1629. JSP, Jump and Save PC, stores the PC and flags in the selected accumulator and
  1630. jumps.
  1631.  
  1632.  
  1633.  
  1634. 2.16.3. JSA - Jump and Save Accumulator
  1635.  
  1636.     JSA      C(E):=C(AC); C(AC):=<E,,PC>; PC:=E+1
  1637.  
  1638. JSA, Jump and Save AC, stores the AC in word addressed by the effective
  1639. address.  Then the left half of the AC is set to the effective address and the
  1640. right half of AC is set to the return PC.  Then the PC is set to one greater
  1641. than the effective address.  The JRA instruction unwinds this call.  The
  1642. advantage of this call is that a routine may have multiple entry points (which
  1643. is difficult to do with JSR) and it's easy to find (and later to skip over)
  1644. arguments that follow the calling instruction (which is possible to do with
  1645. PUSHJ, but not quite so convenient).  Among the disadvantages of this call is
  1646. that it is not reentrant, and it doesn't save flags.
  1647.  
  1648.  
  1649.  
  1650. 2.16.4. JRA - Jump and Restore Accumulator
  1651.  
  1652.     JRA      C(AC):=C(CL(AC)); PC:=E
  1653.  
  1654. JRA, Jump and Restore AC, is the return from JSA.  If, e.g., a subrountine is
  1655. called with JSA AC, then the return is made by: JRA AC,(AC).
  1656. Instruction Set                                                       Page 31
  1657.  
  1658. 2.16.5. PUSHJ - Push on stack and Jump
  1659.  
  1660.  
  1661.     PUSHJ   C(AC):=C(AC)+<1,,1>; C(CR(AC)):=<flags,,PC>;
  1662.             PC:=E
  1663.  
  1664. PUSHJ (PUSH return address and Jump) is like PUSH except the data that is
  1665. pushed onto the top of the stack is the PC and flags word.  The PC that is
  1666. stored is the PC of the instruction that follows the PUSHJ.  Then the PC is
  1667. set to the effective address of the instruction.  Pushdown overflow results if
  1668. the AC becomes positive when it is incremented.
  1669.  
  1670.  
  1671.  
  1672. 2.16.6. POPJ - Pop stack and Jump
  1673.  
  1674.     POPJ     PC:=CR(CR(AC)); C(AC):=C(AC)-<1,,1>
  1675.  
  1676. POPJ (POP return address and Jump) undoes PUSHJ.  The right half of the word
  1677. at the top of the stack is loaded into the PC (the flags are unchanged).  Then
  1678. the stack pointer is decremented as in POP.  The effective address of POPJ is
  1679. ignored.  Pushdown overflow obtains if the AC becomes negative as a result of
  1680. the subtraction.
  1681.  
  1682.  
  1683.  
  1684. 2.16.7. Programming Hints Using PUSHJ and POPJ
  1685.  
  1686. If a subroutine called by PUSHJ AC, wants to skip over the instruction
  1687. following the PUSHJ, the following sequence accomplishes that result:
  1688.  
  1689.  
  1690.         aos (ac)                ; AC better be nonzero.
  1691.         popj ac,
  1692.  
  1693.  
  1694. If you must restore the flags that PUSHJ saved, the following sequence should
  1695. be used instead of POPJ:
  1696.  
  1697.  
  1698.         pop ac, (ac)            ; Adjust the stack
  1699.         jrst 2,                 ; Restore flags and PC from
  1700.                                 ;  old stack top.
  1701.  
  1702.  
  1703.  
  1704.  
  1705. 2.16.8. JRST - Jump and Restore
  1706.  
  1707. JRST, Jump and ReSTore, is an unconditional jump instruction.  In JRST, the AC
  1708. field does not address an accumulator.  Instead, the AC is decoded to signify
  1709. various things.
  1710.  
  1711.  
  1712. JRST            PC:=E
  1713. JRST 2,         PC:=E; flags are restored (see text)
  1714. JRST 10,        PC:=E; Dismiss current priority interrupt
  1715. JRST 12,        PC:=E; restore flags and dismiss priority
  1716.                   interrupt
  1717. Instruction Set                                                       Page 32
  1718.  
  1719. If the AC field is zero, only a jump occurs.  JRST is everyone's favorite
  1720. unconditional jump instruction (the only other one is JUMPA which is more
  1721. typing, also, on older machines JUMPA was slower than JRST).
  1722.  
  1723. JRST 2, (i.e., JRST with AC field set to 2) signifies jump and restore flags.
  1724. (The assembler also recognizes the mnemonic JRSTF for JRST 2,).  If
  1725. indirection is used in JRSTF, then the flags are restored from the last word
  1726. fetched in the address calculation.  If indexing is used with no indirection,
  1727. the flags are restored from the left half of the specified index register.  If
  1728. neither indexing nor indirection is used in the address calculation the flags
  1729. are restored from the left half of the JRSTF itself!  In a user mode program
  1730. JRSTF cannot clear USER nor can it set IOT User (it can however, clear IOT
  1731. User).  JRST 4, JRST 10, and JRST 12 are illegal in user mode and are trapped
  1732. as UUOs.
  1733.  
  1734.  
  1735.  
  1736. 2.16.9. JFCL - Jump on Flag and Clear
  1737.  
  1738. The JFCL instruction is another case in which the AC field is decoded to
  1739. modify the instruction.  The AC field selects the four flags in PC bits 0
  1740. through 3.  PC bits 0 to 3 correspond to bits 9 to 12 in the JFCL instruction.
  1741. JFCL will jump if any flag selected by the AC field is a 1.  All flags
  1742. selected by the AC field are set to zero.
  1743.  
  1744. JFCL 0,         since it selects no PC bits, is a no-op.
  1745.  
  1746. JFCL 17,        will clear all flags, and will jump if any of AROV, CRY0,
  1747.                 CRY1, or FOV are set.
  1748.  
  1749. JFCL 1,         (JFOV) jumps if FOV is set and clears FOV.
  1750.  
  1751. JFCL 10,        (JOV) jumps if AROV is set and clears AROV.
  1752.  
  1753.  
  1754.  
  1755. 2.16.10. XCT - Execute
  1756.  
  1757. XCT, the eXeCuTe instruction, fetches the word addressed by the effective
  1758. address and executes that word as an instruction.  In the case of XCTing an
  1759. instruction that stores a PC, the PC that is stored is the address of the
  1760. instruction that follows the XCT.  If the executed instruction skips, then
  1761. that skip is relative to the XCT.  The AC field of the XCT should be zero.
  1762. [In monitor mode a nonzero AC field in an XCT is significant.]
  1763.  
  1764. The XCT instruction can be used to acheive the effect of a CASE statement, as
  1765. in the following example:
  1766.  
  1767.  
  1768.         xct @[  call foo
  1769.                 move q1, p1
  1770.                 jfcl
  1771.                 aos q1 ](t1)
  1772.  
  1773.  
  1774. where t1 contains the case index, which should have a value (in this case)
  1775. between 0 and 3.
  1776. Instruction Set                                                       Page 33
  1777.  
  1778. 2.16.11. JFFO - Jump if Find First One
  1779.  
  1780. JFFO tests the selected AC.  If C(AC)=0 then set C(AC+1) to zero and execute
  1781. the next instruction.  If C(AC)<>0 then set C(AC+1) to the count of the number
  1782. of zero bits in C(AC) to the left of the first one bit and jump to the
  1783. effective address.  C(AC) is unchanged.
  1784.  
  1785.  
  1786.  
  1787. 2.17. References
  1788.  
  1789. The following manual presents the instruction set of the PDP-10/DECSYSTEM-20
  1790. in complete detail:
  1791.  
  1792.        DECsystem-10/DECSYSTEM-20 Hardware Reference Manual, Volume I,
  1793.     Central Processor, EK-10/20-HR-001, Digital Equipment Corporation
  1794.     (1978).
  1795.  
  1796. Historical information can be found in:
  1797.  
  1798.        Bell, et al., "The Evolution of the DECsystem-10", CACM Jan 1978.
  1799. Macro                                                                 Page 34
  1800.  
  1801.                      3. The DECSYSTEM-20 Macro Assembler
  1802.  
  1803.  
  1804.  
  1805. 3.1. Introduction
  1806.  
  1807.        This chapter presents excerpts from the DEC Macro-20 Reference
  1808.     Manual.  Certain advanced (or rarely used) features - mainly those
  1809.     dealing with storage allocation and polish fixups - have been omitted;
  1810.     see the actual manual if you must have them.  Unfortunately, the Macro
  1811.     manual does not present the material in a tutorial fashion; this
  1812.     rendition of it is not much better than the original in that respect,
  1813.     although examples have been added here and there, and explanations are
  1814.     a little more thorough.  Given the absence of a good tutorial, the
  1815.     best approach to teaching yourself Macro is to read through this
  1816.     chapter from beginning to end to get an idea of what kinds of things
  1817.     Macro does, and what its syntax is, and then to study some
  1818.     well-written Macro programs.
  1819.  
  1820.        At the time of this writing (3 July 1980), Macro suffers from
  1821.     certain limitations traceable to its origins in Tops-10 (PDP-6,
  1822.     really): symbols are limited to 6 characters in length, and input
  1823.     (.MAC) and output (.REL, usually) files are limited to 6 characters in
  1824.     the filename and 3 in the extension (file type).
  1825.  
  1826. Macro is the symbolic assembler program for the DECSYSTEM-20.  The assembler
  1827. reads a file of Macro statements and composes relocatable binary machine
  1828. instruction code suitable for loading by Link, the system's linking loader.
  1829.  
  1830. Macro is a statement-oriented language; statements are in free format and are
  1831. processed in two passes.  In processing statements, the assembler:
  1832.  
  1833.    1. Interprets machine instruction mnemonics.
  1834.  
  1835.    2. Accepts symbol definitions.
  1836.  
  1837.    3. Interprets symbols.
  1838.  
  1839.    4. Interprets pseudo-ops.
  1840.  
  1841.    5. Accepts macro definitions.
  1842.  
  1843.    6. Expands macros on call.
  1844.  
  1845.    7. Assigns memory addresses.
  1846.  
  1847.    8. Generates a relocatable binary program file ( .REL file) for input
  1848.       to Link.
  1849.  
  1850.    9. Optionally generates a program listing file showing source
  1851.       statements, the corresponding binary code, and any errors found.
  1852.  
  1853.   10. Optionally generates a universal ( .UNV) file that can be searched
  1854.       during other assemblies.
  1855.  
  1856. The following conventions are used throughout this chapter:
  1857.  
  1858.    1. All numbers in the examples are octal unless otherwise noted.
  1859. Macro                                                                 Page 35
  1860.  
  1861.    2. All numbers in the text are decimal unless otherwise noted.
  1862.  
  1863.    3. The name of the assembler, Macro, is capitalized; references to
  1864.       user-defined macros are in lower case.
  1865.  
  1866.  
  1867.  
  1868. 3.2. Elements of Macro
  1869.  
  1870. The character set recognized in Macro statements includes all ASCII
  1871. alphanumeric characters and 28 special characters (ASCII 40 through 137
  1872. (octal)).  Lowercase letters are not distinguished from uppercase letters.
  1873.  
  1874. Macro recognizes several ASCII control codes including horizontal tab (^I),
  1875. linefeed (^J), formfeed (^L), carriage-return (^M), and control-underscore
  1876. (^_).  Macro accepts any ASCII character in quoted text, or in text argument
  1877. to the ASCII and ASCIZ pseudo-ops.  The line continuation character, ^_, is
  1878. always effective.  Delimiters for certain pseudo-ops (such as ASCII, ASCIZ,
  1879. and COMMENT) can be any nonblank, nontab ASCII character.
  1880.  
  1881. A Macro program consists of statements made up of Macro language elements.
  1882. Separated into general types, these are:
  1883.  
  1884.    1. Special characters.
  1885.  
  1886.    2. Numbers.
  1887.  
  1888.    3. Literals.
  1889.  
  1890.    4. Symbols.
  1891.  
  1892.    5. Expressions.
  1893.  
  1894.    6. Macro-defined mnemonics.
  1895.  
  1896.    7. Pseudo-ops.
  1897.  
  1898.    8. Macros.
  1899.  
  1900. The format of a Macro statement is discussed later.
  1901.  
  1902.  
  1903.  
  1904. 3.2.1. Special Characters
  1905.  
  1906. Some characters and combinations of characters have special interpretations.
  1907. These interpretations apply only in the contexts described.  In particular,
  1908. they do not apply within comment fields or text strings.  Uparrow (^) is to be
  1909. taken literally, e.g. ^B means the uparrow character followed by a B, not
  1910. control-B.
  1911.  
  1912. Char(s) (Form)  Context and Interpretation
  1913.  
  1914. B (mBn)         Between 2 integer expressions, causes the binary
  1915.                 representation of m to be placed with rightmost bit at bit n
  1916.                 (decimal).
  1917.  
  1918. ^B (^Bn)        Before an integer expression, shows that n is a binary
  1919. Macro                                                                 Page 36
  1920.  
  1921.                 (base 2) number.
  1922.  
  1923. ^D (^Dn)        Before an integer expression, shows that n is a decimal
  1924.                 number.
  1925.  
  1926. E (fE+n,fE-n,fEn) Between a floating-point decimal number and a signed decimal
  1927.                 integer, multiplies f by the +nth power of 10 (decimal).
  1928.  
  1929. ^O (^On)        Before an integer expression, shows that n is an octal number.
  1930.  
  1931. : (sym:)        After a symbol, shows that sym is a label, i.e. that its value
  1932.                 is to become the current value of the location counter.
  1933.  
  1934. :: (sym::)      After a symbol, shows that sym is a global INTERNAL label.
  1935.  
  1936. ; (;text)       Before the end of a line, shows that text is a comment.
  1937.  
  1938. ;; (;;text)     Before end of line (usually in a macro definition), shows that
  1939.                 text is a comment to be printed in the macro definition but
  1940.                 not at call, i.e. in macro expansion.
  1941.  
  1942. . (.)           As an expression, is replaced by the current value of the
  1943.                 location counter.
  1944.  
  1945. , (,)           Among numbers and symbols, delimits operands, accumulator,
  1946.                 arguments.  In a macro call, delimits a null argument.
  1947.  
  1948. ,, (lhw,,rhw)   Between two expressions, delimits left halfword from right
  1949.                 halfword.
  1950.  
  1951. ! (A!B)         Between two expressions, generates the logical inclusive OR of
  1952.                 A and B.
  1953.  
  1954. ^! (A^!B)       Between two expressions, generates the logical exclusive OR of
  1955.                 A and B.
  1956.  
  1957. & (A&B)         Between two expressions, generates the logical AND of A and
  1958.                 B.
  1959.  
  1960. ^- (^-A)        Before an expression, generates the logical complement of A
  1961.                 (NOT A).
  1962.  
  1963. * (A*B)         Between two expressions, generates the product of A and B.
  1964.  
  1965. / (A/B)         Between two expressions, generates the quotient of A by B.
  1966.  
  1967. + (A+B)         Between two expressions, generates the sum of A and B.
  1968.  
  1969. - (A-B)         Between two expressions, generates the difference of A and B.
  1970.  
  1971. - (-A)          Before an expression, generates the two's complement of the
  1972.                 value of A.
  1973.  
  1974. " ("text")      In pairs around text, shows that text is a 7-bit ASCII string,
  1975.                 to be right justified in a field of five characters.
  1976.  
  1977. ' ('text')      In pairs around text, shows that text is a SIXBIT string, to
  1978.                 be right justified in a field of six characters.
  1979. Macro                                                                 Page 37
  1980.  
  1981. ' (arg'text, text'arg) Adjoing a dummy argument in the body of a macro
  1982.                 definition, concatenates the value of the argument to the text
  1983.                 during macro expansion.
  1984.  
  1985. \ (\expr)       Prefixed to an expression in a macro call, directs that the
  1986.                 argument passed be the string for the ASCII value of expr in
  1987.                 the current radix.
  1988.  
  1989. \' (\'expr)     Prefixed to an expression in a macro call, directs that the
  1990.                 argument passed be the string whose SIXBIT code is the value
  1991.                 of expr.
  1992.  
  1993. \" (\"expr)     Prefixed to an expression in a macro call, directs that the
  1994.                 argument passed be the string whose ASCII code is the value of
  1995.                 expr.
  1996.  
  1997. ^_              (Control-underscore, not uparrow underscore) before a CRLF,
  1998.                 continues its argument to the next line.  Does not operate
  1999.                 across end-of-macro.
  2000.  
  2001. _ (A_B)         Between two expressions, shifts the binary representation of A
  2002.                 to the left B positions (if B is negative, shift is to the
  2003.                 right).
  2004.  
  2005. @ (@address)    Prefixed to an address, sets bit 13 of the instruction word,
  2006.                 indicating indirect addressing.
  2007.  
  2008. % (%arg)        As the first character of a dummy argument in a macro
  2009.                 definition, directs that %arg be replaced by a created symbol
  2010.                 during macro expansion; Macro will substitute a different
  2011.                 symbol for it on each invocation of the macro.
  2012.  
  2013. ()              Encloses index field, encloses dummy arguments in macro
  2014.                 definition or parameters in a macro invocation, quotes
  2015.                 characters for macro argument handling, swaps the two halves
  2016.                 of a value.
  2017.  
  2018. <>              Nests expressions, encloses conditional assembly code,
  2019.                 encloses code in REPEAT, IRP, and IRPC pseudo-ops, encloses
  2020.                 macro body in DEFINE pseudo-op, quotes characters for macro
  2021.                 argument handling, forces evaluation of a symbol.
  2022.  
  2023. []              delimits literals (causing the contents of the brackets to be
  2024.                 moved to the literal pool, and the bracketed expression to be
  2025.                 replaced by the location of its contents); delimits argument
  2026.                 in ARRAY, .COMMON, and OPDEF pseudo-ops; quotes characters for
  2027.                 macro argument handling.
  2028.  
  2029. = (sym=expr)    Between symbol and expression, assigns the value of expr to
  2030.                 sym.
  2031.  
  2032. =: (sym=:)      Between symbol and expression, assigns the value of expr to
  2033.                 sym and declares sym to be global INTERNAL.
  2034. Macro                                                                 Page 38
  2035.  
  2036. 3.2.2. Numbers
  2037.  
  2038. The two properties of numbers that are important in Macro are
  2039.  
  2040.    1. The radix (base) in which the number is written.
  2041.  
  2042.    2. How the number should be placed in memory.
  2043.  
  2044. You can control the interpretation of these properties by using pseudo-ops or
  2045. special characters to indicate your choices.
  2046.  
  2047.  
  2048.  
  2049. 3.2.2.1. Integers
  2050.  
  2051. Macro stores an integer in its binary form, right justified in bits 1 to 35 of
  2052. its storage word.  If you use a sign, place it immediately before the integer
  2053. (if you omit the sign, the integer is assumed to be positive).  For a negative
  2054. number, Macro first forms its absolute value in bits 1 to 35, then replaces it
  2055. by its two's complement.  Therefore a positive integer is stored with 0 in bit
  2056. 0, while a negative integer has 1 in bit 0.
  2057.  
  2058. The largest positive integer that Macro can store is 377777 777777 (octal);
  2059. the smallest (most negative) is 400000 000000 (octal).
  2060.  
  2061.  
  2062.  
  2063. 3.2.2.2. Radix
  2064.  
  2065. The initial implicit radix for a Macro program is octal (base 8).  The
  2066. integers you use in your program will be interpreted as octal unless you
  2067. indicate otherwise.  You can change the radix to any base from 2 to 10 by
  2068. using the RADIX pseudo-op.  The new radix will be in effect until you change
  2069. it again.
  2070.  
  2071. Without changing the prevailing radix, you can write a particular integer in
  2072. binary, octal, or decimal.  To do this, prefix the integer with ^B for binary,
  2073. ^O for octal, ^D for decimal.  The indicated radix applies only to the single
  2074. integer immediately following it.
  2075.  
  2076. A single-digit number is always interpreted as radix 10.  Thus 9 is seen as
  2077. decimal 9, even if the current radix is 8.
  2078.  
  2079. For example, suppose the current radix is 8.  Then you can write the decimal
  2080. number 23 as:
  2081.  
  2082. 27              octal (current radix)
  2083.  
  2084. ^d23            decimal
  2085.  
  2086. ^b10111         binary
  2087.  
  2088. but you cannot write decimal 23 as ^d45-22 since the ^d applies only to the
  2089. first number, 45; the 22 is still interpreted as octal.  However, you can
  2090. write decimal 23 as ^d<45-22>.
  2091. Macro                                                                 Page 39
  2092.  
  2093. 3.2.2.3. Floating-point Decimal Numbers
  2094.  
  2095. In your program, a floating-point decimal number is a string of digits with a
  2096. leading, trailing, or embedded decimal point and an optional leading sign.
  2097. Macro recognizes this as a mixed number in radix 10.
  2098.  
  2099. Macro forms a floating-point decimal number with the sign in bit 0, a binary
  2100. exponent in bits 1 to 8, and a normalized binary fraction in bits 9 to 35.
  2101.  
  2102. The normalized fraction can be viewed as followed: its numerator is the binary
  2103. number in bits 9 to 35, whose value is less than 2 to the 28th power, but
  2104. greater than or equal to 2 to the 27th power.  Its denominator is 2 to the
  2105. 28th power, so that the value of the fraction is always less than 1, but
  2106. greater than or equal to 0.  (This value is 0 only if the entire stored number
  2107. is 0.)
  2108.  
  2109. The binary exponent is incremented by 128 so that exponents from -128 to 127
  2110. are represented as 0 to 255.
  2111.  
  2112. For a negative floating-point number, Macro first forms its absolute value as
  2113. a positive number, then takes the two's complement for the entire word.
  2114.  
  2115. Examples:
  2116.  
  2117. The floating point number 17.0 generates the binary word
  2118.  
  2119.     0  10 000 101  100 010 000 000 000 000 000 000 000
  2120.  
  2121. where bit 0 shows the positive sign, bits 1 to 8 show the binary exponent, and
  2122. bits 9 to 35 show the proper binary fraction.  The binary exponent is 133
  2123. (decimal), which after subtracting the added 128 gives 5.  The fraction is
  2124. equal to 0.53125 decimal.  And 0.53125 times 2 to the 5th power is 17, which
  2125. is the number given.
  2126.  
  2127. Similarly, 153. generates
  2128.  
  2129.     0  10 001 000  100 110 010 000 000 000 000 000 000
  2130.  
  2131. while -153. generates
  2132.  
  2133.     1  01 110 111  011 001 110 000 000 000 000 000 000
  2134.  
  2135. These two examples show that a negative number is two's complemented.  Notice
  2136. that since the binary fraction for a negative number always has some nonzero
  2137. bits, the exponent field (taken by itself) appears to be one's complemented.
  2138.  
  2139. As in Fortran, you can write a floating point decimal number with a suffixed
  2140. E+/-n, and the number will be multiplied by 10 to the +/-nth power.  If the
  2141. sign is missing, n is assumed to be positive.  Examples: 2840000. can be
  2142. written 284.E+4 or .284E7; .0000284 can be written .284E-4 or 284.E-7.
  2143.  
  2144. Using this E notation with an integer (no decimal point) is not allowed, and
  2145. causes an error.  Therefore you can use 284.E4 but not 284E4.
  2146.  
  2147. Note:  Macro's algorithm for handling numbers given with the E notation is not
  2148. identical for Fortran's.  The binary values generated by the two translators
  2149. may differ in the lowest order bits.
  2150. Macro                                                                 Page 40
  2151.  
  2152. 3.2.2.4. Binary Shifting
  2153.  
  2154. Binary shifting of a number with Bn sets the location of the rightmost bit at
  2155. bit n in the storage word, where n is a decimal integer.  The shift takes
  2156. place after the binary number is formed.  Any bits shifted outside the range
  2157. (bits 0 through 35) of the storage word are lost.
  2158.  
  2159. For example, here are some numbers with their binary representations given in
  2160. octal:
  2161.  
  2162.  
  2163.   300000 000000    ^d3b2
  2164.  
  2165.   000000 042000    ^d17b25
  2166.  
  2167.   000001 000000    1b17
  2168.  
  2169.   777777 777777    -1b35
  2170.  
  2171.   000000 000001    1b35
  2172.  
  2173.   000000 777777    -1b17
  2174.  
  2175.  
  2176.  
  2177. 3.2.2.5. Underscore Shifting
  2178.  
  2179. You can also shift a number by using the underscore operator.  If V is an
  2180. expression with value n, suffixing _V to a number shifts it n bits to the
  2181. left.  If n is negative, the shift is to the right.
  2182.  
  2183. In an expression of the form W_V, W and V can be any expressions including
  2184. symbols.  The binary value of W is formed in a register, V is evaluated, and
  2185. the binary value of W is shifted V bits when placed in storage.
  2186.  
  2187. An expression such as -3.75E4_^d18 is legal, but the shift occurs after
  2188. conversion to floating point decimal storage format.  Therefore the sign,
  2189. exponent, and fraction fields are all shifted away from their usual locations.
  2190. This is true also of other storage formats.
  2191.  
  2192.  
  2193.  
  2194. 3.2.3. Literals
  2195.  
  2196. A literal is a character string within square brackets inserted in your source
  2197. code.  Macro stores the code generated by the enclosed string in a literal
  2198. pool beginning with the first available literal storage location, and places
  2199. the address of this location in place of the literal.  The literal pool is
  2200. normally at the end of the binary program.
  2201.  
  2202. The statements
  2203. Macro                                                                 Page 41
  2204.  
  2205.  
  2206.         ldb t1, [point 6, .JBVER, 17]
  2207.         LIT
  2208.  
  2209. are equivalent to
  2210.  
  2211.         ldb t1, foo
  2212. foo:    point 6, .JBVER, 17
  2213.  
  2214.  
  2215. A literal can also be used to generate a constant:
  2216.  
  2217.         push p, [0]             ; Generate a zero fullword.
  2218.  
  2219.         move q1, [3,,14]        ; Generate a word with 3 in
  2220.                                 ;  the left half and 14 in the right.
  2221.  
  2222.  
  2223. Multiline literals are also allowed:
  2224.  
  2225. getChr: ildb t2, t1             ; Get a character.
  2226.         cain t2, 0              ; Is it a null?
  2227.          jrst [ move t1, txtPtr ;  Yes, use this pointer
  2228.                 ildb t2, t1     ;   to get a new character.
  2229.                 cain t2, "?"    ;  Is it a question mark?
  2230.                  jrst [ move t1, txtPt2 ; Yes, use this pointer
  2231.                         ildb t2, t1 ; to get the message character,
  2232.                         jrst getHlp ] ; and go to the help routine.
  2233.                 ret ]           ;  Not a question mark, return from getChr.
  2234.         ret                     ; Not a null, return with char in t2.
  2235.  
  2236. The text of a literal continues until a matching closing square bracket is
  2237. found (unquoted and not in a comment field).
  2238.  
  2239. A literal can include any term, symbol, expression, or statement, but it must
  2240. generate at least one but no more than 99 words of data.  A statement that
  2241. does not generate data (such as a direct assignment statement or a RADIX
  2242. pseudo-op) can be included in a literal, but the literal must not consist
  2243. entirely of such statements.
  2244.  
  2245. You can nest literals up to 18 levels.  You can include any number of labels
  2246. in a literal, but a forward reference to a label in a literal is illegal.
  2247.  
  2248. If you use a dot (.) in a literal to retrieve the location counter, remember
  2249. that the location counter is pointing at the statement containing the literal,
  2250. not at the literal itself.  In nested literals, a dot location counter
  2251. references a statement outside the the outermost literal.  In the sequence
  2252.  
  2253.  
  2254.         jrst [  hrrz t1, v
  2255.                 caie t1, op
  2256.                  jrst .+1
  2257.                 jrst foo ]
  2258.         skipe t3
  2259.  
  2260.  
  2261. the expression .+1 generates the address of skipe t3, not jrst foo.
  2262. Macro                                                                 Page 42
  2263.  
  2264. Literals having the same value are collapsed in Macro's literal pool.  Thus
  2265. for the statements
  2266.  
  2267.  
  2268.         push p,[0]
  2269.         caml t2,[0]
  2270.          movei t1, [asciz /frotz/]
  2271.  
  2272.  
  2273. the same address is shared by the two literals [0], and by the null word
  2274. generated at the end of [asciz /frotz/].  Literal collapsing is suppressed for
  2275. those literals that contain errors, undefined expressions, or EXTERNAL
  2276. symbols.
  2277.  
  2278.  
  2279.  
  2280. 3.2.4. Symbols
  2281.  
  2282. Macro symbols include:
  2283.  
  2284.    1. Macro-defined pseudo-ops.
  2285.  
  2286.    2. Macro-defined mnemonics.
  2287.  
  2288.    3. User-defined macros.
  2289.  
  2290.    4. User-defined opdefs.
  2291.  
  2292.    5. User-defined labels.
  2293.  
  2294.    6. Direct-assignment symbols.
  2295.  
  2296.    7. Dummy arguments for macros.
  2297.  
  2298. Macro stores symbols in three symbol tables: one for opcodes and pseudo-ops,
  2299. one for macros and opdefs, and one for user defined labels and
  2300. direct-assignment symbols.  An entry in one of these tables shows the symbol,
  2301. its type, and its value.
  2302.  
  2303. Symbols are helpful in your program because:
  2304.  
  2305.    1. Defining a symbol as a label gives a name to an address.  You can
  2306.       use the label in debugging or as a target for program control
  2307.       statements.
  2308.  
  2309.    2. In revising a program, you can change a value throughout your
  2310.       program by changing a single symbol definition.
  2311.  
  2312.    3. You can give names to values to make computations clearer.
  2313.  
  2314.    4. You can make values available to other programs.
  2315. Macro                                                                 Page 43
  2316.  
  2317. 3.2.4.1. Selecting Valid Symbols
  2318.  
  2319. Follow these rules in selecting symbols:
  2320.  
  2321.    1. Use only letters, numerals, dots (.), dollar signs ($), and percent
  2322.       signs (%).  Macro will consider any other character (including
  2323.       blank) as a delimiter.
  2324.  
  2325.    2. Do not begin a symbol with a numeral.
  2326.  
  2327.    3. If you use a dot for the first character, do not use a numeral for
  2328.       the second.  Do not use dots for the first two characters; doing so
  2329.       can interfere with Macro's created symbols.
  2330.  
  2331.    4. Make the first six characters unique among your symbols.  You can
  2332.       use more than six characters, but Macro will use only the first
  2333.       six.
  2334.  
  2335.    5. Don't choose symbols composed of 1 to 4 letters followed by a
  2336.       percent sign; names of this form are reserved for new monitor
  2337.       calls.
  2338.  
  2339. Examples:
  2340.  
  2341. velocity        Legal, only "veloci" is heeded by Macro.
  2342.  
  2343. chg.vel         Legal, only "chg.ve" is heeded by Macro.
  2344.  
  2345. chg vel         Illegal, looks like two symbols to Macro.
  2346.  
  2347. chgVel          Legal.
  2348.  
  2349. 1stNum          Illegal, begins with numeral.
  2350.  
  2351. .11111          Illegal, begins with dot-numeral.
  2352.  
  2353. ..1111          Unwise, could interfere with created symbols.
  2354.  
  2355.  
  2356.  
  2357. 3.2.4.2. Defining Symbols
  2358.  
  2359. You can define a symbol by making it a label or by giving its value in a
  2360. direct-assignment statement.  Labels cannot be redefined, but
  2361. direct-assignment symbols can be redefined anywhere in your program.
  2362.  
  2363. You can also define special-purpose symbols called OPDEFs and macros using the
  2364. pseudo-ops OPDEF and DEFINE.
  2365.  
  2366. A label is always a symbol with a suffixed colon.  A label is in the first
  2367. (leftmost) field of a Macro statement and is one of the forms:
  2368.  
  2369. errFound:       Macro uses only "errfou".
  2370.  
  2371. case1:          Legal label.
  2372.  
  2373. OK:contin:      Legal; you can use more than one label at a location.
  2374. Macro                                                                 Page 44
  2375.  
  2376. case2::         Double colon declares the label to be global INTERNAL.
  2377.  
  2378. When Macro processes the label, the symbol and the current value of the
  2379. location counter are entered in the user symbol table.  A reference to the
  2380. symbol addresses the code at the label.
  2381.  
  2382. You cannot redefine a label to have a value different from its original value.
  2383. A label is relocatable if the address is represents is relocatable; otherwise
  2384. it is absolute.
  2385.  
  2386. You can define a direct-assignment symbol by associating it with an
  2387. expression.  A direct assignment is in one of the forms:
  2388.  
  2389. symbol=expression - The symbol and the value of the expression are entered
  2390.                 together in the user symbol table.
  2391.  
  2392. symbol=:expression - The symbol and the value of the expression are entered
  2393.                 together in the user symbol table and the symbol is declared
  2394.                 INTERNAL.
  2395.  
  2396. You can redefine a direct-assignment symbol at any time; the new direct
  2397. assignment simply replaces the old definition.
  2398.  
  2399. Note:
  2400.  
  2401.        If you assign a multiword value using direct assignment, only the
  2402.     first word of the value is assigned to the symbol.  For example,
  2403.     A=asciz/abcdefgh/ is equivalent to A=asciz/abcde/, since only the
  2404.     first five characters in the string correspond to code in the first
  2405.     word.
  2406.  
  2407.  
  2408.  
  2409. 3.2.4.3. Symbol-table Search Order
  2410.  
  2411. When you use a symbol in your program, Macro looks it up in the symbol tables.
  2412. Normal Macro searches the macro table first, then the opcode table, and
  2413. finally the user symbol table.  However, if Macro has already found an
  2414. operator in the current statement and is expecting operands, then it searches
  2415. the user symbol table first.
  2416.  
  2417.  
  2418.  
  2419. 3.2.4.4. Symbol Attributes
  2420.  
  2421. Each symbol in your program has one of the following attributes:  local,
  2422. INTERNAL global, or EXTERNAL global.  This attribute is determined when the
  2423. symbol is defined.
  2424.  
  2425. A local symbol is defined for the use of the current program only.  You can
  2426. define the same symbol to have different values in separately assembled
  2427. programs.  A symbol is local unless you indicate otherwise.
  2428.  
  2429. A global symbol is defined in one program, but is also available for use in
  2430. other programs.  Its table entry is visible to all programs in which the
  2431. symbol is declared global.  A global symbol must be declared INTERNAL in the
  2432. progam where it is defined; it can be defined in only one program.  In other
  2433. programs sharing the global symbol, it must be declared EXTERNAL; it can be
  2434. Macro                                                                 Page 45
  2435.  
  2436. EXTERNAL in any number of programs.
  2437.  
  2438. To declare a symbol as INTERNAL global, you can:
  2439.  
  2440.    1. Use the INTERN pseudo-op, e.g. INTERN flag1
  2441.  
  2442.    2. Insert a colon after the "=" in a direct assignment statement, e.g.
  2443.       flag2=:200.
  2444.  
  2445.    3. Use an extra colon with a label, e.g. flag3::.
  2446.  
  2447.    4. For subroutine entry points, use the ENTRY pseudo-op, e.g.
  2448.       ENTRY foo.
  2449.  
  2450. To declare a symbol as an EXTERNAL global, you can use the EXTERN pseudo-op,
  2451. e.g. EXTERN flag4.
  2452.  
  2453.  
  2454.  
  2455. 3.2.5. Expressions
  2456.  
  2457. You can combine numbers and defined symbols with arithmetic and logical
  2458. operators to form expressions.  You can nest expressions by using angle
  2459. brackets.  Macro evaluates each expression (innermost nesting levels first),
  2460. and either resolves it to a fullword value, or generates a Polish expression
  2461. to pass to Link.
  2462.  
  2463.  
  2464.  
  2465. 3.2.5.1. Arithmetic Expressions
  2466.  
  2467. An arithmetic expression can include any number or defined symbol, and any of
  2468. the following operators +, -, *, /.  Examples (in which words, x, y, and z
  2469. have been defined elsewhere):
  2470.  
  2471.  
  2472.         movei t3, words/5
  2473.  
  2474.         addi q2, <x+y-z>
  2475.  
  2476.         addi q2, <<words/5>+1>*5
  2477.  
  2478.  
  2479.  
  2480.  
  2481. 3.2.5.2. Logical Expressions
  2482.  
  2483. A logical expression can include any number or defined symbol whose value is
  2484. absolute, and any of the operators &, !, ^!, ^-.  Each of the binary
  2485. operations &, !, and ^! generates a fullword by performing the indicated
  2486. operation over corresponding bits of the two operands.  For example, a&b
  2487. generates a fullword whose bit 0 is the result of a's bit 0 ANDed with b's bit
  2488. 0, and so forth for all 36 bits.
  2489. Macro                                                                 Page 46
  2490.  
  2491. 3.2.5.3. Evaluating Expressions
  2492.  
  2493. Macro has a hierarchy of operations in evaluating expressions.  In an
  2494. expression without nests (angle brackets), Macro performs its operations in
  2495. this effective order:
  2496.  
  2497.    1. All unary operations and shifts: +, -, ^-, ^d, ^o, ^b, b (binary
  2498.       shift), _ (underscore shift), E.
  2499.  
  2500.    2. Logical binary operations (from left to right): !, ^!, &.
  2501.  
  2502.    3. Multiplication and division (from left to right): *, /.
  2503.  
  2504.    4. Addition and subtraction (binary operations): +, -.
  2505.  
  2506. You can override this hierarchy by using angle brackets to show what you want
  2507. done first.  For example, suppose you want to calculate the sum of a and b,
  2508. divided by c. You cannot do this with a+b/c because Macro will perform the
  2509. division b/c first, then add the result to a. With angle brackets you can
  2510. write the expresssion <a+b>/c to force Macro to add a and b first, then divide
  2511. the result by c.
  2512.  
  2513. Expressions can be nested to any level.  The innermost nest is evaluated
  2514. first; the outermost last.  Some examples of legal expressions (assuming that
  2515. a1, b1, and c are defined symbols) are:
  2516.  
  2517.  
  2518.         a1+b1/5
  2519.         <a1+b1>/5
  2520.         ^-a1&b1^!c
  2521.         ^b101b17-^d98+6
  2522.  
  2523. An expression given in halfword notation <lefthalf,,righthalf> has each half
  2524. evaluated separately in a 36-bit register.  Then the 18 low-order bits of each
  2525. half are joined to form a fullword.  For example, the expression <4,,6>/2
  2526. generates the value 000002 000003.
  2527. Macro                                                                 Page 47
  2528.  
  2529. 3.3. Pseudo-ops
  2530.  
  2531. A pseudo-op is a statement that gives the assembler information to allow it to
  2532. assemble your program in the desired way.  For example, the pseudo-op RADIX
  2533. does not generate code itself, but tells Macro how to interpret numbers in
  2534. your program.  The pseudo-op EXP generates one word of code for each argument
  2535. given with it.
  2536.  
  2537. To use a pseudo-op in your program, follow it with a space or tab, and any
  2538. required or optional arguments or parameters.
  2539.  
  2540. This section describes the use and functions of each pseudo-op.  The headings
  2541. for each description, if applicable, are Format, Function, Examples, and
  2542. Optional Notations.
  2543.  
  2544.  
  2545.  
  2546. 3.3.1. ARRAY
  2547.  
  2548. Format          ARRAY sym[expression]
  2549.  
  2550.                 Expression is an integer value (to be intterpreted in the
  2551.                 current radix, indicating the number of words to be allocated;
  2552.                 the expression cannot be EXTERNAL, relocatable, or negative.
  2553.                 Note that although the expression must be in square brackets,
  2554.                 this use of the brackets is completely unrelated to literals.
  2555.  
  2556. Function        Reserves a block of storage whose length is the value of the
  2557.                 expression, and whose location is identified by the symbol.
  2558.                 Storage is allocated along with other variable symbols in the
  2559.                 program, usually at the end.  The allocated storage is not
  2560.                 necessarily zeroed.
  2561.  
  2562.  
  2563.  
  2564. 3.3.2. ASCII
  2565.  
  2566. Format          ASCII dtextd
  2567.  
  2568.                 where d = delimiter; first nonblank character, whose second
  2569.                 appearance terminates the text, and text = a string of text
  2570.                 characters to be entered.
  2571.  
  2572. Function        Enters ASCII text in the binary code.  Each character uses
  2573.                 seven bits.  Characters are left justified in storage, five
  2574.                 per word, with bit 35 in each word set to 0, and any unused
  2575.                 bits in the last word set to 0.
  2576.  
  2577. Examples
  2578.  
  2579.                 ASCII /This is a string/
  2580.                 ascii   !ps:<frotz>foo.txt!
  2581.                 Ascii?foo?
  2582.  
  2583. Optional Notations:  Omit the space or tab after ASCII.  Not allowed if the
  2584.                 delimiter is a letter, number, dot, dollar or percent sign
  2585.                 (i.e.  a possible symbol constituent), or if the delimiter
  2586.                 character is a control character.
  2587. Macro                                                                 Page 48
  2588.  
  2589.  
  2590.                 Right-justified ASCII can be entered by using double quotes to
  2591.                 surround up to five characters, as in: movei t1, "A".
  2592.  
  2593.  
  2594.  
  2595. 3.3.3. ASCIZ
  2596.  
  2597. Exactly like ASCII, except that a trailing null is guaranteed, even if an
  2598. extra word of nulls must be added.  Most Tops-20 monitor calls expect strings
  2599. to be in this format.
  2600.  
  2601.  
  2602.  
  2603. 3.3.4. BLOCK
  2604.  
  2605. Format          BLOCK expression
  2606.  
  2607.                 where the expression is not EXTERNAL or relocatable, and
  2608.                 evaluates to a positive integer.
  2609.  
  2610. Function        Reserves, at the point of invocation, a block of locations
  2611.                 whose length is the value of the expression.  The location
  2612.                 counter is incremented by this value.  The allocated locations
  2613.                 are not necessarily zeroed.  Note that the BLOCK pseudo-op
  2614.                 does not generate or store code; therefore it should not be
  2615.                 used in a literal, since this will result in overwriting the
  2616.                 reserved space during literal pooling.
  2617.  
  2618. Examples
  2619.  
  2620.                 BLOCK 500
  2621.                 block <^d512/5+1>
  2622.                 block <$nPag_9 - fooLen>
  2623.  
  2624. Optional Notations:  Use the pseudo-op Z inside literals.
  2625.  
  2626.  
  2627.  
  2628. 3.3.5. BYTE
  2629.  
  2630. Format          BYTE bytedef ... bytedef
  2631.  
  2632.                 bytedef = (n)expression, ..., expression
  2633.  
  2634.                 n = byte size in bits; n is a decimal expression in the range
  2635.                 1 to 36.
  2636.  
  2637. Function        Stores values of expressions in n-bit bytes, starting at bit 0
  2638.                 of the storage word.  The first value is stored in bits 0 to
  2639.                 n-1; the second in bits n to 2n-1, and so forth for each given
  2640.                 value.  If a byte will not fit in the remaining bits of a
  2641.                 word, those bits are zeroed and the byte begins in bit 0 of
  2642.                 the next word.  If a value is too large for a byte, it is
  2643.                 truncated on the left.  If the byte size is 0 or is missing
  2644.                 (empty parentheses), a zero word is generated.
  2645.  
  2646. Examples
  2647. Macro                                                                 Page 49
  2648.  
  2649.                 V=2
  2650.                 BYTE (6),5,0,,101,5,V
  2651.  
  2652.  
  2653.                 generates the storage value 050000 010502.  The two commas
  2654.                 indicate a null argument; the 101 (octal) is too large for the
  2655.                 byte size and is left truncated.
  2656.  
  2657.  
  2658.                 byte (6)7,0,1(9)7,0,1,"A"
  2659.  
  2660.  
  2661.                 generates two words: 070001 007000 and 001101 000000.  Notice
  2662.                 that "A" is right-justified in its 9-bit byte.
  2663.  
  2664.                 Note that a comma before a left parenthesis will generate a
  2665.                 null byte.
  2666.  
  2667.  
  2668.  
  2669. 3.3.6. COMMENT
  2670.  
  2671. Format          COMMENT dtextd
  2672.  
  2673.                 d = delimiter; the first nonblank character, whose second
  2674.                 appearance terminates the text.
  2675.  
  2676. Function        Treats the text between the delimiters as a comment.  The text
  2677.                 can include carriage returns to facilitate multiline comments.
  2678.  
  2679. Optional Notations:  Omit the space or tab after COMMENT.  This is not allowed
  2680.                 if the delimiter is a valid character for identifiers, or is a
  2681.                 control character.  Use a semicolon (;) to make the rest of
  2682.                 the line into a comment.  Be careful not to use the delimiter
  2683.                 in the text of the comment, and avoid the use of nonprinting
  2684.                 delimiters.
  2685.  
  2686. Example :
  2687.  
  2688.  
  2689.         foo:    comment | Subroutine Foo
  2690.  
  2691.         This subroutine writes a poem in the style of a given poet.
  2692.  
  2693.         Enter with:
  2694.           t1/ Pointer to asciz name of poet.
  2695.           t2/ Destination designator for poem.
  2696.           t3/ Pointer to asciz string describing desired topic.
  2697.  
  2698.         Returns:
  2699.           +1: always, with t1, t2, and t3 updated appropriately.
  2700.         |
  2701. Macro                                                                 Page 50
  2702.  
  2703. 3.3.7. DEC
  2704.  
  2705. Format          DEC expression, ..., expression
  2706.  
  2707. Function        Defines the local radix for the line as decimal, then enters
  2708.                 the value of each given expression in a fullword of code.  The
  2709.                 location counter is incremented by 1 for each expression.
  2710.  
  2711. Example         DEC 10, 938, 512, 4.5, 6.03E-5
  2712.  
  2713. Optional Notation:  Use the EXP pseudo-op and prefix ^d to each expression
  2714.                 that must be evaluated in radix 10.
  2715.  
  2716.  
  2717.  
  2718. 3.3.8. DEFINE
  2719.  
  2720. Format          DEFINE macroName(dArgList)<macroBody>
  2721.  
  2722.                 where
  2723.  
  2724.                    - macroName is a symbolic name for the macro being
  2725.                      defined.  This name must be unique among all macro
  2726.                      and OPDEF symbols.
  2727.  
  2728.                    - dArgList is a list of dummy arguments.
  2729.  
  2730.                    - macroBody is the source code to be assembled when
  2731.                      the macro is invoked.
  2732.  
  2733. Function        defines the macro.  See the section on macros.
  2734.  
  2735.  
  2736.  
  2737. 3.3.9. END
  2738.  
  2739. Format          END expression
  2740.  
  2741.                 where expression is an optional operand that specifies the
  2742.                 address of the first instruction to be executed, which can be
  2743.                 EXTERNAL, in the right half and, optionally, the length of the
  2744.                 entry vectory in the left.
  2745.  
  2746. Function        Must be the last statement in a Macro program.  Statements
  2747.                 after END are ignored.  The starting address is optional and
  2748.                 normally is given only in the main program (since subroutines
  2749.                 are called from the main program, they should not specify a
  2750.                 starting address).  When the assembler first encounters an END
  2751.                 statement, it terminates pass 1 and begins pass 2.  The END
  2752.                 terminates pass 2 on the second encounter, and unallocated
  2753.                 literals and variables (e.g. ARRAYs) are assembled at the
  2754.                 current location.
  2755.  
  2756. Examples:
  2757.  
  2758.                         end
  2759.                         end start
  2760.                         end <3,,entVec>
  2761. Macro                                                                 Page 51
  2762.  
  2763.                         end <evLen,,entVec>
  2764.  
  2765.  
  2766.  
  2767. 3.3.10. ENTRY
  2768.  
  2769. Format          ENTRY symbol, ..., symbol
  2770.  
  2771.                 Each symbol is the name of an entry point in a library
  2772.                 subroutine.
  2773.  
  2774. Function        Defines each symbol in the list following the ENTRY pseudo-op
  2775.                 as an INTERNAL symbol, and puts appropriate information in the
  2776.                 .REL file to allow the symbols to be included in an index
  2777.                 (such as that constructed by the MAKLIB program).  Each symbol
  2778.                 must correspond to a label of the same name.  Programs
  2779.                 referring to these symbols must, of course, declare them
  2780.                 EXTERNAL.
  2781.  
  2782.  
  2783.  
  2784. 3.3.11. EXP
  2785.  
  2786. Format          EXP expression, ..., expression
  2787.  
  2788. Function        Enters the value of each expression in a fullword of code.
  2789.  
  2790.  
  2791.  
  2792. 3.3.12. EXTERN
  2793.  
  2794. Format          EXTERN symbol, ..., symbol
  2795.  
  2796. Function        Identifies symbols as being defined in other programs.
  2797.                 EXTERNAL symbols cannot be defined within the current program.
  2798.                 At load time, the value of an EXTERNAL symbol is resolved by
  2799.                 Link if you load a module that defines the symbol as an
  2800.                 INTERNAL symbol; if you do not load such a module, Link gives
  2801.                 an error message for the undefined global symbol(s).
  2802.  
  2803.  
  2804.  
  2805. 3.3.13. IFx Group
  2806.  
  2807. Gives criterion and code for conditional assembly.  A symbol or expression
  2808. used to define the conditions for assembly must be defined before Macro
  2809. reaches the conditional statement.  If the value of such a symbol or
  2810. expression is not the same on both assembly passes, a different number of
  2811. words of code may be generated (resulting in a phase error).
  2812.  
  2813. The forms of IF pseudo-op are listed below; in the first six forms, n is the
  2814. value of the given expression.
  2815.  
  2816. IFE expression,<code> - assemble code if n=0.
  2817.  
  2818. IFN expression,<code> - assemble code if n not = 0.
  2819.  
  2820. IFG expression,<code> - assemble code if n>0.
  2821. Macro                                                                 Page 52
  2822.  
  2823. IFGE expression,<code> - assemble code if n>=0.
  2824.  
  2825. IFL expression,<code> - assemble code if n<0.
  2826.  
  2827. IFLE expression,<code> - assemble code if n<=0.
  2828.  
  2829. IF1 <code> - assemble code on Pass 1.
  2830.  
  2831. IF2 <code> - assemble code on Pass 2.
  2832.  
  2833. IFDEF symbol,<code> - assemble code if the symbol is defined as user-defined,
  2834.                 an opcode, or a pseudo-op.
  2835.  
  2836. IFNDEF symbol,<code> - assemble code if the symbol is not defined as
  2837.                 user-defined, an opcode, or a pseudo-op.  Code is also
  2838.                 assembled if the symbol has been referenced, but is not yet
  2839.                 defined.  This can occur during pass 1.
  2840.  
  2841. IFIDN <string1><string2>,<code> - assemble code if the strings are identical.
  2842.  
  2843. IFDIF <string1><string2>,<code> - assemble code if the strings are different.
  2844.  
  2845. IFB <string>,<code> - assemble code if the strings contain only blanks and
  2846.                 tabs.
  2847.  
  2848. IFNB <string>,<code> - assemble code if the string does not contain only
  2849.                 blanks and tabs.
  2850.  
  2851. Example:
  2852.  
  2853.  
  2854.                         $cc=$cc+1               ; Count a character.
  2855.                    ifg <$cc-5>,<                ; Word overflowed?
  2856.                         $cc=0                   ; Yes, reset character counter
  2857.                         $wc=$wc+1               ;  and count a word.
  2858.                    >
  2859.  
  2860. Optional notations:  Omit angle brackets enclosing code for single-line
  2861.                 conditionals.  For IFIDN, IFDIF, IFB, and IFNB only: use a
  2862.                 nonblank, nontab character other than < as the initial and
  2863.                 terminal delimiters for a string (as in the pseudo-ops ASCII
  2864.                 and ASCIZ); you can then include angle brackets in the string.
  2865.  
  2866.  
  2867.  
  2868. 3.3.14. INTERN
  2869.  
  2870. Format          INTERN symbol, ..., symbol
  2871.  
  2872. Function        Declares each given symbol to be INTERNAL global; therefore
  2873.                 its definition, which must be in the current program, is
  2874.                 available to other programs at load time.  Each such symbol
  2875.                 must be defined as a label, a variable, or a direct assignment
  2876.                 symbol.  OPDEF symbols can be declared INTERNAL, and thus be
  2877.                 made available to other programs at load time.  However, if
  2878.                 the current program has another symbol (besides the OPDEF
  2879.                 symbol) of the same name, the INTERNAL declaration will apply
  2880.                 to that symbol rather than to the OPDEF symbol.
  2881. Macro                                                                 Page 53
  2882.  
  2883. 3.3.15. IOWD
  2884.  
  2885. Format          IOWD exp1,exp2
  2886.  
  2887. Function        Generations a word in a special format for use by all five
  2888.                 pushdown stack instructions (adjsp, push, pop, pushj, popj),
  2889.                 as well as for i/o instructions (hence its name).  The left
  2890.                 half of the assembled word contains the 2's complement of the
  2891.                 value of exp1, and the right half contains the value exp2-1.
  2892.  
  2893. Example:        Setting up a pushdown stack.
  2894.  
  2895.  
  2896.                 stkLen=100
  2897.                         array stack[stkLen]
  2898.                         move p, [iowd stkLen,stack]
  2899.  
  2900.  
  2901.  
  2902. 3.3.16. IRP
  2903.  
  2904. Format          IRP arg,<code>
  2905.  
  2906.                 where arg is one of the dummy arguments of the enclosing macro
  2907.                 definition; you can only use IRP in the body of a macro
  2908.                 definition.
  2909.  
  2910. Function        Generates one expansion of the code enclosed in angle brackets
  2911.                 for each subargument of the string that replaces arg.  Each
  2912.                 occurrence of arg within the expansion is replaced by the
  2913.                 subargument currently controlling the expansion (see the
  2914.                 section on macros).
  2915.  
  2916. Example:
  2917.  
  2918.  
  2919.                 define  sum(a,b)<
  2920.                         movei q, 0
  2921.                         irp a,<add q,a>
  2922.                         movem q, b
  2923.                 >
  2924.                         sum (<x,y,z>,foo)
  2925.  
  2926.                 This invocation of sum is replaced by:
  2927.  
  2928.                         movei q, o
  2929.                         add q, x
  2930.                         add q, y
  2931.                         add q, z
  2932.                         movem q, foo
  2933.  
  2934. Macro                                                                 Page 54
  2935.  
  2936. 3.3.17. IRPC
  2937.  
  2938. Format          IRPC arg,<code>
  2939.  
  2940. Function        Generates one expansion of the bracketed code for each
  2941.                 character of the string that replaces arg (a dummy argument of
  2942.                 the enclosing macro definition).  Each occurrence of arg
  2943.                 within the expansion is replaced by the character currently
  2944.                 controlling the expansion.  Concatenation and line
  2945.                 continuation are not allowed across end-of-IRPC, since a
  2946.                 carriage return and linefeed are appended to each expansion.
  2947.  
  2948. Example:
  2949.  
  2950.  
  2951.                 define  deposit (string,bp)<
  2952.                    irpc string, <
  2953.                         movei q, "string"
  2954.                         idpb q, bp
  2955.                    >
  2956.                 >
  2957.                         deposit <foo>,x
  2958.  
  2959.                 expands to:
  2960.  
  2961.                         movei q, "f"
  2962.                         idpb q, x
  2963.                         movei q, "o"
  2964.                         idpb q, x
  2965.                         movei q, "o"
  2966.                         idpb q, x
  2967.  
  2968.  
  2969.  
  2970.  
  2971. 3.3.18. LIT
  2972.  
  2973. Format          LIT
  2974.  
  2975. Function        Assembles literals beginning at the current address.  The
  2976.                 literals assembled are those found since the previous LIT, or
  2977.                 since the beginning of the program, whichever is later.  The
  2978.                 location counter is incremented by 1 for each word assembled.
  2979.                 A literal found after the LIT is not affected.  It will be
  2980.                 assembled at the next following LIT, or at the END statement,
  2981.                 whichever is earlier.  Literals having the same value are
  2982.                 collapsed in Macro's literal pool.
  2983.  
  2984.  
  2985.  
  2986. 3.3.19. OCT
  2987.  
  2988. Format          OCT expression, ..., expresssion
  2989.  
  2990. Function        Defines the local radix for the line as octal; the value of
  2991.                 each each expression is entered in a fullword of code.  The
  2992.                 location counter is incremented by 1 for each expression.
  2993.                 Equivalent to using EXP with each argument prefixed by ^o.
  2994. Macro                                                                 Page 55
  2995.  
  2996. 3.3.20. OPDEF
  2997.  
  2998. Format          OPDEF symbol[expression]
  2999.  
  3000. Function        Defines the symbol as an operator equivalent to the
  3001.                 expression, giving the symbol a fullword value.  When the
  3002.                 operator is later used with operands, the accumulator fields
  3003.                 are added, the indirect bits are ORed, the memory addresses
  3004.                 are added, and the index register addresses are added.  An
  3005.                 OPDEF can be declared INTERNAL, using the INTERN pseudo-op.
  3006.                 However, if a symbol of the same name exists, the INTERNAL
  3007.                 declaration will apply only to that symbol, and not to the
  3008.                 OPDEF.  Although the expression portion of an OPDEF must be in
  3009.                 square brackets, this use of the brackets is completely
  3010.                 unrelated to literals or literal handling.
  3011.  
  3012.  
  3013.  
  3014. 3.3.21. POINT
  3015.  
  3016. Format          POINT byteSize,address,bitPosition
  3017.  
  3018. Function        Generates a byte pointer word for use with the machine
  3019.                 language byte instructions adjbp, ldb, ibp, ildb, and idbp.
  3020.                 The byteSize gives the decimal number of bits in the byte, and
  3021.                 is assembled in bits 6 to 11 of the storage word.  Address
  3022.                 gives the location of the word containing the byte, and is
  3023.                 assembled in bits 13 through 35 (with normal indirect, index,
  3024.                 and offset fields).  BitPosition gives the position (in
  3025.                 decimal) of the rightmost bit in the byte.  Macro places the
  3026.                 value <35-bitPosition> in bits 0-5 of the storage word.  The
  3027.                 default bitPosition is -1, so that the byte increment
  3028.                 instructions ipb, ildb, and idpb will operate on the first
  3029.                 byte in the address word.
  3030.  
  3031.  
  3032.  
  3033. 3.3.22. PRGEND
  3034.  
  3035. Format          PRGEND
  3036.  
  3037. Function        Replaces the END statement for all except the last program of
  3038.                 a multiprogram assembly.  PRGEND closes the local symbol table
  3039.                 for the current module.  You can use PRGEND to place several
  3040.                 small programs into one file to save space and disk accesses.
  3041.                 The resulting binary file can be loaded in library search mode
  3042.                 (refer to the Link and MakLib manuals for more information
  3043.                 about this).  PRGEND is not allowed in macros.  Like END,
  3044.                 PRGEND causes the assembly of all unassembled literals.  In a
  3045.                 file containing PRGENDs, using more than one LIT pseudo-op in
  3046.                 any but the last program produces unpredictable results.  A
  3047.                 starting address for the program terminated by PRGEND may
  3048.                 optionally be given as an argument to PRGEND.
  3049. Macro                                                                 Page 56
  3050.  
  3051. 3.3.23. PRINTX
  3052.  
  3053. Format          PRINTX text
  3054.  
  3055. Function        Causes text to be output at the terminal during assembly,
  3056.                 normally once for each pass.
  3057.  
  3058. Example:
  3059.  
  3060. define  prVal (v,msg)<printx [msg v]>
  3061.  
  3062.    if2, <
  3063.         $$len=.-buffer
  3064.         prVal \$$len, <Size of buffer (in words):>
  3065.         ifg <.-20000>,<printx <Buffer too big!>>
  3066.    >
  3067.  
  3068.  
  3069.  
  3070. 3.3.24. PURGE
  3071.  
  3072. Format          PURGE symbol, ..., symbol
  3073.  
  3074. Function        Deletes symbols from the symbol tables.  Normally used at the
  3075.                 end of a program to fix multiply defined global symbol errors
  3076.                 that occur at Link time, or to remove unwanted symbols from
  3077.                 DDT typeout.  If you use the same symbol for both a macro name
  3078.                 or OPDEF and a label, a PURGE statement deletes the macro name
  3079.                 or OPDEF.  Repeating the PURGE statement then purges the
  3080.                 label.
  3081.  
  3082.  
  3083.  
  3084. 3.3.25. RADIX
  3085.  
  3086. Format          RADIX expression
  3087.  
  3088. Function        Sets the radix to the value of the expression, which is
  3089.                 interpreted in decimal, and must be in the range 2 to 10.  An
  3090.                 implicit RADIX 8 statement begins each Macro program.  All
  3091.                 numerical expressions that follow (up to the next RADIX
  3092.                 pseudo-op) are interpreted in the given radix unless another
  3093.                 local radix is indicated via ^d, ^o, ^b, OCT, DEC, etc.
  3094.                 Ordinarily, numbers outside the range of the given radix are
  3095.                 not interpreted.  For example, in radix 8, the number 99
  3096.                 causes an error.  However, a single-digit number is
  3097.                 interpreted in any case.  For example, in radix 8, the number
  3098.                 9 is recognized as octal 11.
  3099.  
  3100.  
  3101.  
  3102. 3.3.26. REPEAT
  3103.  
  3104. Format          REPEAT expression,<code>
  3105.  
  3106. Function        Generates the bracketed code n times, where n is the value of
  3107.                 the expression, and must be a nonnegative integer.  REPEAT
  3108.                 statements can be nested to any level.  Line continuation is
  3109. Macro                                                                 Page 57
  3110.  
  3111.                 not allowed across end-of-REPEAT, since a carriage return and
  3112.                 linefeed are appended to each expansion of the code.  Note
  3113.                 that REPEAT 0,<code> is logically equivalent to a false
  3114.                 conditional (and is often used to "comment out" a large
  3115.                 section of code), and REPEAT 1,<code> is logically equivalent
  3116.                 to a true conditional.
  3117.  
  3118.  
  3119.  
  3120. 3.3.27. .REQUIRE
  3121.  
  3122. Format          .REQUIRE filespec
  3123.  
  3124. Function        Causes the specified file to be loaded automatically at Link
  3125.                 time.  The filespec must not include a file type, and it must
  3126.                 be a Tops-10 (not Tops-20!) file specification.
  3127.  
  3128.  
  3129.  
  3130. 3.3.28. SEARCH
  3131.  
  3132. Format          SEARCH tableName(fileName), ..., tableName(fileName)
  3133.  
  3134. Function        Defines a list of symbol tables for Macro to search if a
  3135.                 symbol is not found in the current symbol table.  A maximum of
  3136.                 ten tables can be specified.  Tables are searched in the order
  3137.                 specified.  When the SEARCH pseudo-op is seen, Macro checks
  3138.                 its internal UNIVERSAL tagble for a memory-resident UNIVERSAL
  3139.                 of the specified name.  If no such entry is found, Macro reads
  3140.                 in the symbol table using the given file specification.  If no
  3141.                 file specification is given, Macro reads tableName.UNV from
  3142.                 the connected directory, and on failure tries the same
  3143.                 filename in UNV: and SYS:, in that order.  When all the
  3144.                 specified files are found, Macro builds a table for the search
  3145.                 sequence.  If Macro cannot find a given symbol in the current
  3146.                 symbol table, the UNIVERSAL tables are searched in the order
  3147.                 specified.  When the symbol is found, it is moved into the
  3148.                 current symbol table.  This procedure saves time (at the
  3149.                 expense of core) on future references to the same symbol.  A
  3150.                 UNIVERSAL file can search other UNIVERSAL files, provided all
  3151.                 names in the search list have been assembled.
  3152.  
  3153. Optional notation:  Omit the filename and its enclosing parentheses.  Macro
  3154.                 then looks on DSK:, UNV:, and SYS: (in that order) for
  3155.                 tableName.UNV.
  3156.  
  3157.  
  3158.  
  3159. 3.3.29. SIXBIT
  3160.  
  3161. Format          SIXBIT dtextd
  3162.  
  3163.                 d = delimiter (first nonblank character, whose second
  3164.                 appearance terminates the text)
  3165.  
  3166. Function        Enters strings of text characters in 6-bit format.  Six
  3167.                 characters per word are left justified in sequential storage
  3168.                 words.  Any unused bits are set to zero.  Lowercase letters in
  3169. Macro                                                                 Page 58
  3170.  
  3171.                 SIXBIT text strings are treated as uppercase.  Otherwise, only
  3172.                 the SIXBIT character set allowed.  The SIXBIT character set
  3173.                 consists of all the printable ASCII characters except
  3174.                 lowercase letters, and the following symbols: `{|}~.  The
  3175.                 values of the SIXBIT characters are 0-77 (octal); they are
  3176.                 offset from the corresponding ASCII values by octal 40, e.g.
  3177.                 ASCII "A" is 101, and SIXBIT "A" is 41.  Historically, this
  3178.                 was a popular format for the storage of strings whose maximum
  3179.                 length was 6, such as filenames or program names under
  3180.                 Tops-10, because it allowed word comparisons and transfers
  3181.                 instead of slower byte manipulations.
  3182.  
  3183. Optional Notation:  Right-justified SIXBIT can be entered by using single
  3184.                 quotes to surround uf to six characters, as in
  3185.  
  3186.                     move t1, ['FOOBAZ']
  3187.  
  3188.  
  3189.  
  3190. 3.3.30. STOPI
  3191.  
  3192. Ends an IRP or IRPC before all subarguments or characters are used.  The
  3193. current expansion is completed, but no new expansions are started.  STOPI can
  3194. be used with conditionals inside IRP or IRPC to end the repeat if the given
  3195. condition is met.
  3196.  
  3197.  
  3198.  
  3199. 3.3.31. SUBTTL
  3200.  
  3201. Format          SUBTTL String
  3202.  
  3203. Function        Defines a subtitle (of up to 80 characters) to be printed at
  3204.                 the top of each page of the listing file until the end-of-
  3205.                 listing or until another SUBBTL statement is found.  The
  3206.                 initial SUBTTL usually appears on the second line of the first
  3207.                 page of the input file, immediately following the TITLE
  3208.                 statement.  For subsequent SUBTTL statements, the following
  3209.                 rule applies:  if the new SUBTTL is on the first line of a new
  3210.                 page, then the new subtitle appears on that page; if not, the
  3211.                 new subtitle appears on the next page.  Even if you do not
  3212.                 plan to generate listing files, SUBTTL is still a useful
  3213.                 documentation device, and is recognized by certain programming
  3214.                 aids.
  3215.  
  3216.  
  3217.  
  3218. 3.3.32. TITLE
  3219.  
  3220. Format          TITLE String
  3221.  
  3222. Function        Gives the program name and a title to be printed at the top of
  3223.                 each page of the program listing.  The first characters (up to
  3224.                 6) are the program name; the program is saved by this name
  3225.                 unless another is explicitly given in the 'save' command.  In
  3226.                 addition, the name is used when debugging with DDT to gain
  3227.                 access to the program's symbol table.  Only one TITLE is
  3228.                 allowed per module (file or section of file delimited by
  3229. Macro                                                                 Page 59
  3230.  
  3231.                 PRGEND's).  The TITLE statement usually appears as the first
  3232.                 line of a program.  If no TITLE statement is used, the
  3233.                 assembler inserts the program name ".MAIN".
  3234.  
  3235.  
  3236.  
  3237. 3.3.33. XWD
  3238.  
  3239. Format          XWD leftHalf,rightHalf
  3240.  
  3241. Function        Enters two halfwords in a single storage word.  Each half is
  3242.                 formed in a 36-bit register, and the low-order 18 bits are
  3243.                 placed in the halfword.  The high-order bits are ignored.
  3244.  
  3245. Optional Notation: leftHalf,,rightHalf
  3246.  
  3247.  
  3248.  
  3249. 3.3.34. Z
  3250.  
  3251. Format          Z accumulator, address
  3252.  
  3253. Function        Z is treated as if it were the null machine language mnemonic
  3254.                 ( opcode).  An instruction word if formed with zeros in bits 0
  3255.                 to 8.  The rest of the word is formed from the accumulator an
  3256.                 address.  If the accumulator and address fields are omitted, a
  3257.                 zero word is assembled.
  3258.  
  3259.  
  3260.  
  3261. 3.4. Macro Statements and Statement Processing
  3262.  
  3263. A Macro statement has one or more of the following: a label, an opcode, zero
  3264. or more operands, and a comment.  The general form of a macro statement is:
  3265.  
  3266.  
  3267. label:  operator operand, operand ; Comment.
  3268.  
  3269.  
  3270. A carriage return ends the statement.
  3271.  
  3272. Direct assignment statements receive special handling.
  3273.  
  3274. Processing of macros is not discussed in this section because a macro call
  3275. produces text substitution.  After substitution, the text is processed as
  3276. described in this section.  Macros are discussed in their own chapter.
  3277.  
  3278.  
  3279.  
  3280. 3.4.1. Labels
  3281.  
  3282. A label is always a symbol with a suffixed colon.  The assembler recognizes a
  3283. label by finding the colon.  If a statement has labels (you can use more than
  3284. one), they must be the first elements in the statement.
  3285.  
  3286. A label can be defined only once; its value is the address of the first word
  3287. of code generated after it.
  3288. Macro                                                                 Page 60
  3289.  
  3290. Since a label gives an address, the label can be either absolute or
  3291. relocatable.  A label is a local symbol by default, but you can declare a
  3292. label to be INTERNAL globel or EXTERNAL global.
  3293.  
  3294.  
  3295.  
  3296. 3.4.2. Operators
  3297.  
  3298. After processing any labels, the assembler views the first group of following
  3299. nonblank, nontab characters as a possible operator.  An operator is one of the
  3300. following:
  3301.  
  3302.    1. A mnemonic symbol defined by Macro to stand for a machine opcode
  3303.       (see Chapter 2).
  3304.  
  3305.    2. A user-defined operator, such as an OPDEF or macro invocation.
  3306.  
  3307.    3. A Macro pseudo-op.
  3308.  
  3309. If the characters found do not form one of the above, Macro views them as an
  3310. expression.
  3311.  
  3312. An operator is ended by the first non-alphanumeric character that is not a .,
  3313. $, or %.  If it is ended by blank or tab, operands may follow; if it is ended
  3314. by a semicolon, there are no operands and the comment field begins; if it is
  3315. ended by a carriage return, the statement ends and there are no operands or
  3316. comments.
  3317.  
  3318.  
  3319.  
  3320. 3.4.3. Operands
  3321.  
  3322. After processing labels and the operator, if any, the assembler views as
  3323. operands all characters up to the first unquoted semicolon or carriage return.
  3324. Unquoted commas delimit the operands.
  3325.  
  3326. The operator in a statement determines the number (none, one, two, or more)
  3327. and kinds of permitted or required operands.  Any expected operand not found
  3328. is interpreted as null.  An operand can be any expression or symbol
  3329. appropriate for the operator.
  3330.  
  3331. Examples:
  3332.  
  3333.  
  3334. loop:   move t1, x
  3335.         %print <x is %d, y is %d>,<exp t1, y>
  3336.  
  3337. In the first line, t1 and x are operands.  In the second line, a macro,
  3338. %print, is invoked with two operands.  Each of these operands is quoted by
  3339. enclosing it in angle brackets; this is necessary because each operand
  3340. contains an internal comma.
  3341. Macro                                                                 Page 61
  3342.  
  3343. 3.4.4. Comments
  3344.  
  3345. The first unquoted semicolon in a statement begins the comment field.  You can
  3346. use any ASCII characters in a comment; however, angle brackets in a comment
  3347. may produce unpredictable results (such as unexpected termination of a macro
  3348. definition or conditional-assembly code) and should be avoided.
  3349.  
  3350. If the first nonblank, nontab character in a line is a semicolon, the entire
  3351. line is a comment.  You can also enter a full line of comment with the
  3352. pseudo-op REMARK, or a multiline comment with the pseudo-op COMMENT.
  3353.  
  3354. Comments do not affect binary program output.
  3355.  
  3356.  
  3357.  
  3358. 3.4.5. Statement Processing
  3359.  
  3360. Macro processes your program as a linear stream of data.  During Pass 1 of an
  3361. assembly, Macro may find references to symbols not yet defined in the user
  3362. symbol table.  Whenever a symbol is defined, it is entered in the table with
  3363. its value, so that on Pass 2 all definitions can be found in the table.  The
  3364. values then replace the symbols in the binary code that is generated.
  3365.  
  3366.        Note: Delayed definition is allowed only for labels and direct-
  3367.     assignment symbols.  A symbol that contributes to code generation (for
  3368.     example, an OPDEF, a macro, or a REPEAT index) must be defined before
  3369.     any reference to it.
  3370.  
  3371. Statement processing proceeds as follows:
  3372.  
  3373.    1. Labels are found and entered in the user symbol table.
  3374.  
  3375.    2. The next characters up to the first unquoted semicolon, blank, tab,
  3376.       comma, or equal sign are processed:
  3377.  
  3378.          a. Equal sign: the preceding characters form a symbol, and the
  3379.             following characters form an expression.  The symbol and the
  3380.             value of the expression are entered in the user symbol table.
  3381.  
  3382.          b. Other delimiter: the preceding characters form an expression
  3383.             or an operator.  If an operator, it is found in a table and
  3384.             assembled.  If an expression, its value is assembled.
  3385.  
  3386.       If the operator takes operands, the next characters up to the first
  3387.       unquoted semicolon or carriage return form operands.  Unquoted
  3388.       commas delimit operands.  For each operand, leading and trailing
  3389.       blanks and tabs are ignored.  Operands are evaluated and assembled
  3390.       for the given operator.
  3391.  
  3392.    3. The first unquoted semicolon ends processing of the line.  Any
  3393.       further characters up to the first carriage return are comment.
  3394.  
  3395.    4. The first unquoted carriage return ends the statement.  Any
  3396.       following characters begin a new statement.
  3397. Macro                                                                 Page 62
  3398.  
  3399. 3.4.6. Assigning Addresses
  3400.  
  3401. Macro normally (and by default) assembles statements with relocatable
  3402. addresses.  Assembly begins with the zero storage word and proceeds
  3403. sequentially.  Each time Macro assembles a word of binary code, it increments
  3404. its location counter by 1.
  3405.  
  3406. A mnemonic operator generates one word of binary code.  Direct assignment
  3407. statements and some pseudo-ops do not generate any binary code.  Some
  3408. pseudo-ops generate one or more word of binary code.
  3409.  
  3410. You can control address assignment by setting the assembler's location counter
  3411. using the pseudo-ops LOC and RELOC.  You can also reference addresses relative
  3412. to the location counter by using the dot symbol (.).  For example, the
  3413. expression .-1 used as an address refers to the location immediately preceding
  3414. the current location.  Use of this construction is not encouraged (see Chapter
  3415. 8), because you can cause an incorrect address to be assembled by adding or
  3416. removing statements withing the range of a .+n expression.  Labels should be
  3417. used except when n = plus or minus 1.
  3418.  
  3419.  
  3420.  
  3421. 3.4.7. Machine Instruction Mnemonics and Formats
  3422.  
  3423. An instruction is in one of the following forms:
  3424.  
  3425.  
  3426.         mnemonic accumulator, address
  3427.         mnemonic accumulator,
  3428.         mnemonic address
  3429.  
  3430. where "mnemonic" evaluates to a machine operation code (opcode), "accumulator"
  3431. is an accumulator (or register) address, and "address" is a memory address,
  3432. possibly modified by indexing, indirect addressing, or both.
  3433.  
  3434. The accumulator address can be any expression whose value is in the range 0 to
  3435. 17 (octal).
  3436.  
  3437. The memory address gives a location in memory, and can be any expression or
  3438. symbol whose value is an integer in the range 0 to octal 777777.
  3439.  
  3440. You can modify the memory address by indirect addressing, indexed addressing,
  3441. or both.  For indirect addressing, prefix an at-sign (@) to the memory address
  3442. in your program.  For indexed addressing, suffix an index register address in
  3443. parentheses to the memory address in your program.  This address can be any
  3444. expression or symbol whose value is an integer in the range 1 to octal 17.
  3445.  
  3446.        Note: To assemble the index, Macro places the index register
  3447.     address in a fullword of storage, swaps its halfwords (as it does to
  3448.     any expression in parentheses), and then adds the swapped word to the
  3449.     instruction word.
  3450.  
  3451. Example (in which t1=1, temp=100, and x=3):
  3452.  
  3453.     add t1, @temp(x)
  3454.  
  3455. This generates the following binary code:
  3456. Macro                                                                 Page 63
  3457.  
  3458.  
  3459. instruction                indirect
  3460.    code                      bit                memory address
  3461.  
  3462. 010 111 000        0 001      1        0 011    000 000 000 001 000 000
  3463.  
  3464.                 accumulator            index
  3465.                                       register
  3466.  
  3467. The mnemonic ADD has the octal code 270, and this is assembled into bits 0 to
  3468. 8.  The accumulator goes into bits 9 to 12.  Since the @ appears with the
  3469. memory address, bit 13 is set to 1.  The index register goes into bits 14 to
  3470. 17.  Finally, the memory address is assembled into bits 18 to 35.
  3471.  
  3472. If any element is missing from a primary instruction, zeros are assembled in
  3473. its instruction word field.
  3474.  
  3475.  
  3476.  
  3477. 3.4.8. Mnemonics with Implicit Accumulators
  3478.  
  3479. A few mnemonics set bits in the accumulator field as well as in the
  3480. instruction field.  Therefore these mnemonics do not take accumulator
  3481. operands, and are of the form
  3482.  
  3483.     mnemonic address
  3484.  
  3485. For example, JFOV gives the octal code 25504; JFCL gives 255.  They both give
  3486. the opcode 255 in bits 0 to 8, but JFOV also sets the accumulator (bits 9 to
  3487. 12) to binary 0001.  This makes JFOV 100 equivalent to JFCL 1,100.
  3488.  
  3489.  
  3490.  
  3491. 3.5. Using Macros
  3492.  
  3493. A macro is a sequence of statements defined and named in your program.  When
  3494. you invoke a macro (by mentioning its name in your program), the sequence of
  3495. statements from its definition is generated in place of the invocation,
  3496. possibly with "arguments" plugged in.
  3497.  
  3498. By using macros with arguments, you can generate passages of code that are
  3499. similar, but whose differences are controlled by the arguments.  This saves
  3500. repetition in building a source file.
  3501.  
  3502.  
  3503.  
  3504. 3.5.1. Defining Macros
  3505.  
  3506. Before you can invoke a macro, you must define it.  You can also redefine a
  3507. macro if you wish; the new definition simply replaces the old one.
  3508.  
  3509. To define (or redefine) a macro, use the pseudo-op DEFINE:
  3510.  
  3511.     DEFINE macroName (dArgList)<macroBody>
  3512.  
  3513. where "macroName" is the name of the macro, "dArgList" is an optional list of
  3514. "dummy arguments", and "macroBody" is a sequence of statements.  The macroName
  3515. is a symbol constructed according to the rules for symbols.
  3516. Macro                                                                 Page 64
  3517.  
  3518. The optional dummy-argument list can give one or more dummy-argument symbols
  3519. through which values are passed to the sequence of statements.  If a macro
  3520. definition has dummy arguments, they must be enclosed in parentheses.  Use
  3521. commas as delimiters between dummy arguments.  For each dummy argument,
  3522. leading and trailing spaces and tabs are ignored.
  3523.  
  3524. The macroBody is the sequence of statements you want to generate when you
  3525. invoke the macro.  The macroBody must be enclosed in angle brackets.
  3526.  
  3527. Here is a sample macro definition:
  3528.  
  3529.  
  3530. define  vMag (adrs,len) <       ;; Vector Magnitude macro.
  3531.         move t1, adrs           ;; Get first component.
  3532.         fmp t1, t1              ;; Square it.
  3533.         move t2, adrs+1         ;; Get second component.
  3534.         fmp t2, t2              ;; Square it
  3535.         fad t1, t2              ;;  and add in square of first.
  3536.         move t2, adrs+2         ;; Third component...
  3537.         fmp t2, t2              ;;  squared...
  3538.         fad t1, t2              ;;  and added in to the sum.
  3539.         call fSqrt              ;; Go get the floating square root
  3540.         movem t1, len           ;;  and store the result.
  3541. >
  3542.  
  3543. Note the double semicolons; this device allows comments to be included in
  3544. macro definitions but omitted from macro expansions.
  3545.  
  3546.  
  3547.  
  3548. 3.5.2. Invoking Macros
  3549.  
  3550. You can invoke a macro by putting its name in your program.  Recall that you
  3551. must define the macro before you can invoke it.  You can use the macroName as
  3552. a label, an operator, or an operand.
  3553.  
  3554. If the macro's definition has dummy arguments, the macro invocation can have
  3555. arguments.  The arguments passed to the macro are inserted into the defined
  3556. sequence of statements as it is generated.  The first passed argument replaces
  3557. the first dummy argument; the second passed argument replaces the second dummy
  3558. argument; this treatment continues for each argument passed.  Any missing
  3559. arguments are passed as nulls (zeros) or filled in by default arguments (see
  3560. below).
  3561.  
  3562.        Note: if FOO is a macro with four dummy arguments, the call
  3563.     FOO (a,,c) passes a and c as the first and third arguments.  The
  3564.     second argument is passed as null; it is not considered missing and
  3565.     cannot be replaced by a default argument.  The fourth argument is
  3566.     missing and will be replaced by a default argument if one has been
  3567.     defined; otherwise it will be passed as nulls.
  3568.  
  3569. After argument substitution, the defined sequence of statements replaces the
  3570. macroName and the argument list in the source text.  For example, suppose you
  3571. have defined vMag(adrs,len) as shown in Section 3.5.1 above, and vMag is
  3572. invoked in your program as follows:
  3573.  
  3574.  
  3575. getMag: vMag coord, q1
  3576. Macro                                                                 Page 65
  3577.  
  3578. Then the effect would be as if you had written the following code in your
  3579. program in place of the invocation of vMag:
  3580.  
  3581.  
  3582. getMag: move t1, coord
  3583.         fmp t1, t1
  3584.         move t2, coord+1
  3585.         fmp t2, t2
  3586.         fad t1, t2
  3587.         move t2, coord+2
  3588.         fmp t2, t2
  3589.         fad t1, t2
  3590.         call fSqrt
  3591.         movem t1, q1
  3592.  
  3593. This code is called the "macro expansion"; the invocation of vMag has been
  3594. replaced by the macroBody from the definition of vMag, with the actual
  3595. arguments from the invocation (coord and q1) replacing the dummy arguments
  3596. from the definition (coord and len) throughout the text of the macroBody.
  3597.  
  3598.  
  3599.  
  3600. 3.5.3. Macro Invocation Format
  3601.  
  3602. In a macro invocation, delimit the macroName with one or more blanks or tabs.
  3603. If the macro has arguments, the first nonblank, nontab character begins the
  3604. argument list.  Each argument ends with a comma, a carriage return, or a
  3605. semicolon.  These three characters cannot be used within arguments unless
  3606. enclosed by special quoting characters.
  3607.  
  3608. Leading spaces and tabs are stripped from each argument unless they are within
  3609. special quoting characters.  Embedded spaces and tabs are not stripped.
  3610.  
  3611. Examples:
  3612.  
  3613. %erMsg eh?,errLoc
  3614.  
  3615.        The macroName is %erMsg; the arguments are the strings "eh?" and
  3616.     "errLoc".
  3617.  
  3618. %erMsg <Invalid foo, baz, or frotz>,errLoc
  3619.  
  3620.        Here the first argument is quoted, because it contains commas.
  3621.  
  3622.  
  3623. %print <The coordinates are %d, %d, %d>,<
  3624.         x
  3625.         y
  3626.         z
  3627.         >
  3628.  
  3629. Here the first argument is quoted because it contains commas, and the second
  3630. argument is quoted because it contains carriage returns.
  3631. Macro                                                                 Page 66
  3632.  
  3633. 3.5.4. Quoting Characters in Macro Arguments
  3634.  
  3635. The special quoting characters for macro arguments are:
  3636.  
  3637.  
  3638.   < >  Angle brackets
  3639.   ( )  Parentheses
  3640.   [ ]  Square brackets
  3641.   " "  Doublequotes (but not single quotes (apostrophes))
  3642.  
  3643. Any character, including the semicolon (;), enclosed in special quoting
  3644. characters is treated as a regular character.  If one of the special quoting
  3645. characters is to be passed as a regular character, it must be enclosed by
  3646. different special quoting characters.
  3647.  
  3648. Here are the rules for macro argument handling.  In the examples, "foo" is
  3649. assumed to be a defined macro:
  3650.  
  3651.    1. The special quoting characters are not argument delimiters.  They
  3652.       only tell the assembler to treat the enclosed characters as regular
  3653.       characters.
  3654.  
  3655.       foo c<a,b>      has one argument: c<a,b>.
  3656.  
  3657.       foo c,d<a,b>    has two arguments: c and c<a,b>.
  3658.  
  3659.    2. With the two exceptions explained below, special quoting characters
  3660.       are always included in passed arguments.
  3661.  
  3662.       foo a,(b,c)     has two arguments: a and (b,c).
  3663.  
  3664.       foo [xwd 1,L1]-1(ac) has one argument: [xwd 1,L1]-1(ac).
  3665.  
  3666.       foo "(",0 has two arguments:  "(" and 0.
  3667.  
  3668.       Exceptions:
  3669.  
  3670.          a. If the first character of the argument list is a left
  3671.             parenthesis, then it and its matching right parenthesis
  3672.             delimit the argument list.  They are not treated as special
  3673.             quoting characters and are not included in passed arguments.
  3674.             All nested quoting characters except angle brackets are
  3675.             disabled.  After stripping the outer parentheses, angle
  3676.             brackets are handled as described in Exception 2, below.
  3677.  
  3678.             foo (a,b,c)     has 3 arguments: a, b, and c.
  3679.  
  3680.             foo (?Length > 132) has one argument: ?Length > 132.
  3681.  
  3682.             foo ([a,b])     has two arguments: [a and b].
  3683.  
  3684.             foo (<a,b>)     has one argument: a,b.
  3685.  
  3686.          b. If a left angle bracket is the first character of the
  3687.             argument list, or the first character after an unquoted
  3688.             comma, then it and its matching right angle bracket are
  3689.             treated as special quoting characters, but are not included
  3690.             in passed arguments.
  3691. Macro                                                                 Page 67
  3692.  
  3693.             foo <a,b>,c     has two arguments: a,b and c.
  3694.  
  3695.             foo c,<a,b>     has two arguments: c and a,b.
  3696.  
  3697.  
  3698.  
  3699. 3.5.5. Nesting Macro Definitions
  3700.  
  3701. You can define a macro within the body of another macro definition.  The
  3702. nested macro is not defined to the assembler until the enclosing macro is
  3703. invoked.  See the example in 3.5.6.
  3704.  
  3705.  
  3706.  
  3707. 3.5.6. Concatenating Macro Arguments
  3708.  
  3709. The apostrophe (') is the concatenation operator for macro calls.  If you
  3710. insert an apostrophe immediately before or after a dummy argument in the body
  3711. of a macro, the assembler removes it at invocation.  This removal joins
  3712. (concatenates) the passed argument to the neighboring character in the
  3713. generated text.
  3714.  
  3715. If the apostrophe precedes the dummy argument, the passed argument is suffixed
  3716. to the preceding character; if the apostrophe is follows the dummy argument,
  3717. the passed argument is prefixed to the following character.
  3718.  
  3719. You can use more than one apostrophe with a dummy argument.  In this case only
  3720. apostrophes next to the dummy argument will be removed (at most one from each
  3721. side).  Other apostrophes are treated as regular characters in the macroBody.
  3722. The following example shows the treatment of apostrophes on both sides of the
  3723. dummy argument, and of double apostrophes:
  3724.  
  3725.  
  3726. define  o (prefix,midfix) <
  3727.    define ocomp (suffix) <
  3728.         prefix'o'midfix''suffix
  3729.    >
  3730. >
  3731.  
  3732. The invocation "o a,j" generates:
  3733.  
  3734.  
  3735.         aoj'suffix
  3736.  
  3737. because when the assembler replaces "prefix" with "a", the apostrophe
  3738. following is removed to form "ao".  When "j" replaces "midfix", the preceding
  3739. apostrophe and first following apostrophe are removed to form "aoj'suffix".
  3740.  
  3741. Now the invocation "ocomp le" generates "aojle" since the apostrophe is
  3742. removed to join "aoj" and "le".
  3743.  
  3744.  
  3745.  
  3746. 3.5.7. Default Arguments and Created Symbols
  3747.  
  3748. Ordinarily, an argument missing from a macro invocation is passed as nulls.
  3749. For example, the macro defined by
  3750. Macro                                                                 Page 68
  3751.  
  3752.  
  3753. define  words (a,b,c) <
  3754.         exp a,b,c
  3755. >
  3756.  
  3757. when invoked by "words 1,1" generates three words containing 1, 1, and 0,
  3758. respectively.
  3759.  
  3760. You can, however, alter this handling by specifying default values other than
  3761. nulls, or by using created symbols.
  3762.  
  3763.  
  3764.  
  3765. 3.5.7.1. Specifying Default Values
  3766.  
  3767. If you want a missing argument to default to some value other than nulls, you
  3768. can specify the default value in your DEFINE statement.  Do this by inserting
  3769. the default value in angle brackets immediately after the dummy argument.  For
  3770. example, the macro defined by
  3771.  
  3772.  
  3773. define  words (a,b<222>,c<333>) <
  3774.         exp a, b, c
  3775. >
  3776.  
  3777. when invoked by "words 1,1" generates three words containing 1, 1, and 333,
  3778. respectively.
  3779.  
  3780. An argument passed as nulls by consecutive commas is NOT considered missing
  3781. and cannot cause a default value to be supplied.  Therefore missing arguments
  3782. can occur only at the end of the list of passed arguments.
  3783.  
  3784.  
  3785.  
  3786. 3.5.7.2. Created Symbols
  3787.  
  3788. A symbol used as a label in a macroBody must be different for each call of the
  3789. macro, since duplicate labels are not allowed.  Therefore for each call a
  3790. different symbol for the label must be passed as an argument.
  3791.  
  3792. If you do not refer to such a label from outside the macro, you can simply let
  3793. the assembler provide a new label for each call.  This label is called a
  3794. created symbol, and is of the form ..nnnn where nnnn is a 4-digit number.
  3795.  
  3796. To use a created symbol in place of a passed argument, use the percent sign
  3797. (%) as the first character of the dummy argument in your DEFINE statement.
  3798. The assembler then creates a symbol for use in the macro expansion if that
  3799. argument is missing from a call to the macro.  If you provide an argument in
  3800. the call, the passed argument overrides the created symbol.
  3801.  
  3802. The argument is determined to be missing from, or present in, the macro
  3803. invocation in the same way in 3.5.7.1, i.e. only a trailing argument can be
  3804. missing.
  3805.  
  3806. Example:
  3807. Macro                                                                 Page 69
  3808.  
  3809.  
  3810. define  compare (test,save,index,%loc) <
  3811. %loc:   move save, test
  3812.         setz index,
  3813.         came save, table(index)
  3814.          jrst %loc
  3815. >
  3816.  
  3817.         compare t1, t1, t3
  3818.  
  3819. expands to:
  3820.  
  3821. ..0001: move t2, t1
  3822.         setz t3,
  3823.         came t2, table(t3)
  3824.          jrst ..0001
  3825.  
  3826. while
  3827.         compare t1, t2, t4, foo
  3828.  
  3829. expands to:
  3830.  
  3831. foo:    move t2, t1
  3832.         setz t4,
  3833.         came t2, table(t4)
  3834.          jrst foo
  3835.  
  3836.  
  3837.  
  3838. 3.5.8. Indefinite Repetition
  3839.  
  3840. The pseudo-ops IRP, IRPC, and STOPI give a convenient way to repeat all or
  3841. part of a macro; you can change arguments on each repetition if you wish, and
  3842. the number of repetitions can be computed at assembly time.  You can use these
  3843. three pseudo-ops only within the body of a macro definition.
  3844.  
  3845. To see how IRP works, assume the macro definition
  3846.  
  3847.  
  3848. define  doEach (a) <
  3849.         IRP a,<a>
  3850. >
  3851.  
  3852. The invocation "doEach <alpha,beta,gamma>" produces the code:
  3853.  
  3854.  
  3855.         alpha
  3856.         beta
  3857.         gamma
  3858.  
  3859. because each subargument passed to IRP generates one repetition of the code.
  3860. Notice that the range of IRP must be enclosed in angle brackets.
  3861.  
  3862. Using angle brackets in the invocation of doEach is critical, since they make
  3863. the string "alpha,beta,gamma" a single argument for IRP.  IRP then sees the
  3864. commas as delimiting subarguments.
  3865.  
  3866. IRPC is similar to IRP, but an argument passed to IRPC generates one
  3867. Macro                                                                 Page 70
  3868.  
  3869. repetition for each character of the argument.  See 3.3.17 for an example of
  3870. IRPC.
  3871.  
  3872. STOPI ends the action of IRP or IRPC after assembly of the current expansion.
  3873. You can use STOPI with a conditional assembly to calculate a stopping point
  3874. during assembly.  Here's an example, in which IRPC is used to generate code to
  3875. copy either a whole string or the first five characters, whichever is shorter:
  3876.  
  3877.  
  3878. define  copy5 (string, dest) <
  3879. $count=5
  3880.         irpc string, <          ;; Get a character from String.
  3881.            movei t1, "string"   ;; Copy it.
  3882.            idpb t1, dest        ;;  ...
  3883.            $count=$count-1      ;; Count it.
  3884.            ife $count,<stopi>   ;; If we've done 5, then quit.
  3885.    >
  3886. >
  3887.  
  3888.  
  3889.  
  3890. 3.5.9. Alternate Interpretations of Characters Passed to Macros
  3891.  
  3892. The normal argument passed by a macro call is simply the string of characters
  3893. given with the call.  Macro offers three alternate interpretations of the
  3894. passed argument.
  3895.  
  3896.    - If you prefix a backslash (\) to an expression argument, the
  3897.      argument passed is the ASCII numeric character string giving the
  3898.      value of the expression.  See 3.3.23 for a useful example.
  3899.  
  3900.    - If you prefix a backslash-apostrophe (\') to an expression argument,
  3901.      the argument passed is the string whose value is the SIXBIT string
  3902.      with the integer value of the expression.
  3903.  
  3904.    - If you prefix backslash-doublequote (\") to an expression argument,
  3905.      the argument passed is the string whose value is the ASCII string
  3906.      with the integer value of the expression.
  3907.  
  3908. Illustration:  a macro "foo" that just replaces itself by its argument can
  3909. work in many ways.
  3910.  
  3911.  
  3912. define  foo (a) <
  3913.         a
  3914. >
  3915.  
  3916. Sample invocations of foo; assume the following symbol definitions:
  3917.  
  3918.  
  3919. Z=60
  3920. ZZ='SIXBIT'
  3921. ZZZ="ASCII"
  3922.  
  3923. Invocation      Expansion
  3924.  
  3925. foo 60          60
  3926. Macro                                                                 Page 71
  3927.  
  3928. foo \60         60
  3929.  
  3930. foo \'60        P
  3931.  
  3932. foo \"60        0
  3933.  
  3934. foo Z           Z
  3935.  
  3936. foo \Z          60
  3937.  
  3938. foo \'Z         P
  3939.  
  3940. foo \"Z         0
  3941.  
  3942. foo ZZ          ZZ
  3943.  
  3944. foo \ZZ         635170425164
  3945.  
  3946. foo \'ZZ        SIXBIT
  3947.  
  3948. foo ZZZ         ZZZ
  3949.  
  3950. foo \ZZZ        203234162311
  3951.  
  3952. foo \"ZZZ       ASCII
  3953.  
  3954.  
  3955.  
  3956. 3.6. Errors and Messages
  3957.  
  3958. Macro has three kinds of messages:
  3959.  
  3960.    1. Informational messages
  3961.  
  3962.    2. Single-character error codes
  3963.  
  3964.    3. MCRxxx (where xxx is a 3-letter mnemonic code)
  3965.  
  3966.  
  3967.  
  3968. 3.6.1. Informational Messages
  3969.  
  3970. This are found at the end of listings, and some of them are printed at your
  3971. terminal.  The only truly useful one is:
  3972.  
  3973.     UNASSIGNED DEFINED AS IF EXTERNAL
  3974.  
  3975. This message lists symbols that were not defined.  A symbol can be undefined
  3976. for several reasons:
  3977.  
  3978.    1. You forgot to define it, e.g. you referred to a label that you
  3979.       forgot to include in your program.
  3980.  
  3981.    2. You spelled it wrong either when defining it or when referring to
  3982.       it.
  3983.  
  3984.    3. You are referring to a symbol defined in another module, but you
  3985.       forgot to declare it EXTERNAL in the current module.
  3986. Macro                                                                 Page 72
  3987.  
  3988. 3.6.2. Single-Character Error Codes
  3989.  
  3990. These cryptic and uninformative codes are printed at your terminal when Macro
  3991. encounters various kinds of errors.
  3992.  
  3993. A               Argument error in pseudo-op.
  3994.  
  3995. D               The statement refers to a multiply defined symbol.
  3996.  
  3997. E               Improper use of EXTERNAL symbol.
  3998.  
  3999. L               Literal generates less than 1 or more than 99 words of code.
  4000.  
  4001. M               Symbol has already been defined; it will retain its first
  4002.                 definition.
  4003.  
  4004. N               Number error.
  4005.  
  4006. O               Opcode undefined, assembled as zeros.
  4007.  
  4008. P               Phase error.  In general, the assembler generates the same
  4009.                 number of locations on Pass 1 and Pass 2.  Any discrepancy
  4010.                 causes a phase error.
  4011.  
  4012. Q               Questionable.  A broad class of warnings issued when the
  4013.                 assembler finds ambiguous language.
  4014.  
  4015. R               Relocation error.
  4016.  
  4017. U               Undefined Symbol.
  4018.  
  4019. V               Symbol used to control the assembler is undefined.
  4020.  
  4021. X               Error in defining or calling a macro during Pass 1.
  4022.  
  4023.  
  4024.  
  4025. 3.6.3. MCRxxx Messages
  4026.  
  4027. These appear at your terminal during assembly, and are followed by an English
  4028. phrase that explains the problem, e.g.
  4029.  
  4030.     MCRCFU - CANNOT FIND UNIVERSAL
  4031.  
  4032. The MCRxxx messages should be more or less self-explanatory.
  4033. Monitor Calls                                                         Page 73
  4034.  
  4035.                    4. Introduction to Tops-20 Monitor Calls
  4036.  
  4037.  
  4038.  
  4039. 4.1. Introduction
  4040.  
  4041. This document contains all the information you need to do certain basic
  4042. monitor calls (mostly those for input/output) from assembly language programs
  4043. on the DECSYSTEM-20.  Only a few of the many existing monitor calls are
  4044. described, and these are not always described in complete detail.  Any
  4045. information not covered here can be found in most recent edition of the
  4046. DECSYSTEM-20 Monitor Calls Reference Manual.
  4047.  
  4048. Knowledge of the KL10 (DECSYSTEM-20) instruction set, and of an assembler
  4049. (preferably Macro-20), is assumed.  All numbers in the following text, except
  4050. bit positions (which are always decimal), are octal (base 8) unless otherwise
  4051. noted.
  4052.  
  4053.  
  4054.  
  4055. 4.2. General Information
  4056.  
  4057. Monitor calls are invocations of subroutines in the Tops-20 monitor.  A DEC-20
  4058. monitor call is known as a JSYS (Jump to System).  All JSYS's have opcode 104,
  4059. which is trapped by the monitor which in turn looks at the address field of
  4060. the instruction to find out which JSYS is being called.  The following
  4061. conventions apply to all JSYS's:
  4062.  
  4063. Arguments for the JSYS are placed in accumulators (AC's).  The first argument
  4064. is in AC1, the second in AC2, and so forth up to a maximum of four AC's.  If
  4065. more than four arguments need to be passed, they are placed in an argument
  4066. block pointed to by an AC.
  4067.  
  4068. Results are also returned in AC's 1-4; if more than 4 results are to be
  4069. returned, they are returned in a block of memory whose address was specified
  4070. in the calling sequence.  Any AC which does not return a result should have
  4071. the same contents after the call as before.
  4072.  
  4073. After execution of the JSYS, control is returned to the caller at one of two
  4074. locations.  The +1 return (calling location plus 1) is often used to indicate
  4075. failure of the JSYS to perform its intended function, and an error code is
  4076. stored somewhere to indicate the exact cause of the failure.  The +2 return is
  4077. used to indicate successful completion of the JSYS.
  4078.  
  4079. However, some JSYS's have only a single return to the instruction following
  4080. the call (+1) regardless of success or failure; this is the newer convention.
  4081. For this reason, it is generally not wise to depend on the +1/+2 convention;
  4082. another mechanism has been provided which should be used instead: erjmp/ercal.
  4083. Erjmp (which assembles as 'jump 16,') causes a jump to the specified location
  4084. if the JSYS, which must precede it immediately, failed.  Ercal ('jump 17,')
  4085. works in the same way except it 'calls' rather than 'jumps'.  Each JSYS, upon
  4086. encountering an error, inspects the contents of the instruction following the
  4087. JSYS call.  If it is an erjmp or ercal, it takes the indicated action; if not,
  4088. it returns +1 or +2 according to its definition.
  4089.  
  4090. Every JSYS error has an associated error message, which provides a one-line
  4091. English description of the error, e.g.
  4092. Monitor Calls                                                         Page 74
  4093.  
  4094. ?Directory access privileges required
  4095.  
  4096. The erring JSYS does not print the message; other JSYS's are provided to print
  4097. these error strings in a standard way (on the left margin, preceded by a
  4098. question mark).  In general, recovery from a JSYS error involves printing the
  4099. error message and then either halting or going to some special section of code
  4100. that takes corrective action.  Since these cases are overwhelmingly common,
  4101. let us assume that a special macro, called %jsErr, has been provided to take
  4102. care of them.  It has the following format:
  4103.  
  4104.  
  4105.          %jsErr message,address
  4106.  
  4107.  
  4108. If the message is specified, it is printed as a standard error message; if
  4109. not, the appropriate system-defined JSYS error message is printed.  If the
  4110. address is specified, control will transfer to it after the message is
  4111. printed, otherwise the program will halt (but can be continued at the
  4112. instruction following the %jserr).  Here are some examples (shown without
  4113. setting up the AC's):
  4114.  
  4115.  
  4116.         GTJFN                   ; JSYS to Get Job File Number.
  4117.          %jsErr                 ; Print standard message and halt on error.
  4118.  
  4119.         GTJFN
  4120.          %jsErr <Can't get the JFN> ; Print custom message, then halt.
  4121.  
  4122.         GTJFN
  4123.          %jsErr (,foo)          ; Print standard message then go to foo.
  4124.  
  4125. A couple more examples not using the macro:
  4126.  
  4127.         GTJFN
  4128.          erjmp foo              ; Go to foo on error.
  4129.  
  4130.         GTJFN
  4131.          ercal baz              ; Call subroutine baz on error.
  4132.  
  4133.         GTJFN
  4134.          ercal [setz t1         ; Execute these instructions on error.
  4135.                 movei t2, 1
  4136.                 ret ]           ; (ret = 'popj 17,')
  4137.         movem t1, injfn         ; Come here regardless of success or failure.
  4138.  
  4139.         GTJFN
  4140.          erjmp [setz t1         ; On failure, execute these instructions
  4141.                 movei t2, 1     ;  ...
  4142.                 jrst foo ]      ;  then go to foo.
  4143.         movem t1, injfn         ; Come here only on success.
  4144.  
  4145.  
  4146. Erjmp and ercal are defined in monSym (i.e. in sys:monSym.unv) for Macro
  4147. programs, and predefined for Midas programs.  %jsErr is defined, for Macro, in
  4148. CUSYM; jsErr is defined for Midas in MAC:MacSym.mid.
  4149. Monitor Calls                                                         Page 75
  4150.  
  4151. 4.3. Using Mnemonic Symbols
  4152.  
  4153. Most JSYS's include among their arguments a number of arbitrarily chosen
  4154. numeric constants, including special numbers to designate the source for input
  4155. or output, and bits that can be on or off depending on whether the
  4156. corresponding option is selected.  These bits are listed in the description of
  4157. each JSYS.  Of course it is possible to write the (possibly combined) bits as
  4158. octal constants, but this would be extremely poor programming practice,
  4159. because the resulting code would be unreadable.  Therefore, symbols have been
  4160. defined to stand for each bit.  These symbols have some mnemonic value, and
  4161. they should always be used.  The definitions appear in SYS:MONSYM.UNV, and you
  4162. access them from your Macro program by including the "search monSym"
  4163. directive.  (Midas has the symbols built in.)
  4164.  
  4165. Some of the very common symbols that are not specific to any particular JSYS
  4166. are:
  4167.  
  4168.  
  4169.           Value:
  4170. Symbol    Left Half     Right Half      Meaning
  4171. ------    ---------     ----------      -------
  4172. .PRIIN          0           100         Primary input (usually TTY)
  4173. .PRIOU          0           101         Primary output (ditto)
  4174. .FHSLF          0        400000         Fork Handle Self (current process)
  4175.  
  4176. When a JSYS has option bits, these have symbols of the form JJ%NNN, where JJ
  4177. denotes which JSYS, and NNN denotes the option.  The % is included to prevent
  4178. confusion with user defined symbols (which should not be of this form), and to
  4179. emphasize that the symbol stands for a JSYS bit.  Examples:
  4180.  
  4181.  
  4182. Symbol    JSYS    Bit   Meaning
  4183. ------    ----    ---   -------
  4184. GJ%NEW    GTJFN    1    Want JFN for a new file.
  4185. GJ%OLD    GTJFN    2    Want JFN for an old (i.e. existing) file.
  4186. OF%RD     OPENF   19    Want to open a file for read access.
  4187. OF%WR     OPENF   20    Want to open a file for write access.
  4188.  
  4189.  
  4190.  
  4191. 4.4. Source/Destination Designators
  4192.  
  4193. Many monitor calls operate on or transmit byte streams; a byte stream is a
  4194. sequence of bytes of some size from 1 to 36 bits, most commonly 7 bit bytes
  4195. (ASCII text) or 36 bit bytes (machine words).  The source or destination of
  4196. these bytes can be any one of several items, including a file, a terminal, or
  4197. a string in the caller's address space.  In these cases, a standard 36-bit
  4198. quantity, called the source/designation designator, is used as a JSYS argument
  4199. to declare the byte stream on which to operate.  It can have various formats;
  4200. these are the most common:
  4201. Monitor Calls                                                         Page 76
  4202.  
  4203.  
  4204.           Value:
  4205. Symbol    Left Half     Right Half      Meaning
  4206. ------    ---------     ----------      -------
  4207. (none)          0        a JFN          Job file number, i.e. a file.
  4208.  
  4209. .PRIIN          0          100          Primary input (usually TTY).
  4210. .PRIOU          0          101          Primary output (usually TTY).
  4211.  
  4212. (none)    reasonable     address        Pointer to beginning of a string
  4213.           left half of                  in the caller's address space.
  4214.           byte pointer.
  4215.  
  4216. (none)     777777        address        Equivalent to 440700,,address,
  4217.                                         i.e. a 7-bit byte pointer.
  4218.  
  4219. The monitor can tell which type of designator is intended either from its
  4220. format or from option settings which you provide.  The last format is provided
  4221. to allow you to write
  4222.  
  4223.  
  4224.         hrroi t1, [asciz/foo/]
  4225.  
  4226. rather than
  4227.  
  4228.         move t1, [point 7, [asciz/foo/]] ; Macro
  4229. or
  4230.         move t1, [440700,,[asciz/foo/]]  ; Midas or Macro
  4231.  
  4232. This saves a memory reference, and it's easier to type.  But it only works for
  4233. JSYS's, not for byte instructions; the JSYS internally translates 777777 in
  4234. the left half of a source/destination designator to 440700.
  4235.  
  4236. Note that JSYS's usually assume that an input byte string in memory (i.e. one
  4237. pointed to by a byte pointer) ends with a zero byte; strings are usually kept
  4238. in memory in this format, which is known as ASCIZ (7-bit ASCII, terminated by
  4239. zero).
  4240.  
  4241.  
  4242.  
  4243. 4.5. Setting up a JSYS Invocation
  4244.  
  4245. You may have noticed that some of the JSYS bits described above fall in the
  4246. left half of the word, while others fall in the right half.  This means that
  4247. to load the AC's with the appropriate bits could require different
  4248. instructions.  Since programs should not depend on the actual values of the
  4249. symbols for JSYS bits, a macro is provided to free you from worrying about
  4250. whether a given symbol is a left-half or right-half quantity:  the macro is
  4251. called MOVX; it translates to the appropriate instruction based on its
  4252. argument, e.g. if
  4253.  
  4254.  
  4255. JS%FOO = bit 35
  4256. JS%BAZ = bit 0,
  4257. () swaps its contents,
  4258. [] specifies the address of the enclosed quantity, and
  4259. ! is the logical OR operator, then:
  4260. Monitor Calls                                                         Page 77
  4261.  
  4262.  
  4263.         movx t1, JS%FOO  (becomes)      movei t1, JS%FOO
  4264.         movx t1, JS%BAZ  (becomes)      movsi t1, (JS%BAZ)
  4265.         movx t1, JS%FOO!JS%BAZ (becomes) move t1, [JS%FOO!JS%BAZ]
  4266.  
  4267. If you would rather avoid movx, you can use the third form; it will always
  4268. work, but it often costs an extra memory reference (and a little more typing).
  4269.  
  4270. One final complication: some JSYS arguments consist of fields which must take
  4271. on certain values.  The desired value must somehow be logically ANDed with a
  4272. mask of 1's that specifies the field.  For instance, the NOUT JSYS (which
  4273. outputs a number according to a format which you specify) accepts as one of
  4274. its arguments, the number of columns in which to print the number.  This field
  4275. happens to be in bits 11-17.  If you want the number to be printed in a field
  4276. of, say, 5 columns, you must put a 5 right-justified in bits 11-17.  This
  4277. field has a name, NO%COL, and it assembles as 000177000000.  It would be hard
  4278. to imagine how to logically AND a 5 with this field at assembly time.
  4279. Fortunately, a macro is provided for this purpose:  FLD(value,mask), which in
  4280. this case would be written FLD(5,NO%COL).  The result here is 000005000000,
  4281. which in turn can be logically ORed with other bits and fields to provide all
  4282. the information needed for the JSYS to return the desired result.
  4283.  
  4284. The FLD and MOVX macros are defined for Macro-20 in SYS:MACSYM.UNV.
  4285.  
  4286. Here's a fullblown example, in which the NOUT JSYS is set up to print a
  4287. number, which is stored at location foo, on the terminal in a field of 5
  4288. characters, usigned, with leading blanks, in base-4 notation.  First, the
  4289. symbol definitions are reproduced from MONSYM:
  4290.  
  4291.  
  4292. Symbol  Bit(s)  Meaning
  4293. ------  ------  -------
  4294. NO%MAG      0   Output the magnitude (i.e. unsigned).
  4295. NO%LFL      2   Output leading filler specified by NO%ZRO.
  4296. NO%ZRO      3   Output 0's as leading filler.
  4297.                  If off, output 1's as leading filler.
  4298. NO%COL  11-17   Number of columns to output.
  4299. NO%RDX  18-35   Radix (2-36) of number being output.
  4300.  
  4301. Now here's the actual JSYS setup and call:
  4302.  
  4303.         movx t1, .PRIOU         ; Output goes to terminal.
  4304.         move t2, foo            ; The number is stored in foo.
  4305.         movx t3, NO%MAG!NO%LFL!fld(5,NO%COL)!fld(4,NO%RDX) ; Format.
  4306.         NOUT                    ; Number Out JSYS.
  4307.          %jserr                 ; Print message and halt on error.
  4308.  
  4309. This should be sufficient background for you to understand the descriptions of
  4310. the specific JSYS's.
  4311.  
  4312.  
  4313.  
  4314. 4.6. JSYS's to Open and Close Files
  4315.  
  4316. A file in Tops-20 is identified by its device name, directory name, filename,
  4317. file type, and generation number.  These 5 items uniquely identify any file on
  4318. the system that is accessible to a user.  The device name identifies the
  4319. device on which the file is stored (or it can be a "logical device name" that
  4320. Monitor Calls                                                         Page 78
  4321.  
  4322. specifies a list of one or more devices and/or directories which is to be
  4323. searched for the file); the directory name identifies the directory containing
  4324. the file.  The filename, type, and generation number identify a particular
  4325. file in the given device and directory.
  4326.  
  4327. Tops-20 requires references to files to be via "handles" that can be contained
  4328. in a few bits (a halfword, really) and do not require extensive lookup
  4329. procedures for each reference.  Such a handle is called a JFN (Job File
  4330. Number); it is a small integer, valid within a particular job (even if the job
  4331. consists of many processes) but not valid across jobs; JFN 2 in job 11 will
  4332. generally be a handle on a completely different file than JFN 2 in job 18.
  4333.  
  4334. A JFN is associated with a file by means of the GTJFN (Get JFN) monitor call,
  4335. which accepts a file specification and returns a JFN for the indicated file.
  4336. The special JFN's 100 ( .PRIIN) and 101 ( .PRIOU) are reserved for the primary
  4337. input and output designators, respectively, and are never returned by the
  4338. GTJFN call.
  4339.  
  4340. To do i/o (input/output) to a file, you must first get a JFN for it, using
  4341. GTJFN.  You must then open the file by giving the JFN to the OPENF JSYS.  Then
  4342. you can use various monitor calls to actually transfer data.  When you are
  4343. finished with the file, you must close it using the CLOSF monitor call.
  4344.  
  4345. These essential monitor calls are now described, but not in complete detail.
  4346. For the more esoteric features, refer to the Monitor Calls Reference Manual.
  4347. The examples shown here are for Macro programs.  In general the only
  4348. difference between Macro and Midas (for these examples) the logical OR
  4349. operator (in Macro, it's "!"; in Midas it's "\")
  4350.  
  4351.  
  4352.  
  4353. 4.6.1. GTJFN (JSYS 20) - Get Job File Number (short form)
  4354.  
  4355. Returns the JFN for the specified file.  Accepts the specification for the
  4356. file from a string in memory or from a file (possibly a terminal) but not
  4357. both.  If the source is the terminal, recognition can be done.  One or more
  4358. fields of the file specification can be represented by a logical name.  If any
  4359. fields are omitted, the system will provide default values as follows:
  4360.  
  4361.  
  4362.   Device  Connected structure.
  4363.   Directory    Connected directory.
  4364.   Name         No default; must be specified.
  4365.   Type         Null.
  4366.   Generation   Highest existing (input file); next higher (output).
  4367.  
  4368. Accepts in AC1: Flag bits in the left half, default generation number
  4369.                 in the right half (usually 0).
  4370.  
  4371.            AC2: Source designator from which to obtain the file
  4372.                 specification (see description of flag bit GJ%FNS).
  4373.  
  4374. Returns:    +1: Failure, error code in AC1.
  4375.  
  4376.             +2: Success, flags in the left half of AC1, and the JFN
  4377.                 in the right.
  4378.  
  4379. Flag bits:
  4380. Monitor Calls                                                         Page 79
  4381.  
  4382. Symbol (Bit(s)) Meaning
  4383.  
  4384. GJ%FOU (0)      (File OUtput) The file given is to be assigned the next higher
  4385.                 generation number; this bit indicates that a new version of a
  4386.                 file is to be created and is normally set if the file is for
  4387.                 output use.
  4388.  
  4389. GJ%NEW (1)      The file specification must not refer to an existing file,
  4390.                 i.e. the file must be a new file.
  4391.  
  4392. GJ%OLD (2)      The file specification given must refer to an existing file,
  4393.                 i.e. the file must be an old file. Note: if you want to open a
  4394.                 file in ' append' mode (i.e. you want to create a new file if
  4395.                 none exists, or else write to the end of an existing file),
  4396.                 don't specify GJ%OLD or GJ%NEW, and use OF%APP in the OPENF
  4397.                 call (see below).
  4398.  
  4399. GJ%CFM (4)       ConFirMation from the user will be required (if GJ%FNS is on)
  4400.                 to verify that the file specification is correct.  This
  4401.                 generally means that the user will have to type carriage
  4402.                 return after typing the file specification.
  4403.  
  4404. GJ%FNS (16)     (File Name Source) The contents of AC2 are to be interpreted
  4405.                 as follows:
  4406.  
  4407.                    1. If this bit is on, AC2 contains an input JFN in the
  4408.                       left half, and an output JFN in the right.  The
  4409.                       input JFN is used to obtain the file specification
  4410.                       to be associated with the JFN.  The output JFN is
  4411.                       used to indicate the destination for printing the
  4412.                       names of any fields being recognized.  To omit
  4413.                       either JFN, specify .NULIO (377777).  This option
  4414.                       is generally used when the file specification is
  4415.                       being obtained from the terminal, and recognition
  4416.                       is being performed.  The JFN's will normally be
  4417.                       .PRIIN and .PRIOU.
  4418.  
  4419.                    2. If this bit is off, AC2 contains a pointer to an
  4420.                       ASCIZ string in memory that specifies the file to
  4421.                       be associated with the JFN.
  4422.  
  4423. GJ%SHT (17)     This bit should always be on to indicate that the long form of
  4424.                 GTJFN is not being used (the long form requires extra input).
  4425.  
  4426. (none) (18-35)  The generation number of the file.  Usually one of the
  4427.                 following:
  4428.  
  4429.                    1. .GJDEF (0) - the normal case - to indicate that the
  4430.                       next higher generation number of the file is to be
  4431.                       used if GJ%FOU is on, or that the highest existing
  4432.                       generation of the file is to be used if GJ%FOU is
  4433.                       off.
  4434.  
  4435.                    2. .GJNHG (-1) - to indicate that the next higher
  4436.                       generation number is to be used if no generation
  4437.                       number is supplied.
  4438.  
  4439. To translate a JFN to its corresponding filename string, see the description
  4440. Monitor Calls                                                         Page 80
  4441.  
  4442. of JFNS in the Monitor Calls Reference Manual.
  4443.  
  4444.  
  4445. Examples:
  4446.  
  4447. ; Get a JFN from a filename string in memory.
  4448.  
  4449.         movx t1, GJ%OLD!GJ%SHT  ; For an "old" file
  4450.         hrroi t2, [asciz/foo.txt/] ; called "foo.txt",
  4451.         GTJFN                   ;  get a Job File Number.
  4452.          %jsErr                 ; Print message and halt on error.
  4453.         hrrzm t1, iJfn          ; Save the JFN in location "ijfn".
  4454.  
  4455. Note the "hrrzm", rather than "movem".  This eliminates the extraneous flags
  4456. that are returned in the left half, which could cause errors in some
  4457. applications that don't need them (most don't).
  4458.  
  4459.  
  4460. ; Get a JFN from the terminal, allowing recognition.
  4461.  
  4462.         movx t1, GJ%OLD!GJ%FNS!GJ%CFM!GJ%SHT ; Old, tty i/o, confirm.
  4463.         move t2, [.PRIIN,,.PRIOU] ; Get filename from terminal.
  4464.         GTJFN                   ; Get the JFN.
  4465.          %jsErr (,err)          ; Print msg & go to "err" on error.
  4466.         hrrzm t1, iJfn          ; Save the result.
  4467.  
  4468.  
  4469.  
  4470. 4.6.2. OPENF (JSYS 21) - Open a File
  4471.  
  4472. Opens the given file.  No data transfer can be done until the file is open.
  4473.  
  4474.  
  4475. Accepts in AC1: JFN of the file being opened, in the right half.
  4476.  
  4477.            AC2: Various control information, including:
  4478.  
  4479. Symbol  Bit(s)  Meaning
  4480. ------  ------  -------
  4481. OF%BSZ   0-5    Byte size (maximum 36 decimal)
  4482. OF%RD      19   Allow read access.
  4483. OF%WR      20   Allow write access.
  4484. OF%APP     22   Allow  append access.
  4485. OF%PLN     30   Disable line number checking and consider a line number
  4486.                  as 5 characters of text.  If this bit is off, line
  4487.                  numbers will be discarded automatically.
  4488.  
  4489. Returns:    +1: Failure, error code in AC1.
  4490.             +2: Success.
  4491.  
  4492. No values are returned.
  4493. Monitor Calls                                                         Page 81
  4494.  
  4495.  
  4496.  
  4497. Example:
  4498.  
  4499. ; Open an old file for read access.
  4500.  
  4501.         move t1, iJfn           ; The JFN already obtained by GTJFN.
  4502.         movx t2, fld(7,OF%BSZ)!OF%RD ; 7-bit bytes, read access desired.
  4503.         OPENF                   ; Open the file.
  4504.          %jsErr (<Can't open the file>,fail) ; Print this message and
  4505.                                 ;  go to location "fail" on error.
  4506.  
  4507.  
  4508.  
  4509. 4.6.3. CLOSF (JSYS 22) - Close a File.
  4510.  
  4511. Closes a specific file.
  4512.  
  4513.  
  4514. Accepts in AC1: Flags, normally 0, in left half, JFN in right half.
  4515.  
  4516. Returns     +1: Failure, error code in AC1.
  4517.             +2: Success.
  4518.  
  4519. No value is returned.
  4520.  
  4521. Flags:
  4522.  
  4523. CO%NRJ (0)      Do not release the JFN.
  4524.  
  4525. CO%ABT (6)      abort any output operations currently being done.  Close the
  4526.                 file, but do not perform any cleanup operations normally
  4527.                 associated with closing a file (e.g. do not output remaining
  4528.                 buffers).  If output to a new disk file that has not been
  4529.                 closed (i.e. is nonexistent) is aborted, the file is closed
  4530.                 and then expunged.
  4531.  
  4532.  
  4533. Example:
  4534.  
  4535. ; Close a file
  4536.  
  4537.         move t1, ijfn           ; Get the JFN into AC1.
  4538.         CLOSF                   ; Close the file.
  4539.          %jsErr (,.+1)          ; On error, print message but continue.
  4540.  
  4541.  
  4542.  
  4543. 4.7. File i/o JSYS's
  4544.  
  4545. There are three ways to do file i/o: by character (byte), by character string
  4546. (byte string), and by page.  Of these, only the first two will be discussed.
  4547. For paged i/o see the Monitor Calls Reference Manual.
  4548.  
  4549. When doing input, whether byte- or string-oriented, you must always be
  4550. prepared to handle errors, and to distinguish a normal end-of-file (eof) error
  4551. from other errors.  A monitor call is provided that can be used for this
  4552. purpose (among others):
  4553. Monitor Calls                                                         Page 82
  4554.  
  4555. 4.7.1. GTSTS (JSYS 24) - Get file Status
  4556.  
  4557. Returns the status of a file associated with a JFN.
  4558.  
  4559. ACCEPTS in AC1: JFN in the right half.
  4560.  
  4561. Returns:    +1: always, with JFN status word in AC2.  If the JFN is
  4562.                 illegal in any way, bit GS%NAM will be 0.
  4563.  
  4564. The JFN Status Word has the following format:
  4565.  
  4566. Symbol  Bit     Meaning
  4567. ------  ---     -------
  4568. GS%OPN   0      File is open.
  4569. GS%RDF   1      Read access is allowed.
  4570. GS%WRF   2      Write access allowed.
  4571. GS%EOF   8      Last read was past end of file.
  4572. GS%NAM  10      A file specification is associated with this JFN.
  4573.  
  4574. If GS%OPN is 0, then the settings of the other bits are meaningless.  There
  4575. are other bits and fields in the JFN Status Word; for these, see the Monitor
  4576. Calls Reference Manual.
  4577.  
  4578. When testing the status word for some (combination of) bit(s), you are faced
  4579. with a situation similar to loading some combination of option bits into an AC
  4580. for a JSYS call, i.e. you don't know (or at least you shouldn't depend on)
  4581. whether the bits form a left-half, right-half, or fullword quantity, and
  4582. therefore you don't know which test instruction to use (tl--, tr--, ts--, or
  4583. td--).  Of course, td-- will always work if you put the argument in square
  4584. brackets, but this requires an extra memory fetch at runtime.  For this
  4585. reason, a set of tx-- macros have been defined that are analogous in purpose
  4586. and operation to the "movx" macro described above.  You can always use a tx--
  4587. without worrying about the actual value of the quantity being tested.  These
  4588. comments apply not just to testing the JFN status word, but to testing any
  4589. word for symbolically defined bits.
  4590.  
  4591. Example (assume that a JSYS error has just occurred during input):
  4592.  
  4593.  
  4594. ; Check for end of file.
  4595.  
  4596.         move t1, iJfn           ; Load the JFN of the input file.
  4597.         GTSTS                   ; Get the status of the file.
  4598.         txnn t2, GS%EOF         ; Are we at eof?
  4599.          jrst error             ;  No, must be some other error.
  4600.  
  4601. ; Come here on end of file.
  4602.  
  4603.  
  4604.  
  4605. 4.7.2. Sequential Byte i/o
  4606.  
  4607. The following JSYS's input or output bytes sequentially.
  4608. Monitor Calls                                                         Page 83
  4609.  
  4610. 4.7.2.1. BIN (JSYS 50) - Byte In
  4611.  
  4612. Inputs the next byte from the specified source.  When the byte is read from a
  4613. file, the file must first be opened, and the size of the byte given, with the
  4614. OPENF call.  When the byte is read from memory, a pointer to the byte is
  4615. given; this pointer is always updated after the call (a BIN to a character
  4616. string in memory is equivalent to an ildb instruction).
  4617.  
  4618.  
  4619. Accepts in AC1: source designator (JFN or byte pointer)
  4620.  
  4621. Returns     +1: always, with the byte right-adjusted in AC2.
  4622.  
  4623. If the end of file is reached, AC2 contains 0 and an erjmp or ercal
  4624. instruction following the BIN call will be activated (but note that end of
  4625. file is not the only error possible).
  4626.  
  4627.  
  4628.  
  4629. 4.7.2.2. PBIN (JSYS 73) - Primary Byte In
  4630.  
  4631. Like BIN, but always obtains the byte from the primary input source (i.e. the
  4632. .PRIIN JFN, usually the terminal).  Needs no input.
  4633.  
  4634. Returns:  +1: always, with byte right-adjusted in AC1.
  4635.  
  4636. Various errors are possible, including end-of-file.
  4637.  
  4638.  
  4639.  
  4640. 4.7.2.3. BOUT (JSYS 51) - Byte Out
  4641.  
  4642. Outputs a byte sequentially to the specified destination.  When the byte is
  4643. written to a file, the file must first be opened, and the size of the byte
  4644. given, with the OPENF call.  When the byte is written to memory, a pointer to
  4645. the location in which to write the byte is given in AC1.  This pointer is
  4646. updated after the call.
  4647.  
  4648. Accepts in AC1: destination designator (JFN or byte pointer).
  4649.  
  4650. Returns +1: always.
  4651.  
  4652. Various errors are possible.
  4653.  
  4654.  
  4655.  
  4656. 4.7.2.4. PBOUT (JSYS 74) - Primary Byte Out
  4657.  
  4658. Like BOUT, except byte always goes to the primary output destination (i.e. the
  4659. .PRIOU JFN, usually the terminal).
  4660.  
  4661. Accepts in AC1: byte to be output, right-justified.
  4662.  
  4663. Returns:  +1: always.
  4664.  
  4665. Various errors are possible.
  4666. Monitor Calls                                                         Page 84
  4667.  
  4668.  
  4669.  
  4670.  
  4671.  
  4672. 4.7.2.5. Example of Byte i/o
  4673.  
  4674.  ; This program segment reads bytes one at a time from a file whose
  4675. ;  JFN is stored in location "iJfn".  If a byte is null (zero), it is
  4676. ;  discarded, otherwise it is written to the output file, whose JFN
  4677. ;  is stored in location "oJfn".  Both files are assumed to be open.
  4678.  
  4679.  
  4680. copy:   move t1, iJfn           ; Load input JFN into t1.
  4681.         BIN                     ; Get next byte.
  4682.          erjmp tstEof           ;  On error, go test for eof.
  4683.         jumpe t2, copy          ; If the character was zero, ignore it.
  4684.         move t1, oJfn           ; Load output jfn into t1.
  4685.         BOUT                    ; Write the byte to the output file.
  4686.          %jsErr                 ;  Print message and halt on error.
  4687.         jrst copy               ; Loop for all bytes in file.
  4688.  
  4689. ; Come here on error in the BIN JSYS.  Check for end of file.
  4690.  
  4691. tsteof: GTSTS                   ; JSYS to Get file Status (JFN is in t1).
  4692.         txnn t2, GS%EOF         ; Was it an eof?
  4693.          %erMsg (,done)         ;  No, print the error message and finish up.
  4694.  
  4695. ; Here when we've copied the entire file.
  4696.  
  4697. done:   move t1, iJfn           ; Close the input file
  4698.         CLOSF                   ;  using the CLOSF JSYS.
  4699.          %jsErr (,.+1)          ; On error, print message but continue.
  4700.  
  4701.         move t1, ojfn           ; And close the ouput file too.
  4702.         CLOSF
  4703.          %jsErr (,.+1)
  4704.  
  4705. ; End of program fragment.
  4706.  
  4707. Note the %erMsg macro; it is identical to %jsErr, except that it is executed
  4708. unconditionally rather than via erjmp or ercal.  It is mainly intended for use
  4709. after a skipping instruction or subroutine call.
  4710.  
  4711.  
  4712.  
  4713. 4.7.3. String-oriented i/o
  4714.  
  4715. The following JSYS's input or output byte strings.
  4716.  
  4717.  
  4718.  
  4719. 4.7.3.1. SIN (JSYS 52) - String In
  4720.  
  4721. Reads a string from the specified source into the caller's address space.  The
  4722. string can be a specified number of bytes or terminated with a specified byte.
  4723. Monitor Calls                                                         Page 85
  4724.  
  4725.  
  4726. Accepts in AC1: Source designator (JFN or byte pointer).
  4727.  
  4728.            AC2: Pointer to string in the caller's address space (destination).
  4729.  
  4730.            AC3: Count of number of bytes to input, or 0.
  4731.  
  4732.            AC4: Byte (right-justified) on which to terminate input (optional).
  4733.  
  4734. Returns:    +1: Always, with updated string pointers in AC1 and AC2
  4735.                 (if pertinent), and updated count in AC3 (if pertinent).
  4736.  
  4737. The contents of AC3 controls the number of bytes to read as follows:
  4738.  
  4739. AC3=0           The string being read is terminated with a 0 byte.
  4740.  
  4741. AC3>0           A string of the specified number of bytes is to be read or a
  4742.                 string terminated with the byte given in AC4 is to be read,
  4743.                 whichever occurs first.
  4744.  
  4745. AC3<0           A string of minus the number of bytes is to be read.
  4746.  
  4747. AC4 is ignored unless AC3 contains a positive number.
  4748.  
  4749. An end of file can be processed as in the example above.  After execution of
  4750. the call, the file's pointer is updated for subsequent i/o to the file.  AC2
  4751. is updated to point to the last byte read or, if AC3 contained 0, the last
  4752. nonzero byte read.  The count in AC3 is updated toward 0 by subtracting the
  4753. number of bytes read from the number of bytes requested to be read.  If the
  4754. input was terminated by an end-of-file condition, AC1 thru AC3 are updated
  4755. (where pertinent) to reflect the number of bytes transferred before the end of
  4756. file was reached.
  4757.  
  4758. Various errors, besides eof, are possible (e.g. invalid JFN, file not open,
  4759. device or data error, etc.).
  4760.  
  4761.        Note:  The source JFN can be .PRIIN (i.e. the terminal), but SIN is
  4762.     not the best JSYS to use for input of strings from the terminal,
  4763.     because it does not allow for editing (via DEL, ^U, ^W, and ^R) or
  4764.     prompting.  Terminal string input is best done using the TEXTI or
  4765.     RDTTY JSYS (RDTTY is described below); better still, all terminal
  4766.     input can be done using the COMND JSYS (Chapter 5), which allows not
  4767.     only prompting and editing, but automatic help and recognition, as
  4768.     well as syntax checking for all sorts of fields (numbers, file names,
  4769.     keywords, etc).  For TEXTI and COMND, refer to the Monitor Calls
  4770.     Reference Manual.
  4771.  
  4772.  
  4773.  
  4774. 4.7.3.2. SOUT (JSYS 53) - String Out
  4775.  
  4776. Writes a string from the caller's address space to the specified destination.
  4777. The string can be a specified number of bytes or terminated with a specified
  4778. byte.
  4779. Monitor Calls                                                         Page 86
  4780.  
  4781.  
  4782. Accepts in AC1: Destination designator.
  4783.  
  4784.            AC2: Pointer to string to be written.
  4785.  
  4786.            AC3: Count of the number of bytes to be written, or 0.
  4787.  
  4788.            AC4: Byte (right-justified) on which to terminate output.
  4789.  
  4790.  
  4791. Returns:    +1: Always, updated string pointers and counts in the
  4792.                 AC's, if pertinent.
  4793.  
  4794. Interpretation of the arguments is exactly the same as by SIN, and the
  4795. operation is entirely analogous, but in the opposite direction.
  4796.  
  4797.  
  4798.  
  4799. 4.7.3.3. PSOUT (JSYS 76) - Primary String Out
  4800.  
  4801. A short form of SOUT (there is no corresponding short form of SIN).  Outputs a
  4802. string sequentially to the primary output destination (usually the terminal).
  4803.  
  4804.  
  4805. Accepts in AC1: Pointer to ASCIZ (zero-terminated) string in the
  4806.                 caller's address space.
  4807.  
  4808. Returns:    +1: Always, with updated string pointer in AC1.
  4809.  
  4810. As usual, various errors are possible (usually an invalid byte pointer is the
  4811. culprit).
  4812. Monitor Calls                                                         Page 87
  4813.  
  4814. 4.7.3.4. Example of String I/O
  4815.  
  4816. This program fragment copies the input file (which is already opened in 7-bit
  4817. mode and whose JFN is stored in location "iJfn") to the output file (open
  4818. similarly, JFN in "oJfn"), a string at a time, where a string is considered to
  4819. be a sequence of bytes terminated by a linefeed, but of maximum lenth 512
  4820. (decimal).  Note that the linefeed character is represented symbolically; this
  4821. is considered good technique because it makes the program more readable.  The
  4822. symbolic definitions of the (nonprinting) ASCII control characters are
  4823. obtained by searching MACSYM.
  4824.  
  4825.  
  4826. maxLen=^d512                    ; Define maximum length symbolically.
  4827.  
  4828. buffer: block <maxlen/5+1>      ; String buffer (convert bytes to words).
  4829.           :
  4830.           :
  4831. copy:   move t1, iJfn           ; Load the input file JFN.
  4832.         hrroi t2, buffer        ; Point to place in memory to put string.
  4833.         movei t3, maxLen        ; Maximum number of characters.
  4834.         movei t4, .CHLFD        ; Terminate on the CHaracter LineFeeD.
  4835.         SIN                     ; Read the string into the buffer.
  4836.          erjmp tstEof           ;  On error, go test for eof.
  4837.  
  4838. ; Now write the string into the output file.  Note that t3 contains
  4839. ;  <maxlen - <length of string>>.  We can't count on the presence of the
  4840. ;  terminating linefeed because input may have exhausted the maximum byte
  4841. ;  count before a linefeed was encountered.
  4842.  
  4843.         move t1, oJfn           ; Load the output file JFN.
  4844.         hrroi t2, buffer        ; Point to the string to be written.
  4845.         subi t3, maxLen         ; Get negative length into t3.
  4846.         SOUT                    ; Write the string out.
  4847.          %jserr (,done)         ;  Print message and finish up on error.
  4848.  
  4849.         jrst copy               ; Loop for all strings in file.
  4850.  
  4851. tstEof: GTSTS                   ; JFN of input file already in t1.
  4852.         txnn t2, GS%EOF         ; Error caused by end of file?
  4853.          %ermsg (,done)         ;  No, print message and finish up.
  4854.  
  4855. done:   hrroi t1, [asciz /All done/] ; Type this message
  4856.         PSOUT                   ;  at the terminal.
  4857.  
  4858. ; Now just close the files in the normal way.
  4859.  
  4860. ; (end of program fragment)
  4861.  
  4862.  
  4863.  
  4864. 4.7.3.5. RDTTY (JSYS 523) - Read string interactively from TTY
  4865.  
  4866. RDTTY is the JSYS most suited to simple terminal input; it is a subset of the
  4867. TEXTI JSYS, which is much more flexible, more powerful, but more complicated
  4868. to use (see the Monitor Calls Reference Manual for details on TEXTI and full
  4869. Monitor Calls                                                         Page 88
  4870.  
  4871. details on RDTTY).  We will describe the most useful options of the RDTTY
  4872. JSYS.
  4873.  
  4874. RDTTY is most suited for interactive terminal input because it lets the user
  4875. edit her/his input, on a line-by-line (or several-line) basis, before it's
  4876. "eaten" by the program.  All the editing characters, viz., ^R, ^W, ^U, ^L, and
  4877. RUBOUT, are available for editing (though no recognition is possible, since
  4878. command parsing is not being done).  There are basically two ways to call
  4879. RDTTY: to read a single line (up to a carriage-return or line-feed), and to
  4880. read a whole group of lines (up to a ^Z or ESCAPE).  In the single-line mode,
  4881. the program receives each line as the user types it, and thus only permits
  4882. editing on a single-line basis; in the line-group mode, the user can enter any
  4883. number of lines (limited only by the size of your input buffer) and edit all
  4884. the way back to the beginning of input (for example, MM and Mail use the
  4885.                                                             1
  4886. line-group mode to collect the text of messages to be sent).
  4887.  
  4888. The RDTTY JSYS reads input from the primary input port ( .PRIIN), until either
  4889. a break character is seen (such as ^Z or carriage-return) or the given byte
  4890. count is exhausted (which means your buffer is full).  Output generated as a
  4891. result of editing the input text (such as echoing of deleted characters after
  4892. backslashes, as in "foo<RUBOUT><RUBOUT>ee", which echoes as "foo\o\oee" on a
  4893. hardcopy terminal) goes to the primary output port (.PRIOU).  .PRIIN and
  4894. .PRIOU normally designate the user's terminal (TTY) as an both input and
  4895. output device, respectively.
  4896.  
  4897.  
  4898. Accepts in AC1: pointer to string in caller's address space where
  4899.                 input is to be placed.
  4900.  
  4901.            AC2: control bits in left half, as described below, and
  4902.                 number of bytes available in the buffer (pointed to
  4903.                 by AC1) in the right half.
  4904.  
  4905.            AC3: 0, if no prompt is wanted, or
  4906.                 byte pointer to prompting text (^R) buffer.
  4907.  
  4908. Returns:    +1: failure, error code is in AC1.
  4909.             +2: success, updated string pointer in AC1, appropriate
  4910.                 bits set in the left half of AC2, and updated count of
  4911.                 available bytes in the right half of AC2.
  4912.  
  4913.  
  4914. Note that the prompting text buffer is not automatically output by RDTTY; you
  4915. have to output it yourself before doing the RDTTY (but it will be output
  4916. properly if ^R or ^L is typed during user input).
  4917.  
  4918. The control flags in the left half of AC2 are broken into two groups:  those
  4919. given to RDTTY, and those returned (see the Monitor Calls Manual for a
  4920.  
  4921. ---------------
  4922.   1
  4923.    If you need to read in a group of text lines, even a large group, it's
  4924. advisable to use the the line-group mode of RDTTY, since memory is 'cheap':
  4925. just give RDTTY a large buffer area; this makes things much easier for the
  4926. poor, fallible human out there.
  4927. Monitor Calls                                                         Page 89
  4928.  
  4929. complete description of the control flags).
  4930.  
  4931. Symbol (Bit(s)) Meaning
  4932.  
  4933. Given to RDTTY in AC2:
  4934.  
  4935. RD%BRK (0)      BReaK on ^Z or ESCAPE (i.e., line-group mode)
  4936.  
  4937. RD%BEL (3)      Break on End of Line (carriage return or linefeed, i.e.,
  4938.                 single-line mode)
  4939.  
  4940. RD%RAI (10)     RAIse user input: convert lower case to upper case
  4941.  
  4942. Returned from RDTTY in AC2:
  4943.  
  4944. RD%BTM (12)     Break character TerMinated input: if this is set, the input
  4945.                 was terminated because a break character was seen; if not,
  4946.                 then input was terminated because the buffer is full (as
  4947.                 determined by the byte count given in the right half of AC2)
  4948.  
  4949.  
  4950.  
  4951. 4.7.3.6. RDTTY Example
  4952.  
  4953. The following example uses the RDTTY JSYS to collect a "note", or a group of
  4954. lines about some subject, and write it all to a file (which is opened and
  4955. closed elsewhere).
  4956.  
  4957.  
  4958. ; Data area
  4959.  
  4960. maxLen==^d10000                 ; Allow 10k characters in note input.
  4961. prompt: asciz/Text of note (end with ^Z or ESCAPE): /
  4962.  
  4963. inBuf:  block maxLen/5 + 1      ; Input buffer.
  4964. oJfn:   block 1                 ; Output JFN.
  4965.           .
  4966.           .
  4967.           .
  4968. Monitor Calls                                                         Page 90
  4969.  
  4970.  
  4971. ; Assume oJfn is set up with the output file JFN.
  4972.  
  4973. note:   hrroi t1, prompt        ; Prompt for the note.
  4974.         PSOUT                   ;  ...
  4975.  
  4976.         hrroi t1, inBuf         ; Get a pointer to destination buffer.
  4977.         movx t2, <RD%BRK!maxLen> ; Break on ^Z, ESC, up to buffer size.
  4978.         hrroi t3, prompt        ; Use prompt on ^R, etc.
  4979.         RDTTY                   ; Read the note.
  4980.          %jsErr                 ; Die loudly if fails.
  4981.  
  4982.         hrrz t3, t2             ; Get remaining byte count.
  4983.         movns t3                ; Negate it and add to maxLen to get
  4984.         add t3, [maxLen]        ;  number of bytes input.
  4985.         hrroi t1, inBuf         ; What we want to output.
  4986.         move t2, oJfn           ; Get destination JFN,
  4987.         SOUT                    ;  and output what we just read.
  4988.          %jsErr                 ; Handle failure nicely.
  4989.           .
  4990.           .
  4991.  
  4992.  
  4993.  
  4994.  
  4995. 4.7.4. Number conversion JSYS's
  4996.  
  4997. These are similar to string i/o JSYS's in that their input or output is a
  4998. string (in memory or in a file), but the string is the ASCII character
  4999. representation of a number in some base, and conversion is done either from
  5000. the internal form of the number to the string or vice versa.
  5001.  
  5002.  
  5003.  
  5004. 4.7.4.1. NIN (JSYS 225) - Number In
  5005.  
  5006. Inputs the character-string representation of an integer number, ignoring
  5007. leading spaces.  This call terminates on the first character not in the
  5008. specified radix.  If that character is a carriage return followed by a line
  5009. feed, the line feed is also input.
  5010.  
  5011.  
  5012. Accepts in AC1: Source designator (JFN or byte pointer).
  5013.  
  5014.            AC3: Radix (2-10) of number being input.
  5015.  
  5016. Returns:    +1: Failure, error code in AC3, updated string pointer
  5017.                 (if pertinent) in AC1.
  5018.  
  5019.             +2: Success, internal two's complement binary representation
  5020.                 of number in AC2, and updated string pointer (if
  5021.                 pertinent) in AC1.
  5022.  
  5023. Various errors are possible (invalid JFN, file not open, invalid radix, first
  5024. nonspace character not a digit, overflow, etc.).  It is not advisable to use
  5025. NIN to input a number from the terminal because NIN does not allow editing and
  5026. reprompting, as does RDTTY; RDTTY should be used to get the string
  5027. representation of the number into memory, and then NIN should be used to
  5028. Monitor Calls                                                         Page 91
  5029.  
  5030. convert the string to a number; if the string contains invalid characters, the
  5031. error can be caught and the user can be informed and reprompted (by a
  5032. %jsErr (,foo) after the NIN, where foo is the address of the RDTTY sequence).
  5033. This technique is shown in a subsequent example.
  5034.  
  5035.  
  5036.  
  5037. 4.7.4.2. NOUT (JSYS 224) - Number Out
  5038.  
  5039. Outputs an integer number to a file or to a string in memory.
  5040.  
  5041.  
  5042. Accepts in AC1: Destination designator.
  5043.  
  5044.            AC2: Number to be output.
  5045.  
  5046.            AC3: Format control information as follows:
  5047.  
  5048. Symbol (bit(s)) Meaning
  5049.  
  5050. NO%MAG (0)      Output the magnitude.  That is, output the number as an
  5051.                 unsigned 36-bit number (e.g. output -1 as 777777777777 in base
  5052.                 8).
  5053.  
  5054. NO%SGN (1)      Output a plus sign for a positive number.
  5055.  
  5056. NO%LFL (2)      Output leading filler.  If this bit is not set, trailing
  5057.                 filler is output, and bit NO%ZRO is ignored.
  5058.  
  5059. NO%ZRO (3)      Output 0's as the leading filler if the specified number of
  5060.                 columns (NO%COL) allows filling.  If this bit is not set,
  5061.                 blanks are output as leading filler if the number of columns
  5062.                 allows filling.
  5063.  
  5064. NO%OOV (4)      Output on column overflow and return an error.  If this bit is
  5065.                 not set, column overflow is not output.
  5066.  
  5067. NO%AST (5)      Output asterisks on column overflow.  If this bit is not set
  5068.                 and NO%OOV is set, all necessary digits are output on column
  5069.                 oveflow.
  5070.  
  5071. NO%COL (11-17)  Number of columns (including the sign column) to output is
  5072.                 right-justified in this field.  If this field is 0, as many
  5073.                 columns as necessary are output.
  5074.  
  5075. NO%RDX (18-35)  Radix (2-36) of number being output.
  5076.  
  5077. Returns:        +1: Failure, error code in AC3.
  5078.  
  5079. +2: Success, updated string pointer in AC1, if pertinent.
  5080.  
  5081. Various errors are possible, including NOUTX2 (column overflow), plus those
  5082. that are possible for NIN.
  5083. Monitor Calls                                                         Page 92
  5084.  
  5085. 4.7.4.3. NIN/NOUT Example
  5086.  
  5087. Here, the user is prompted at the terminal to type in a decimal number.  The
  5088. number is then typed back to the user, in octal (base 8) notation,
  5089. right-adjusted in a field of width 9.
  5090.  
  5091.  
  5092. prompt: asciz /Decimal number: / ; The prompt.
  5093. numLen=^d20                     ; Length of buffer for number string.
  5094. numBuf: block numLen            ; The input buffer.
  5095.         :
  5096.         :
  5097. reTry:  hrroi t1, prompt
  5098.         PSOUT                   ; Prompt the user for a decimal number.
  5099.  
  5100. ; Get the alleged number from the terminal into memory in string form.
  5101.  
  5102.         hrroi t1, numBuf        ; Point to buffer for string that user types.
  5103.         movx t2, RD%BEL!numLen  ; Break on CRLF, max length for typein.
  5104.         hrroi t3, prompt        ; Reprompting text.
  5105.         RDTTY                   ; Get string, allowing editing.
  5106.          %jsErr (,reTry)        ; Print message & reprompt on error.
  5107.  
  5108. ; Now convert the string to a number.
  5109.  
  5110.         hrroi t1, numBuf        ; Point to string representation of number.
  5111.         movei t3, ^d10          ; Radix for interpretation.
  5112.         NIN                     ; Number In - do the conversion.
  5113.          %jsErr (,reTry)        ; On error, print msg and ask again.
  5114.  
  5115. ; Now type it back, converting to octal notation.  The number is still in t2.
  5116.  
  5117.         movx t1, .PRIOU         ; Output is to primary output destination.
  5118.         movx t3, NO%MAG!NO%LFL!NO%AST!fld(^d9,NO%COL)!fld(^d8,NO%RDX)
  5119.         NOUT                    ; Type the number.
  5120.          %jserr (,prompt)       ;  On error, print message and reprompt.
  5121.  
  5122. ; (end of program fragment)
  5123.  
  5124. Similar monitor calls ( FLIN and FLOUT) exist for input and output of floating
  5125. point numbers; see the Monitor Calls Reference Manual for these.
  5126. Monitor Calls                                                         Page 93
  5127.  
  5128. 4.7.5. Random-access i/o
  5129.  
  5130. Tops-20 gives you the ability to randomly access files on disk storage, which
  5131. is the only kind of device which supports this type of access (other than
  5132. DECtape, which is now essentially defunct in "DEC land").
  5133.  
  5134. As described earlier, disk files can be considered to be merely a sequence of
  5135. bytes, of some size from 1 to 36 bits (the normal sizes are 7, for text files,
  5136. and 36, for binary, word-oriented files); the byte size of the file is
  5137. determined at the time of the OPENF for the file (and can thus be changed from
  5138. open to open, if you're daring).  Each byte in the file has a label, or index,
  5139. which is its position in the sequence, starting at zero.  For example, the
  5140. text file containing the 15 ascii bytes "This is a file." can be considered to
  5141. be a sequence of bytes, as follows:
  5142.  
  5143.     Index   Byte  Value             Index   Byte  Value
  5144.       0     "T"    124                8     "a"    141
  5145.       1     "h"    150                9     " "    040
  5146.       2     "i"    151               10     "f"    146
  5147.       3     "s"    163               11     "i"    151
  5148.       4     " "    040               12     "l"    154
  5149.       5     "i"    151               13     "e"    145
  5150.       6     "s"    163               14     "."    056
  5151.       7     " "    040
  5152.  
  5153. For example, the zero'th byte of the file is an ascii "T" (octal value 124),
  5154. the tenth byte is an ascii "f" (octal value 146), and the fourteenth, and
  5155. last, byte is a period, "." (octal value 056).
  5156.  
  5157. Although it's not important to understanding the notion of random-access i/o,
  5158. it's culturally interesting to note that disk files are stored in units of
  5159. pages, or 512 36-bit words, or 2560 (512*5) 7-bit bytes.  Thus, the above
  5160. file, which is 15 bytes long, would occupy 3 (15/5) words, or one page.  Why
  5161. one page?  Because pages are the minimum unit of disk file storage, and thus,
  5162. the above file is "wasting" 509 words of disk space (this much of the one page
  5163. it uses is unoccupied).  The 512 words-per-page is a hardware parameter, which
  5164. we can't do much about, so we'll accept this waste as reasonable, since files
  5165. are generally many pages in length (and the wasted portion is then
  5166. proportionally smaller).
  5167.  
  5168. Tops-20 keeps track of two items, when you're doing i/o with disk files:  the
  5169. current byte index (the one you would read next if you did a BIN JSYS, or
  5170. write next if you did a BOUT), known in JSYS jargon as the 'file pointer', and
  5171. the end-of-file byte index, which is simply the length of the file, in bytes
  5172. (and is thus, conceptually, the non-existent byte after the last byte in the
  5173. file).
  5174.  
  5175. When you first open the file (with an OPENF), the file pointer is set
  5176. depending on how you opened the file.  If you opened it for reading or writing
  5177. (or both), then the file pointer will be zero, i.e., you're initially
  5178. positioned to read or write the first (zero'th) byte in the file.  If you
  5179. opened it for appending, then the file pointer is initially set to the
  5180. end-of-file byte index, i.e., you're positioned to read or write the byte
  5181. right after the last real byte in the file; in the case of a BIN this first
  5182. read will return a zero byte and indicate you're at end of file; in the case
  5183. of a BOUT this first write will simply extend the file by one byte.
  5184.  
  5185. For example, if you had done 15 BIN JSYS's on the sample file shown above
  5186. Monitor Calls                                                         Page 94
  5187.  
  5188. after opening it, on the 16th BIN you would be at end-of-file (i.e., there are
  5189. no more bytes to read), and Tops-20 would obey an erjmp instruction after the
  5190. BIN, going to where you specified (which would presumably check for a true
  5191. end-of-file condition and handle it appropriately).  For a more graphic
  5192. example, after 10 BIN's, say, then the situation looks like:
  5193.  
  5194.     Index   Byte  Value
  5195.       0     "T"    124      <- byte read on the first BIN
  5196.       :      :      :
  5197.       8     "a"    141
  5198.       9     " "    040      <- byte just read on the 10th BIN
  5199.      10     "f"    146      <- file pointer (what will be
  5200.      11     "i"    151          read by the next BIN)
  5201.      12     "l"    154
  5202.      13     "e"    145
  5203.      14     "."    056
  5204.      15      -none-         <- end-of-file byte index
  5205.  
  5206. Thus, as mentioned in the previous example, when the file pointer becomes
  5207. equal to the end-of-file byte index (15 in this example), end-of-file is said
  5208. to be "reached".  Of course, if you're writing a file, then the end-of-file
  5209. byte index is normally the same as the file pointer, since the file pointer
  5210. indexes the next byte to be read or written.
  5211.  
  5212. Of course, you can mix random-access i/o with sequential i/o in any old way,
  5213. and the results are very well-defined.  The SFPTR JSYS simply sets the file
  5214. pointer to the next byte to be read or written; once it's set, you can merrily
  5215. BIN, BOUT, SIN and SOUT, and they'll take place at the file pointer position,
  5216. updating the pointer appropriately.  Using the sample file from before,
  5217. imagine that you've done a SFPTR to the 4th byte (which is the space after
  5218. "This" - why isn't it the "s" in "This"?).  Then, suppose you do a BOUT of a
  5219. "-" character to the file.  The resulting situation will be:
  5220.  
  5221.     Index   Byte  Value
  5222.       0     "T"    124
  5223.       1     "h"    150
  5224.       2     "i"    151
  5225.       3     "s"    163
  5226.       4     "-"    055      <- file pointer after the SFPTR
  5227.       5     "i"    151      <- file pointer after the BOUT
  5228.       6     "s"    163
  5229.       :      :      :
  5230.  
  5231. In a more 'cultural' vein, again, you should know that Tops-20 considers a
  5232. disk file to be a completely extensible sequence of bytes, i.e., it is
  5233. possible, and quite easy, to extend a file by simply positioning to the
  5234. end-of-file position (with the SFPTR JSYS, as described below) and writing
  5235. more bytes with BOUTs or SOUTs.  The end-of-file byte index will be updated
  5236. appropriately.  Even more, it's possible to position the file pointer to some
  5237. point way beyond the end-of-file index, and write more bytes.  The file will
  5238. simply be extended appropriately with zero bytes, up to the point at which you
  5239. started writing (technically speaking, there may be some 'holes' in the file,
  5240. but they will look like zero, or null, bytes when you read over them; they
  5241. only matter if you don't like nulls, or are doing your own direct disk page
  5242. manipulation).  For example, given the sample file above, if you positioned to
  5243. the 20th byte (which doesn't exist yet), and wrote the byte string "more.",
  5244. then the file would simply be extended, resulting in a file with 25 bytes,
  5245. with the end-of-file and file pointer equal to 25, and with the file
  5246. Monitor Calls                                                         Page 95
  5247.  
  5248. containing
  5249.  
  5250.             This is a file.<0><0><0><0><0>more.
  5251.  
  5252. where the <0>'s represent null (zero) bytes.
  5253.  
  5254. There are basically four JSYS's designed for dealing with disk files in a
  5255. random (not purposeless!) fashion: read the current file pointer for a file
  5256. (RFPTR), set the file pointer for a file (SFPTR), read a byte from a file,
  5257. given its index (RIN, for Random IN), and write a byte to a file, given the
  5258. desired byte index (ROUT, for Random OUT).
  5259.  
  5260.  
  5261.  
  5262. 4.7.5.1. RFPTR (JSYS 43) - Read File Pointer
  5263.  
  5264. Returns the current file pointer of the specified file.
  5265.  
  5266.  
  5267. Accepts in AC1: JFN of an open file.
  5268.  
  5269. Returns:    +1: Failure, error code in AC1.
  5270.             +2: Success, byte number (index) in AC2.
  5271.  
  5272.  
  5273. Actually, you can read the file pointer of a non-disk file, but it is either
  5274. meaningless or the number of bytes read so far from the file (e.g., in a tape
  5275. file).  RFPTR can fail in various ways, but only if you don't give it a valid
  5276. JFN for an open file.
  5277.  
  5278.  
  5279.  
  5280. 4.7.5.2. SFPTR (JSYS 27) - Set File Pointer
  5281.  
  5282. Sets the specified file's file pointer for subsequent i/o to the file.  Note
  5283. that doing an SFPTR specifying a certain byte index, followed by a BIN or BOUT
  5284. JSYS, is the same as doing a RIN or ROUT JSYS, respectively, specifying the
  5285. same byte index.
  5286.  
  5287.  
  5288. Accepts in AC1: JFN of an open disk file.
  5289.  
  5290.            AC2: byte index to which the file pointer is to be set,
  5291.                 or, -1 to set the pointer to the current end-of-file
  5292.                 index.
  5293.  
  5294. Returns:    +1: failure, error code in AC1.
  5295.             +2: success, file pointer has been set.
  5296.  
  5297.  
  5298. The SFPTR JSYS can fail in various ways, but only if you don't give it a valid
  5299. disk file JFN.
  5300. Monitor Calls                                                         Page 96
  5301.  
  5302. 4.7.5.3. RIN (JSYS 54) - Random byte In
  5303.  
  5304. Inputs a byte nonsequentially (i.e., random byte input) from the specified
  5305. file.  The size of the byte is that given in the OPENF call for the file.
  5306.  
  5307.  
  5308. Accepts in AC1: JFN of an open disk file.
  5309.  
  5310.            AC2: byte index within the file of the byte desired.
  5311.  
  5312. Returns:    +1: always, with the byte right-justified in AC2.
  5313.  
  5314.  
  5315. If the end of file is reached (i.e., you specify a byte index greater than or
  5316. equal to the end-of-file index), a zero is returned in AC2; this is not really
  5317. an error condition, but you can catch it if you want to with an erjmp or ercal
  5318. after the RIN.  The file's file pointer is updated for subsequent sequential
  5319. i/o to the file.  Several errors are possible, but not if you give it a real
  5320. JFN for a file opened in (at least) read mode (unless the file is opened for
  5321. append access only, in which case you can't change the file pointer, to avoid
  5322. letting you read the part of the file you're not supposed to see, e.g., a
  5323. mail.txt file with protection 770404).
  5324.  
  5325.  
  5326.  
  5327. 4.7.5.4. ROUT (JSYS 55) - Random byte Out
  5328.  
  5329. ROUT outputs a byte nonsequentially (i.e., random byte output) to the
  5330. specified file.  The size of the byte is that given in the OPENF call for the
  5331. file.
  5332.  
  5333.  
  5334. Accepts in AC1: JFN for an open disk file.
  5335.  
  5336.            AC2: the byte to be output, right-justified.
  5337.  
  5338.            AC3: the byte index within the file at which to write
  5339.                 the byte in AC2.
  5340.  
  5341. Returns:    +1: always, with the byte written in the file.
  5342.  
  5343.  
  5344. The file byte pointer after the ROUT is C(AC3)+1 (i.e., the file pointer is
  5345. set to C(AC3), the byte is written, and the file pointer updated to account
  5346. for the byte just written).  ROUT will always succeed if you give it a JFN for
  5347. a disk file opened for writing and ask it to write at a nonnegative byte index
  5348. that is less than the upper limit for the disk (you can have at most 512*512
  5349. pages (or 512*512*512 36-bit bytes) in a file); also, it may fail if you try
  5350. to ROUT to a file opened in append-only mode (because that would allow you to
  5351. change parts of a file you weren't supposed to access, such as a mail.txt file
  5352. protected at 770404).
  5353. Monitor Calls                                                         Page 97
  5354.  
  5355. 4.8. Fork-Handling JSYS's
  5356.  
  5357.  
  5358.  
  5359. 4.8.1. What's in a Fork?
  5360.  
  5361. To effectively use machine language on the DEC-20, you have to understand
  5362. something about what programs are, how they are born, how they live, and how
  5363. they die.
  5364.  
  5365. The term 'program' can be understood in many ways; most intuitively, because
  5366. it's in the form that we understand more easily, it means a text file in some
  5367. source language, such as Macro-20 or Pascal.  But, this textual form of the
  5368. program must be processed by a translator (an assembler or compiler) to
  5369. produce a form more palatable to the actual machine.  Even in this form, which
  5370. is normally a '.REL' or relocatable file, it isn't quite understandable to the
  5371. machine.  It needs to go a further step, called linking, which involves
  5372. combining it with any other program segments which it needs to interact with
  5373. during execution by the machine (such as a language support package for doing
  5374. input/output, etc.).  Once it's linked, the result can be saved as an '.EXE'
  5375. or executable file.
  5376.  
  5377. An executable file is nothing more than a program in vestigial or 'pure
  5378. potential' form, i.e., a data file with contents specifying how memory is to
  5379. be filled when it is incarnated as an active, or executing, program.  We can
  5380. distinguish between a program in this passive state (the result of compiling,
  5381. linking and saving), from a program actually in execution by the Tops-20
  5382. system.  Using this distinction, we can properly call the passive element
  5383. --the EXE file-- the 'program', and the active element --the part that
  5384. executes the program-- the 'process' or 'fork' (the latter is jargon used when
  5385. dealing with Tops-20 processes).
  5386.  
  5387. It may be helpful to think of the fork as a self-contained machine with a
  5388. well-defined 'control panel', or interface to the outside world.  This control
  5389. panel has a set of 'knobs' for controlling it and objects which are dealt with
  5390. via 'handles'; the knobs and handles are manipulated by other forks, via
  5391. JSYS's.  A fork, considered in this way, is a machine with power to follow
  5392. instructions, which come from the passive program (EXE file); a fork is loaded
  5393. up with its instructions by pulling in the program's pages from the EXE file.
  5394. Then, it can be started, temporarily stopped (frozen), continued, stopped,
  5395. etc.  There also must be a way to create and destroy these fork machines, and
  5396. there is.  The fork can, under its own power, follow the program's
  5397. instructions and stop itself (it can't start itself, for obvious reasons).
  5398.  
  5399. From the time a fork is created until it is annihilated, it is necessarily in
  5400. some 'state', just like any good mechanical machine:  stopped, running,
  5401. waiting for something external to it to happen, etc.
  5402.  
  5403. A Tops-20 job is nothing more than a related collection of forks; since a fork
  5404. can only come into existence by being created by another fork, each fork has a
  5405. superior fork (which created it) and some number of inferior forks (which it
  5406. created).  It's also helpful to think of a fork's superior as its parent and
  5407. its inferiors as its children.  The top-level fork in each job (which has no
  5408. superior) is the Tops-20 EXECutive command processor, which is responsible for
  5409. creating other forks and running programs in them.  The EXEC is thus the
  5410. super-parent fork in each job, and is created by Tops-20 when you type a
  5411. control-C on an unlogged-in terminal.  In a graphic form, suppose you've
  5412. logged in and have run EMACS as a kept editor, written a program, gotten out
  5413. Monitor Calls                                                         Page 98
  5414.  
  5415. of EMACS and started to compile it with MIDAS.  At this point, your job's fork
  5416. structure looks like:
  5417.  
  5418.  
  5419.                      (W: Your EXEC fork)
  5420.                         /    #0
  5421.                        /      |
  5422.                       /       |
  5423.             (H: EMACS)    (R: MIDAS)
  5424.                 #1            #2
  5425.  
  5426.  
  5427.  
  5428. For convenience' sake, we label the forks with numbers (in the order in which
  5429. they were created).  In fork #2, the MIDAS EXE file is being executed (R:
  5430. means running), and fork #1, containing the EMACS EXE and various TECO files,
  5431. is temporarily halted (H: means halted), since you're not using it currently.
  5432. The EXEC fork, fork #0, is waiting for the MIDAS fork to halt itself before
  5433. going on and prompting you for more commands (W: means waiting for another
  5434. fork).
  5435.  
  5436. Suppose, after running MIDAS, you Push to a new EXEC and run your program
  5437. (somewhat useless, but helpful for this example).  At the time your program is
  5438. running, your job fork structure looks like:
  5439.  
  5440.  
  5441.                        (W: your EXEC)
  5442.                         /    #0     \
  5443.                        /      |      \
  5444.                       /       |       \
  5445.              (H: EMACS)   (H: MIDAS)   (W: Pushed-to EXEC)
  5446.                 #1           #2         /      #3
  5447.                                        /
  5448.                                       /
  5449.                              (R: your program)
  5450.                                     #4
  5451.  
  5452.  
  5453. Here you see more clearly the 'tree' structure of the forks in your job.  As
  5454. with most other trees encountered in computer science, this one is drawn
  5455. upside-down, with the branches growing down.  You can also see why Tops-20
  5456. processes are called 'forks', as the tree structure forks out at each process,
  5457. just as a road forks at a junction.
  5458.  
  5459. To elaborate more on the superior and inferior notion, fork #0 has forks #1,
  5460. #2, and #3 as inferiors, and fork #3 has fork #4 as an inferior.  Of course,
  5461. forks #1, #2 and #3 have fork #0 as a superior, and fork #4's superior is fork
  5462. #3.
  5463.  
  5464. Notice the states of the various forks: the top-level EXEC is now waiting on
  5465. the pushed-to EXEC to stop; your MIDAS fork has halted itself (which made the
  5466. top EXEC go on and ask you for more commands, at which point you Pushed to the
  5467. new EXEC); the EMACS fork's state hasn't changed, since you haven't told the
  5468. top EXEC to do anything with it; the pushed-to EXEC is waiting for your
  5469. running program to finish.
  5470. Monitor Calls                                                         Page 99
  5471.  
  5472. 4.8.2. The Fork Environment
  5473.  
  5474. As mentioned above, each fork has a 'control panel', or interface with the
  5475. external environment, i.e. the world of forks outside itself.  This panel has
  5476. several different areas, relating to the various kinds of interactions
  5477. possible with the outside world.  These areas are as follows (don't worry
  5478. about the areas we haven't discussed yet):
  5479.  
  5480.    1. The file system, each file represented by a Job File Handle (JFN);
  5481.  
  5482.    2. The fork world, each inferior fork represented by a relative fork
  5483.       handle;
  5484.  
  5485.    3. The software interrupt system, as described by various enabled or
  5486.       disabled channels and their handler address, as well as the global
  5487.       state of the interrupt system for the fork;
  5488.  
  5489.    4. Inter-process communication system, each channel of communication
  5490.       represented by a Process ID (PID);
  5491.  
  5492.    5. Inter-process sychronization system, each sychronization request
  5493.       represented by outstanding Enqueue request (ENQs);
  5494.  
  5495.    6. The user-terminal interface, consisting of various mode information
  5496.       for the terminal apropos this fork;
  5497.  
  5498. Note that each area on the 'control panel' has a method of referencing the
  5499. various external objects related to the area; these are called 'handles' in
  5500. general (Job File Handles, Relative Fork Handles, Process ID Handles, etc.).
  5501. This is no coincidence: you have to refer to one of several objects --forks,
  5502. files, process IDs, etc.-- when you want to do something with them --open a
  5503. file, start a fork, send a message to another process, etc.-- and thus the
  5504. need for a handle.  A handle is usually nothing more than a small integer
  5505. uniquely identifying the particular object you want to deal with.
  5506.  
  5507.  
  5508.  
  5509. 4.8.3. Basic Fork-Handling JSYS's
  5510.  
  5511. With the above introduction to forks and their environment, we can proceed to
  5512. the two most basic fork-handling JSYS's: RESET and HALTF.
  5513.  
  5514.  
  5515.  
  5516. 4.8.3.1. RESET (JSYS 147): Reset the current fork
  5517.  
  5518. This JSYS, in the terms of the previous section, cleans up the interface to
  5519. the external environment for this fork.  It's always a good idea to use this
  5520. JSYS at the start of your program to make sure there are no 'loose ends' lying
  5521. around.
  5522.  
  5523.  
  5524. Returns:    +1: Always (no errors are possible).
  5525.  
  5526.  
  5527. The RESET JSYS (cf. the list above in section 4.8.2):
  5528.  
  5529.    1. closes all files for this fork (and any inferiors) and releases all
  5530. Monitor Calls                                                        Page 100
  5531.  
  5532.       Job File Numbers (JFNs);
  5533.  
  5534.    2. destroys all inferior forks and releases any Relative Fork Handles
  5535.       it can;
  5536.  
  5537.    3. resets the software interrupt system for this fork;
  5538.  
  5539.    4. releases all handles on inter-process communication channels
  5540.       (PIDs);
  5541.  
  5542.    5. releases all inter-process sychronization requests (ENQs);
  5543.  
  5544.    6. resets the terminal for this process to wake up on every character,
  5545.       echo input, and translate output normally;
  5546.  
  5547.  
  5548.  
  5549. 4.8.3.2. HALTF (JSYS 170) - Halt the current fork
  5550.  
  5551. Halts this fork and any forks inferior to this one; this fork (the one
  5552. executing this JSYS) then goes into the 'halted' state (with a 'voluntarily
  5553. terminated' flavor).  If this fork is resumed (with a RFORK JSYS), then it
  5554. will continue with the instruction after this HALTF JSYS.
  5555.  
  5556.  
  5557. Returns:    +1: only if this fork is later resumed (no errors are
  5558.                 possible from the HALTF itself).
  5559.  
  5560.  
  5561.  
  5562.  
  5563. 4.8.3.3. Examples of RESET and HALTF
  5564.  
  5565. These two JSYS's are fairly simply used in practice.  An example of a complete
  5566. MACRO program that prints "I'm here" and stops is:
  5567.  
  5568.  
  5569.         title ImHere
  5570.         search monsym
  5571.  
  5572. ImHere: RESET                   ; Tidy up the environment.
  5573.         hrroi 1, [asciz/I'm here/] ; Print our
  5574.         PSOUT                   ;  message to the terminal,
  5575.         HALTF                   ;  and stop this fork.
  5576.          jrst ImHere            ; If this fork is continued, start over.
  5577.  
  5578.         end ImHere
  5579.  
  5580.  
  5581.  
  5582.  
  5583. 4.9. Miscellaneous JSYS's
  5584. Monitor Calls                                                        Page 101
  5585.  
  5586. 4.9.1. STCMP (JSYS 540) - STring CoMParison
  5587.  
  5588. Compares two ASCIZ strings in memory.  Letters are always considered as upper
  5589. case regardless of their case within the string; e.g. "ABC" and "abc" are
  5590. considered an exact match.
  5591.  
  5592.  
  5593. Accepts in AC1:  Pointer to test string.
  5594.  
  5595.            AC2:  Pointer to base string.
  5596.  
  5597. Returns:    +1:  always, with
  5598.  
  5599.                  AC1 containing the compare code:
  5600.  
  5601.                    SC%LSS (bit 0) Test string less than base string.
  5602.                    SC%SUB (bit 1) Test string is a subset of
  5603.                                     base string.
  5604.                    SC%GTR (bit 2) Test string greater than base string.
  5605.  
  5606.                    No bits are set in AC1 if the strings are equal.
  5607.  
  5608.                  AC2 containing base string pointer, updated such that
  5609.                  an ildb instruction will reference the first
  5610.                  nonmatching byte.
  5611.  
  5612. One string is considered less than another string if the ASCII value of the
  5613. first nonmatching character in the first string is less than the ASCII value
  5614. of the character in the same position in the second string.
  5615.  
  5616. On string is considered a subset of another string if both of the following
  5617. conditions are true:
  5618.  
  5619.    1. From left to right, the ASCII values of the characters in
  5620.       corresponding positions are the same.
  5621.  
  5622.    2. The test string is shorter than the base string.
  5623.  
  5624. Two strings are considered equal if the ASCII values of the characters in
  5625. corresponding positions are the same and the two strings are the same size.
  5626. In this case, the contents of AC1 is 0 on return.
  5627.  
  5628. Example:
  5629.  
  5630.  
  5631.         move t1, [point 7, string1] ; Pointers to test string
  5632.         move t2, [point 7, [asciz /FOO/]] ; and base string.
  5633.         STCMP                   ; Compare them.
  5634.         jumpe t1, equal         ; Do this if they're equal.
  5635.         txnn t1, SC%LSS!SC%SUB  ; Not equal.  Test string less?
  5636.          jrst greater           ;  No, greater - go handle.
  5637.  
  5638. ; Get here only if test string lexically less than base string.
  5639.         :
  5640.         :
  5641. COMND JSYS                                                           Page 102
  5642.  
  5643.                          5. The COMND JSYS - JSYS 544
  5644.  
  5645.  
  5646.        The COMND JSYS is probably the single most attractive feature of
  5647.     the DECSYSTEM-20.  It allows any interactive program to be totally
  5648.     (and automatically) fault-tolerant and helpful to its users.  The pain
  5649.     involved in learning to use it effectively is worth suffering, but
  5650.     should probably be deferred until you have become comfortable with the
  5651.     instruction set, Macro-20, and the monitor calls described in Chapter
  5652.     4.
  5653.  
  5654.        The following introductory material was adapted for use in this
  5655.     manual from a document written by Andrew R. Lowry and David S. Millman
  5656.     at Columbia in August 1978.
  5657.  
  5658.  
  5659.  
  5660. 5.1. Informal Introduction
  5661.  
  5662. You are probably already at least partially familiar with the workings of the
  5663. COMND jsys, although you may not be aware of your education.  The COMND jsys
  5664. is the thing that figures out what you mean when you abbreviate your commands
  5665. to the EXEC, or when the EXEC finishes up your commands for you when you types
  5666. an ESCAPE character.  It is also what types guide words in parentheses telling
  5667. you what you must type next, and it is the thing that will untiringly answer
  5668. your question marks with lists of alternatives for you to choose from.  In
  5669. short, it is one of the things that makes learning and typing in commands to
  5670. the EXEC as easy as it is.
  5671.  
  5672. Using the COMND jsys mainly consists of the following:  you tell it what
  5673. you're looking for, and it tells you what it finds.  All the complexities have
  5674. to do with how this communication takes place.  A great deal of this is common
  5675. to all the calls you can give to COMND, but some of it depends on exactly what
  5676. you're asking COMND to look for.
  5677.  
  5678. All the information which you must supply to COMND may be broken down
  5679. basically into two sets, the Command State Block (CSB) and the Function
  5680. Descriptor Block (FDB).
  5681.  
  5682. The CSB is ten words (storage locations) long and contains information about
  5683. what has been typed so far, how much more can be typed without overflowing the
  5684. space that has been set aside to store it, and where COMND can find other
  5685. information that it needs. Most of this information must be supplied only once
  5686. by the program using COMND, and from that point on COMND will update the
  5687. information as it goes.
  5688.  
  5689. The FDB is four words long and contains information which is more specific to
  5690. the type of call which is being made than is the information in the CSB.  It
  5691. is here that COMND finds out what type of information it should be looking for
  5692. -- file name, time of day, one out of a list of possible keywords, or any
  5693. other of the 24 different items it knows how to look for.  Also in the FDB it
  5694. finds pointers to a help string and a default string which the controlling
  5695. program supplies.  The help string is what will be typed if the user types a
  5696. question mark, and the default string is what COMND will fill in if the user
  5697. types an escape character.  Finally, COMND finds several indicators in the FDB
  5698. telling it how to process the request -- things like whether or not to convert
  5699. lower case input into upper case, whether or not to accept indirect file
  5700. specifications, etc.
  5701. COMND JSYS                                                           Page 103
  5702.  
  5703. The only thing left to do after the CSB and the FDB have been properly filled
  5704. in is to tell COMND where they are and let it go do its work.  The only
  5705. questions now are, what does it do, and what are all the things it might give
  5706. back?
  5707.  
  5708. When COMND is invoked, it starts accepting characters, usually from the job's
  5709. controlling terminal.  It keeps taking characters until the user types what is
  5710. called an "action" chatacter.  Action characters include question mark,
  5711. escape, ctrl/f and carriage return, and they are called action characters
  5712. because COMND won't start doing what it is supposed to do until one of them is
  5713. typed.  Once an action character is encountered, COMND will determine whether
  5714. or not the user has finished typing what s/he was supposed to type, and if so,
  5715. will return control to the calling program.  This can be done in any of three
  5716. possible states.
  5717.  
  5718. If COMND was able to interpret what was typed, and decided that it was an
  5719. appropriate response, then it returns normally with the data that it received
  5720. stored in a place where the program can easily retrieve it.
  5721.  
  5722. If COMND was unable to understand what was typed in the context of what it was
  5723. told to look for, then it will return with an error indicator set so that the
  5724. program will know that something went wrong.
  5725.  
  5726. The third possibility is best shown by example.  Suppose a program desires to
  5727. obtain from the user first a file name, then a time of day.  This will involve
  5728. two calls to COMND.  When the first call is executed, suppose the user (call
  5729. him Fred) types in FOO.BAR as his file name.  COMND accepts this as a valid
  5730. file name and returns normally to the calling program, which then executes
  5731. COMND again, this time asking for a time of day.
  5732.  
  5733. At this point, Fred decides that he really didn't want to use FOO.BAR, but
  5734. wanted FOO.BAZ instead.  So he deletes back to the R and types in a Z, and
  5735. then he goes ahead and types in a time of day as required.  Now it looks like
  5736. trouble ... COMND has already told the program that Fred wanted FOO.BAR, and
  5737. now it needs some way to let the program know that he changed his mind.  In
  5738. COMND jargon, we say that a "reparse" is needed.  COMND sets a flag to let the
  5739. program know what has happened, and now the program must start right from the
  5740. beginning and reissue all the calls that it made to COMND for the current
  5741. command line (this rather vague term will be firmed up shortly).  Thus it
  5742. redoes the call to get a file name, and COMND fills in FOO.BAZ this time, and
  5743. then it continues with the time of day call just like before.  If there had
  5744. been other calls on this command line before the file name, they too would
  5745. have to be reissued in the same order as they originally were called.
  5746.  
  5747. The term "command line" was used a few times in the preceeding paragraph, and
  5748. although it may have a fairly intuitive meaning, it also has a very strict
  5749. meaning in the context of the COMND jsys, which will be explained now and
  5750. should be kept in mind when trying to understand the reparse mechanism.
  5751.  
  5752. One of the calls that can be made to COMND is called "CMINI" (each different
  5753. call has its own slightly mnemonic name).  The CM signifies that it has
  5754. something to do with COMND, and the INI stands for "INItialize".  This call,
  5755. unlike the rest of the calls, accepts no input from the terminal.  It is used
  5756. to set up initial values in the CSB and to type out the command line prompt.
  5757. The end of this prompt is the farthest back that a user may delete when typing
  5758. the prompted-for command.
  5759.  
  5760. A "command line", then, consists of all responses to COMND calls made between
  5761. COMND JSYS                                                           Page 104
  5762.  
  5763. successive CMINI's.  For a reparse, the program reissues COMND calls starting
  5764. with the one after the CMINI call that initiated the command line.  The CMINI
  5765. call should not be reissued.  That would be done if an error were detected and
  5766. the entire command line had to be restarted.  The difference is that when
  5767. CMINI is done, COMND forgets everything that was previously contained in the
  5768. buffer.  This is appropriate for a complete restart after an error, but not
  5769. for merely backing up on a reparse.
  5770.  
  5771. A final general topic is the concept of multiple function calls.  This refers
  5772. to giving COMND more than one alternative to look for.  For instance, it may
  5773. be equally acceptable at a particular point in a command line for the user to
  5774. type either a date, or simply a decimal integer, specifying possibly a number
  5775. of days from the current date.  It would be advantageous for COMND to know
  5776. about the alternatives and not have to return an error if the second
  5777. alternative were chosen.
  5778.  
  5779. To accomplish this, it is possible to have several FDB'S all linked together
  5780. in a chain.  The first one contains a pointer to the second, which contains a
  5781. pointer to the third, etc.  Then if COMND can't make sense of what is typed in
  5782. the context of the first FDB, it goes on and tries the next FDB, and so on
  5783. right down the line until it gets to an FDB that does not point to another
  5784. one.  At that point, if none of the FDB's succeeded, an error condition is
  5785. finally signalled and COMND returns.  If one of the FDB's does fit, then not
  5786. only is the normal data returned, but also the location of the succeeding FDB
  5787. so that the program will be able to determine what ultimately happened.
  5788.  
  5789. The same procedures apply to multiple FDB's as to single ones in regard to
  5790. reparsing, error restarts, etc.  Remember that when using multiple FDB's only
  5791. one input item is parsed, not several.  The multiple nature comes from the
  5792. fact that COMND is given several choices as to how it should attempt to
  5793. interpret that item.
  5794.  
  5795. Note that when using multiple FDB's, only one CSB is used.  This fact
  5796. underlines the main difference between the natures of information stored in
  5797. the two blocks, the CSB being fairly call-independent, while almost all of the
  5798. information in the FDB depends on exactly what call is being made.
  5799.  
  5800. At this point you should have an idea of what is involved in getting the COMND
  5801. jsys to do your work for you.
  5802.  
  5803. Various people have written comprehensive sets of macros or UUO's to simplify
  5804. use of the COMND JSYS.  Such macros appear in MACSYM, CUsym, and elsewhere.  A
  5805. sample program is included in Chapter 11, and a description of Columbia's
  5806. COMND macro/UUO package is included in 7.1.
  5807.  
  5808.        This remainder of the Chapter is taken intact from the Tops-20 v4
  5809.     Monitor Calls Reference Manual.
  5810.  
  5811.  
  5812.  
  5813. 5.2. General Information
  5814.  
  5815. COMND - JSYS 544
  5816.  
  5817. Parses one field of a command that is either typed by a user or contained in a
  5818. file.  When this monitor call is used to read a command from a terminal, it
  5819. provides the following features:
  5820. COMND JSYS                                                           Page 105
  5821.  
  5822.    1. Allows the input of a command (including the guide words) to be
  5823.       given in abbreviated, recognition (ESC and CTRL/F), and/or full
  5824.       input mode.
  5825.  
  5826.    2. Allows the user to edit his input with the DELETE, CTRL/U, CTRL/W,
  5827.       and CTRL/R editing keys.
  5828.  
  5829.    3. Allows fields of the command to be defaulted if an ESC or CTRL/F is
  5830.       typed at the beginning of any field or if a field is omitted
  5831.       entirely.
  5832.  
  5833.    4. Allows a help message to be given if a question mark (?) is typed
  5834.       at the beginning of any field.
  5835.  
  5836.    5. Allows input of an indirect file (@file) that contains the fields
  5837.       for all or the remainder of the command.
  5838.  
  5839.    6. Allows a recall of the correct portion of the last command (i.e.,
  5840.       up to the beginning of the field where an error was detected) if
  5841.       the next command line begins with CTRL/H.  The correct portion of
  5842.       the command is retyped, and the user can then continue typing from
  5843.       that point.
  5844.  
  5845.    7. Allows input of a line to be continued onto the next line if the
  5846.       user types a hyphen (-) immediately preceding a carriage return.
  5847.       (The carriage return is invisible to the program executing the
  5848.       COMND call, although it is stored in the text buffer.) The hyphen
  5849.       can be typed by the user while he is typing a comment.  The comment
  5850.       is then continued onto the next line.
  5851.  
  5852. The COMND call allows the command line that is input to contain a comment if
  5853. the comment is preceded by either an exclamation point or a semicolon and the
  5854. previous field has been terminated.  When the COMND call inputs an exclamation
  5855. point after a field that has been terminated, it ignores all text on the
  5856. remainder of the line or up to the next exclamation point.  When the COMND
  5857. call inputs a semicolon after a field that has been terminated, it ignores all
  5858. text on the remainder of the line.
  5859.  
  5860. When an indirect file is given on the command line, it can be given at the
  5861. beginning of any field.  However, it must be the last item typed on the line,
  5862. and its contents must complete the current command.  The user must terminate
  5863. his input of the indirect file (after any recognition is performed) with a
  5864. carriage return.  If he does not terminate his input, the message ?INDIRECT
  5865. FILE NOT CONFIRMED is output.  Also, if the user types a question mark
  5866. (instead of the file specification of the indirect file) after he types the
  5867. @ character, the message FILESPEC OF INDIRECT FILE is output.  The indirect
  5868. file itself should not contain an ESC or carriage return; if these characters
  5869. are included, they will be treated as spaces.  The contents of the indirect
  5870. file are placed in the text buffer but are not typed on the user's terminal.
  5871.  
  5872. As the user types his command, the characters are placed in a command text
  5873. buffer.  This buffer can also include the command line prompt, if any.
  5874. Several byte pointers and counts reflect the current state of the parsing of
  5875. the command.  These pointers and counts are as follows:
  5876.  
  5877.    1. Byte pointer to the beginning of the prompting-text buffer
  5878.       (.CMRTY).  This pointer is also called the CTRL/R buffer byte
  5879.       pointer since it indicates the initial part of the text that will
  5880. COMND JSYS                                                           Page 106
  5881.  
  5882.       be output on a CTRL/R.  (The remainder of the text output on a
  5883.       CTRL/R is what the user had typed before he typed CTRL/R.)  The
  5884.       buffer containing the prompt need not be contiguous with the buffer
  5885.       containing the remainder of the command line.  Typically this
  5886.       pointer is to a string in the literals area.
  5887.  
  5888.    2. Byte pointer to the beginning of the user's input (.CMBFP).  This
  5889.       is the limit back to which the user can edit.
  5890.  
  5891.    3. Byte pointer to the beginning of the next field to be parsed
  5892.       (.CMPTR).
  5893.  
  5894.    4. Count of the space remaining in the text input buffer (.CMCNT).
  5895.  
  5896.    5. Count of the number of characters in the buffer that have not yet
  5897.       been parsed (.CMINC).
  5898.  
  5899. The illustration below is a logical arrangement of the byte pointers and
  5900. counts.  Remember that the prompting-text buffer does not have to be adjacent
  5901. to the text buffer.
  5902.  
  5903.  
  5904.                                                        .CMCNT
  5905.  
  5906.  
  5907.  
  5908.                 !=======================================================!
  5909.                 !        !              !                 !             !
  5910.                 !        !              !                 !             !
  5911.                 !=======================================================!
  5912.                 ^        ^              ^
  5913.                 !        !              !
  5914.                 !        !              !        .CMINC
  5915.                 !        !              !
  5916.                 !        !              !
  5917.                 !        .CMBFP         .CMPTR
  5918.                 .CMRTY
  5919.  
  5920.  
  5921. These byte pointers and other information are contained in a command state
  5922. block, whose address is given as an argument to the COMND monitor call.  The
  5923. .CMINI function initializes these pointers.
  5924.  
  5925. Parsing of a command is performed field by field and by default begins when
  5926. the user types a carriage return, ESC, CTRL/F, or question mark.  These
  5927. characters are called action characters because they cause the system to act
  5928. on the command as typed so far.  A field can also be terminated with a space,
  5929. tab, slash, comma, or any other nonalphanumeric character.  Normally, the
  5930. parsing does not begin, and the COMND call does not return control to the
  5931. program, until an action character is typed.  However, if B8(CM%WKF) is on in
  5932. word .CMFLG when the COMND call is executed, parsing begins after each field
  5933. is terminated.
  5934.  
  5935. The command is parsed by repeated COMND calls.  Each call specifies the type
  5936. of field expected to be parsed by supplying an appropriate function code and
  5937. any data needed for the function.  This information is given in a function
  5938. descriptor block.  On successful completion of each call, the current byte
  5939. pointers and the counts are updated in the command state block, and any data
  5940. COMND JSYS                                                           Page 107
  5941.  
  5942. obtained for the field is returned.
  5943.  
  5944. The program executing the COMND call should not reset the byte pointers in the
  5945. command state block after it completes the parsing of each command.  It should
  5946. set up the state block once at the beginning and then use the .CMINI function
  5947. when it begins parsing each line of a command.  This is true because the
  5948. .CMINI function implements the CTRL/H error recovery feature in addition to
  5949. initializing the byte pointers in the state block and printing the prompt for
  5950. the line.  If the program resets the pointers, the CTRL/H feature is not
  5951. possible because the pointers from the previous command are not available.
  5952. When a CTRL/H is input, the .CMINI function allows error recovery from the
  5953. last command only if both (1) the pointer to the beginning of the user's input
  5954. (.CMBFP) is not equal to the pointer to the beginning of the next field to be
  5955. parsed (.CMPTR) and (2) the last character parsed in the previous command was
  5956. not an end-of-line character.
  5957.  
  5958. The design of the COMND call allows the user to delete his typed input with
  5959. the DELETE, CTRL/W, and CTRL/U keys without regard to field boundaries.  When
  5960. the user deletes into a field that has already been parsed, the COMND call
  5961. returns to the program with B3(CM%RPT) set in word .CMFLG.  This return
  5962. informs the program to forget the current state of the command and to reparse
  5963. from the beginning of the line.  Because the complete line as typed and
  5964. corrected by the user is in the text buffer, the parse can be repeated and
  5965. will yield the same result up to the point of the change.
  5966.  
  5967. The calling sequence to the COMND call is as follows:
  5968.  
  5969.  
  5970.    ACCEPTS IN AC1:  address of the command state block
  5971.  
  5972.               AC2:  address of the first alternative function  descriptor
  5973.                     block
  5974.  
  5975.    RETURNS     +1:  always (unless a reparse is needed and the right half
  5976.                     of .CMFLG is nonzero), with
  5977.                     AC1 containing  flags  in  the  left  half,  and  the
  5978.                         address  of  the command state block in the right
  5979.                         half.  The flags are copied from word  .CMFLG  in
  5980.                         the command state block.
  5981.                     AC2 containing either the data obtained for the field
  5982.                         or an error code if the field could not be parsed
  5983.                         (CM%NOP is on).
  5984.                     AC3 containing in the left half the  address  of  the
  5985.                         function  descriptor block given in the call, and
  5986.                         in the right half the  address  of  the  function
  5987.                         descriptor  block  actually  used  (i.e., the one
  5988.                         that matched the input).
  5989.  
  5990. The format of the command state block is shown below.
  5991. COMND JSYS                                                           Page 108
  5992.  
  5993.  
  5994.            0                        17 18                       35
  5995.           !=======================================================!
  5996.    .CMFLG !         Flag Bits         ! Reparse Dispatch Address  !
  5997.           !-------------------------------------------------------!
  5998.    .CMIOJ !         Input JFN         !        Output JFN         !
  5999.           !-------------------------------------------------------!
  6000.    .CMRTY !              Byte Pointer to CTRL/R Text              !
  6001.           !-------------------------------------------------------!
  6002.    .CMBFP !          Byte Pointer to Start of Text Buffer         !
  6003.           !-------------------------------------------------------!
  6004.    .CMPTR !        Byte Pointer to Next Input To Be Parsed        !
  6005.           !-------------------------------------------------------!
  6006.    .CMCNT !             Count of Space Left in Buffer             !
  6007.           !-------------------------------------------------------!
  6008.    .CMINC !          Count of Characters Left in Buffer           !
  6009.           !-------------------------------------------------------!
  6010.    .CMABP !              Byte Pointer to Atom Buffer              !
  6011.           !-------------------------------------------------------!
  6012.    .CMABC !                  Size of Atom Buffer                  !
  6013.           !-------------------------------------------------------!
  6014.    .CMGJB !            Address of GTJFN Argument Block            !
  6015.           !=======================================================!
  6016.  
  6017.  
  6018.                              Command State Block
  6019.  
  6020. Word (Symbol)   Meaning
  6021.  
  6022. .CMFLG (0)      Flag bits in the left half, and the reparse dispatch address
  6023.                 in the right half.  Some flag bits can be set by the program
  6024.                 executing the COMND call; others can be set by the COMND call
  6025.                 after its execution.  The bits that can be set by the program
  6026.                 are described following the Command State Block description.
  6027.                 The bits that can be set by COMND are described following the
  6028.                 Function Descriptor Block description.
  6029.  
  6030.                 The reparse dispatch address is the location to which control
  6031.                 is automatically transferred when a reparse of the command is
  6032.                 needed because the user edited past the current pointer (i.e.,
  6033.                 the user edited characters that were already parsed).  If this
  6034.                 field is zero, the COMND call sets B3(CM%RPT) in the left half
  6035.                 of this word and gives the +1 return when a reparse is needed.
  6036.                 The program must then test CM%RPT and, if on, must reenter the
  6037.                 code that parses the first field of the command.  When the
  6038.                 reparse dispatch address is given, control is transferred
  6039.                 automatically to that address.
  6040.  
  6041.                 The code at the reparse dispatch address should initialize the
  6042.                 program's state to what it was after the last .CMINI function.
  6043.                 This initialization should include resetting the stack
  6044.                 pointer, closing and releasing any JFNs acquired since the
  6045.                 last .CMINI function, and transferring control to the code
  6046.                 immediately following the last .CMINI function call.
  6047.  
  6048. .CMIOJ (1)      Input JFN in the left half, and output JFN in the right half.
  6049.                 These designators identify the source for the input of the
  6050.                 command and the destination for the output of the typescript.
  6051. COMND JSYS                                                           Page 109
  6052.  
  6053.                 These designators are usually .PRIIN (for input) and .PRIOU
  6054.                 (for output).
  6055.  
  6056. .CMRTY (2)      Byte pointer to the beginning of the prompting-text.
  6057.  
  6058. .CMBFP (3)      Byte pointer to the beginning of the user's input.  The user
  6059.                 cannot edit back past this pointer.
  6060.  
  6061. .CMPTR (4)      Byte pointer to the beginning of the next field to be parsed.
  6062.  
  6063. .CMCNT (5)      Count of the space remaining in the buffer after the .CMPTR
  6064.                 pointer.
  6065.  
  6066. .CMINC (6)      Count of the number of unparsed characters in the buffer after
  6067.                 the .CMPTR pointer.
  6068.  
  6069. .CMABP (7)      Byte pointer to the atom buffer, a temporary storage buffer
  6070.                 that contains the last field parsed by the COMND call.  The
  6071.                 terminator of the field is not placed in this buffer.  The
  6072.                 atom buffer is terminated with a null.
  6073.  
  6074. .CMABC (10)     Count of the number of characters in the atom tbuffer.  This
  6075.                 count should be at least as large as the largest field
  6076.                 expected to be parsed.
  6077.  
  6078. .CMGJB (11)     Address of a GTJFN argument block.  This block must be at
  6079.                 least 16(octal) words long and must be writable.  If a longer
  6080.                 GTJFN block is being reserved, the count in the right half of
  6081.                 word .GJF2 of the GTJFN argument block must be greater than
  6082.                 four.  This block is usually filled in by the COMND call with
  6083.                 arguments for the GTJFN call if the specifified function is
  6084.                 requesting a JFN (i.e., functions .CMIFI, .CMOFI, and .CMFIL).
  6085.                 The user should store data in this block on the .CMFIL
  6086.                 function only.
  6087.  
  6088. The flag bits that can be set by the user in the left half of word .CMFLG in
  6089. the Command State Block are described below.  These bits apply to the parsing
  6090. of the entire command and are preserved by COMND after execution.  See the end
  6091. of the COMND JSYS discussion for the bits that are returned by COMND in the
  6092. left half of word .CMFLG.
  6093.  
  6094.  
  6095.  
  6096. 5.3. Bits Supplied in State Block on COMND Call
  6097.  
  6098. Symbol (bit)    Meaning
  6099.  
  6100. CM%RAI (6)      Convert lowercase input to uppercase.
  6101.  
  6102. CM%XIF (7)      Do not recognize the @ character as designating an indirect
  6103.                 file; instead consider the character as ordinary unctuation.
  6104.                 A program sets this bit to prevent the input of an indirect
  6105.                 file.
  6106.  
  6107. CM%WKF (8)      Begin parsing after each field is terminated instead of only
  6108.                 after an action character (carriage return, ESC, CTRL/F,
  6109.                 question mark) is typed.  For example, a program sets this bit
  6110.                 if it must change terminal characteristics (e.g., it must turn
  6111. COMND JSYS                                                           Page 110
  6112.  
  6113.                 off echoing because a password may be input) in the middle of
  6114.                 a command.  However, use of this bit is not recommended
  6115.                 because terminal wakeup occurs after each field is terminated,
  6116.                 thereby increasing system overhead.  The recommended method of
  6117.                 changing terminal characteristics within a command is to input
  6118.                 the field requiring the special characteristic on the next
  6119.                 line with its own prompt.  For example, if a program is
  6120.                 accepting a password, it should turn off echoing after the
  6121.                 .CMCFM function of the main command and perform the .CMINI
  6122.                 function to type the prompt requesting a password on the next
  6123.                 line.
  6124.  
  6125. The format of the function descriptor block is shown below.
  6126.  
  6127.  
  6128.           0           8 9          17 18                       35
  6129.          !=======================================================!
  6130.          !  function   !  function   ! address of next function  !
  6131.    .CMFNP!    code     !    flags    !     descriptor block      !
  6132.          !-------------------------------------------------------!
  6133.    .CMDAT!              Data for specific function               !
  6134.          !-------------------------------------------------------!
  6135.    .CMHLP!          Byte pointer to help text for field          !
  6136.          !-------------------------------------------------------!
  6137.    .CMDEF!        Byte pointer to default string for field       !
  6138.          !-------------------------------------------------------!
  6139.    .CMBRK!             Pointer to 4-word break mask              !
  6140.          !=======================================================!
  6141.  
  6142.  
  6143.  
  6144. 5.4. Function Descriptor Block
  6145.  
  6146. Symbol (word)   Meaning
  6147.  
  6148. .CMFNP (0)      Function code and pointer to next function descriptor block
  6149.                 (FDB).
  6150.  
  6151.                      B0-B8(CM%FNC)   Function code
  6152.                      B9-B17(CM%FFL)  Function-specific flags
  6153.                      B18-B35(CM%LST) Address of the next FDB
  6154.  
  6155. .CMDAT (1)      Data for the specific function, if any.
  6156.  
  6157. .CMHLP (2)      Byte pointer to the help text for this field.  This word can
  6158.                 be zero if the program is not supplying its own help text.
  6159.                 CM%HPP must be set (in word 0) in order for this pointer to be
  6160.                 used.
  6161.  
  6162. .CMDEF (3)      Byte pointer to the default string for this field.  This word
  6163.                 can be zero if the program is not supplying its own default
  6164.                 string.
  6165.  
  6166. .CMBRK (4)      Pointer to a 4-word break mask that specifies which characters
  6167.                 constitute end of field.  Word .CMBRK is ignored unless CM%BRK
  6168.                 (B13) is on.
  6169.  
  6170. The individual words in the function descriptor block are described in the
  6171. COMND JSYS                                                           Page 111
  6172.  
  6173. following paragraphs.
  6174.  
  6175.  
  6176.  
  6177. 5.4.1. Words .CMFNP and .CMDAT of the FDB
  6178.  
  6179. Word .CMFNP contains the function code for the expected field to be parsed,
  6180. and word .CMDAT contains any additional data needed for that function.  The
  6181. function codes, along with any required data for the functions, are described
  6182. below.
  6183.  
  6184. Symbol (code)   Meaning
  6185.  
  6186. .CMKEY (0)      Parse a keyword, such as a command name.  Word .CMDAT contains
  6187.                 the address of a keyword symbol table in the format described
  6188.                 in the TBLUK monitor call description (i.e., alphabetical).
  6189.                 The data bits that can be defined in the right half of the
  6190.                 first word of the argument pointed to by the table entries
  6191.                 (when B0-B6 of the first word are off and B7(CM%FW) is on) are
  6192.                 as follows:
  6193.  
  6194.                 B35(CM%INV)     Suppress this keyword in the list output on a
  6195.                                 ?.  The program can set this bit to include
  6196.                                 entries in the table that should be invisible
  6197.                                 because they are not preferred keywords.  For
  6198.                                 example, this bit can be set to allow the
  6199.                                 keyword LIST to be valid, even though the
  6200.                                 preferred keyword may be PRINT.  The LIST
  6201.                                 keyword would not be listed in the output
  6202.                                 given on a ?.  This bit is also used in
  6203.                                 conjunction with the CM%ABR bit to suppress an
  6204.                                 abbreviation in the output given on a ?.
  6205.  
  6206.                 B34(CM%NOR)     Do not recognize this keyword even if an exact
  6207.                                 match is typed by the user and suppress its
  6208.                                 listing in the list output on a ?.  (Refer to
  6209.                                 the TBLUK call description for more
  6210.                                 information on using this bit.)
  6211.  
  6212.                 B33(CM%ABR)     Consider this keyword a valid abbreviation for
  6213.                                 another entry in the table.  The right half of
  6214.                                 this table entry points to the keyword for
  6215.                                 which this is an abbreviation.  The program
  6216.                                 can set this bit to include entries in the
  6217.                                 table that are less than the minimum unique
  6218.                                 abbreviation.  For example, this bit can be
  6219.                                 set to include the entry ST (for START) in the
  6220.                                 table.  If the user then types ST as a
  6221.                                 keyword, it will be accepted as a valid
  6222.                                 abbreviation even though there may be other
  6223.                                 keywords beginning with ST.  To suppress the
  6224.                                 output of this abbreviation in the list typed
  6225.                                 on a ?, the program must also set the CM%INV
  6226.                                 bit.
  6227.  
  6228. On a successful return from .CMKEY, AC2 contains the address of the table
  6229.                 entry where the keyword was found.
  6230. COMND JSYS                                                           Page 112
  6231.  
  6232. CMNUM (1)       Parse a number.  Word .CMDAT contains the radix from 2 to 10)
  6233.                 of the number.  On a successful return, AC2 contains the
  6234.                 number.
  6235.  
  6236. .CMNOI (2)      Parse a guide word string, but do not return an error if no
  6237.                 guide word is input.  An error is returned only if a guide
  6238.                 word is input that does not match the one expected by the
  6239.                 COMND call.  A guide word field must be delimited by
  6240.                 parentheses.  Word .CMDAT contains a byte pointer to an ASCIZ
  6241.                 string.  This string does not contain the parentheses of the
  6242.                 guide word.  Guide words are output if the user terminated the
  6243.                 previous field with ESC.  Guide words are not output, nor can
  6244.                 they be input, if the user has caused parsing into the next
  6245.                 field.
  6246.  
  6247. .CMSWI (3)      Parse a switch.  A switch field must begin with a slash and
  6248.                 can be terminated with a colon in addition to any of the legal
  6249.                 terminators.  Word .CMDAT contains the address of a switch
  6250.                 keyword symbol table.  (Refer to the TBLUK monitor call
  6251.                 description for the format of the table.) The entries in the
  6252.                 table do not contain the slash of the switch keywords;
  6253.                 however, they should end with a colon if the switch requires a
  6254.                 value.  The data bits CM%INV, CM%NOR, and CM%ABR defined for
  6255.                 the .CMKEY function can also be set on this function.  On a
  6256.                 successful return, AC2 contains the address of the table entry
  6257.                 where the switch keyword was found.
  6258.  
  6259. .CMIFI (4)      Parse an input file specification.  This function causes the
  6260.                 COMND call to execute a GTJFN call to attempt to parse the
  6261.                 specification for an existing file, using no default fields.
  6262.                 The .CMGJB address (word 11 in the command state block) must
  6263.                 be supplied, but the GTJFN block should be empty.  (Data
  6264.                 stored in the block will be overwritten by the COMND JSYS.
  6265.                 Also, certain GTJFN flags are set.)  On a successful return,
  6266.                 AC2 contains the JFN assigned.  Hyphens are treated as
  6267.                 alphanumeric characters for this function
  6268.  
  6269.                 See note following .CMFIL function.
  6270.  
  6271. .CMOFI (5)      Parse an output file specification.  This function causes the
  6272.                 COMND call to execute a GTJFN call to attempt to parse the
  6273.                 specification for either a new or an existing file.  The
  6274.                 default generation number is the generation number of the
  6275.                 existing file plus 1.  The .CMGJB address must be supplied,
  6276.                 but the GTJFN block should be empty.  (Data stored in the
  6277.                 block will be overwritten by the COMND JSYS.  Also, certain
  6278.                 GTJFN flags are set.)  On a successful return, AC2 contains
  6279.                 the JFN assigned.  Hyphens are treated as alphanumeric
  6280.                 characters for this function.
  6281.  
  6282.                 See note following .CMFIL function.
  6283.  
  6284. .CMFIL (6)      Parse a general (arbitrary) file specification.  This function
  6285.                 causes the COMND call to execute a GTJFN to attempt to parse
  6286.                 the specification for the file.  The .CMGJB address must be
  6287.                 supplied, but data stored in certain words of the GTJFN block
  6288.                 will be overwritten by the COMND JSYS and certain GTJFN flags
  6289.                 will be set (see note below).  On a successful return, AC2
  6290. COMND JSYS                                                           Page 113
  6291.  
  6292.                 contains the JFN assigned.  Hyphens are treated as
  6293.                 alphanumeric characters for this function.
  6294.  
  6295.                 Note that portions of the GTJFN block used by functions
  6296.                 .CMOFI, .CMIFI, and .CMFIL are controlled by COMND.  The
  6297.                 following list shows which words are under the control of
  6298.                 COMND and which words are under the control of the user:
  6299.  
  6300.                 GTJFN      Controlled    Characteristics
  6301.                 Word(s)    by
  6302.  
  6303.                 .GJGEN     COMND
  6304.  
  6305.                                          1.  .CMOFI   sets   flags
  6306.                                              GJ%FOU,  GJ%MSG,  and
  6307.                                              GJ%XTN and clears all
  6308.                                              other flags.
  6309.  
  6310.                                          2.  .CMIFI   sets    flag
  6311.                                              GJ%OLD,   and  GJ%XTN
  6312.                                              and clears all  other
  6313.                                              flags.
  6314.  
  6315.                                          3.  .CMOFI   and   .CMIFI
  6316.                                              zero  the  right half
  6317.                                              of word .GJGEN
  6318.  
  6319.                                          4.  .CMFIL   sets    flag
  6320.                                              GJ%XTN   and   clears
  6321.                                              GJ%FCM
  6322.  
  6323.                 .GJSRC     COMND         None
  6324.  
  6325.                 .GJDEV -
  6326.                 .GJJFN     COMND/
  6327.                            USER          Functions   .CMIFI    AND
  6328.                                          .CMOFI give COMND control
  6329.                                          of these  words.   .CMFIL
  6330.                                          gives the user control of
  6331.                                          these words.
  6332.                 .GJF2 -
  6333.                 .GJATR     COMND         None
  6334.  
  6335. .CMFLD (7)      Parse an arbitrary field.  This function is useful for fields
  6336.                 not normally handled by the COMND call.  The input, as
  6337.                 delimited by the first nonalphanumeric character, is copied
  6338.                 into the atom buffer; the delimiter is not copied.  Note the
  6339.                 following:
  6340.  
  6341.                    1. This function will parse a null field
  6342.  
  6343.                    2. Hyphens are treated as alphanumeric characters for
  6344.                       this function
  6345.  
  6346.                    3. No validation is performed (such as filename
  6347.                       validation)
  6348.  
  6349.                    4. No standard help message is available (see below)
  6350. COMND JSYS                                                           Page 114
  6351.  
  6352.                    5. The FLDBK. and BRMSK. macros may be used for
  6353.                       including other characters in the field (like "*").
  6354.  
  6355. .CMCFM (10)     Confirm.  This function waits for the user to confirm the
  6356.                 command with a carriage return and should be used at the end
  6357.                 of parsing a command line.
  6358.  
  6359. .CMDIR (11)     Parse a directory name.  Login and files-only directories are
  6360.                 allowed.  Word .CMDAT contains data bits for this function.
  6361.                 The currently defined bit is as follows:
  6362.  
  6363.                     B0(CM%DWC)     Allow wildcard characters
  6364.  
  6365.                 On a successful return, AC2 contains the 36-bit directory
  6366.                 number.
  6367.  
  6368. .CMUSR (12)     Parse a user name.  Only login directories are allowed.  On a
  6369.                 successful return, AC2 contains the 36-bit user number.
  6370.  
  6371. .CMCMA (13)     Comma.  Sets B1(CM%NOP-no parse) in word .CMFLG of the command
  6372.                 state block and returns if a comma is not the next item in the
  6373.                 input.  Blanks can appear on either side of the comma.  This
  6374.                 function is useful for parsing a list of arguments.
  6375.  
  6376. .CMINI (14)     Initialize the command line (e.g., set up internal monitor
  6377.                 pointers, type the prompt, and check for CTRL/H).  This
  6378.                 function should be used at the beginning of parsing a command
  6379.                 line but not when reparsing a line.  Otherwise, the CTRL/H
  6380.                 feature will not work.
  6381.  
  6382.                 To use this function, the user first moves the appropriate
  6383.                 data into the command state block and then issues .CMINI.  If,
  6384.                 at any time during the parsing of a line, an error occurs,
  6385.                 .CMINI is issued again to reinitialize the line.  However, for
  6386.                 the 2'nd thru N'th invocation of .CMINI for a given line, the
  6387.                 user should not alter the byte pointers and character counts
  6388.                 in the command state block.  To do so would disable the CTRL/H
  6389.                 feature.  This feature allows the user program, on parsing a
  6390.                 bad atom, to print an error message, reissue the prompt, and
  6391.                 parse the command line again without forcing the user to
  6392.                 retype the entire line.
  6393.  
  6394.                 If .CMINI reads a CTRL/H character, .CMINI will reset all byte
  6395.                 pointers and character counts except the .CMINC count to their
  6396.                 original state.  .CMINI will set the .CMINC count to the
  6397.                 number of characters in the buffer up to the bad atom.  These
  6398.                 characters are output to the terminal and parsed again.
  6399.                 Control then passes to the reparse address (if provided) and
  6400.                 normal parsing resumes.  The effect on the program is as if
  6401.                 the bad atom had never been typed.
  6402.  
  6403. .CMFLT (15)     Parse a floating-point number.  On a successful return, AC2
  6404.                 contains the floating-point number.
  6405.  
  6406. .CMDEV (16)     Parse a device name.  On a successful return, AC2 contains the
  6407.                 device designator.
  6408.  
  6409. .CMTXT (17)     Parse the input text up to the next carriage return, place the
  6410. COMND JSYS                                                           Page 115
  6411.  
  6412.                 text in the atom buffer, and return.  If an ESC or CTRL/F is
  6413.                 typed, it causes the terminal bell to ring (because
  6414.                 recognition is not available with this function) and is
  6415.                 otherwise ignored.  If a ?  is typed, an appropriate response
  6416.                 is given, and the ? is not included in the atom buffer.  (A ?
  6417.                 can be included in the input text if it is preceded by a
  6418.                 CTRL/V.)
  6419.  
  6420. .CMTAD (20)     Parse a date and/or time field according to the setting of
  6421.                 bits CM%IDA and CM%ITM.  The user must input the field as
  6422.                 requested.  Any date format allowed by the IDTIM call can be
  6423.                 input.  If a date is not input, it is assumed to be the
  6424.                 current date.  If a time is not input, it is assumed to be
  6425.                 00:00:01.  When both the date and time fields are input, they
  6426.                 must be separated by one or more spaces.  If the fields are
  6427.                 input separately, they must be terminated with a space or
  6428.                 carriage return.  Word .CMDAT contains bits in the left half
  6429.                 and an address in the right half as data for the function.
  6430.                 The bits are:
  6431.  
  6432.                      B0(CM%IDA) Parse a date
  6433.                      B1(CM%ITM) Parse a time
  6434.                      B2(CM%NCI) Do not convert the date and/or time to
  6435.                         internal format.
  6436.  
  6437.                 The address in the right half is the beginning of a 3-word
  6438.                 block in the caller's address space.  On a successful return,
  6439.                 this block contains data returned from the IDTNC call executed
  6440.                 by COMND if B2(CM%NCI) was on in the COMND call (i.e., if the
  6441.                 input date and/or time field was not to be converted to
  6442.                 internal format).  If B2(CM%NCI) was off in the COMND call, on
  6443.                 a successful return, AC2 contains the internal date and time
  6444.                 format.
  6445.  
  6446. .CMQST (21)     Parse a quoted string up to the terminating quote.  The
  6447.                 delimiters for the string must be double quotation marks and
  6448.                 are not copied to the atom buffer.  A double quotation mark is
  6449.                 input as part of the string if two double quotation marks
  6450.                 appear together.  This function is useful if the legal field
  6451.                 terminators and the action characters are to be included as
  6452.                 part of a string.  The characters ?, ESC, and CTRL/F are not
  6453.                 treated as action characters and are included in the string
  6454.                 stored in the atom buffer.  Carriage return is an invalid
  6455.                 character in a quoted string and causes B1(CM%NOP) to be set
  6456.                 on return.
  6457.  
  6458. .CMUQS (22)     Parse an unquoted string up to one of the specified break
  6459.                 characters.  Word .CMDAT contains the address of a 4-word
  6460.                 block of 128 break character mask bits.  (Refer to word .RDBRK
  6461.                 of the TEXTI call description for an explanation of the mask.)
  6462.                 The characters scanned are not placed in the atom buffer.  On
  6463.                 return, .CMPTR is pointing to the break character.  This
  6464.                 function is useful for parsing a string with an arbitrary
  6465.                 delimiter.  The characters ?, ESC, and CTRL/F are not treated
  6466.                 as action characters (unless they are specified in the mask)
  6467.                 and can be included in the string.  Carriage return can also
  6468.                 be included if it is not one of the specified break
  6469.                 characters.
  6470. COMND JSYS                                                           Page 116
  6471.  
  6472. .CMTOK (23)     Parse the input and compare it with a given string ("token").
  6473.                 Word .CMDAT contains the byte pointer to the given string.
  6474.                 This function sets B1(CM%NOP) in word .CMFLG of the command
  6475.                 state block and returns if the next input characters do not
  6476.                 match the given string.  Leading blanks in the input are
  6477.                 ignored.  This function is useful for parsing single or
  6478.                 multiple character operators (e.g., + or **).
  6479.  
  6480. .CMNUX (24)     Parse a number and terminate on the first non-numeric
  6481.                 character.  Word .CMDAT contains the radix (from 2 to 10) of
  6482.                 the number.  On a successful return, AC2 contains the number.
  6483.                 This function is useful for parsing a number that may not be
  6484.                 terminated with a nonalphabetic character (e.g., 100PRINT
  6485.                 FILEA).
  6486.  
  6487.                 Note that non-numeric identifiers can begin with a digit
  6488.                 (e.g., 1SMITH as a user name).  When a non-numeric identifier
  6489.                 and a number appear as alternates for a field, the order of
  6490.                 the function descriptor blocks is important.  The .CMNUX
  6491.                 function, if given first, would accept the digit in the
  6492.                 non-numeric identifier as a valid number instead of as the
  6493.                 beginning character of a non-numeric identifier.
  6494.  
  6495. .CMACT (25)     Parse an account string.  The input, as delimited by the first
  6496.                 nonalphanumeric character, is copied into the atom buffer; the
  6497.                 delimiter is not copied.  No verification is performed nor is
  6498.                 any standard help message available.
  6499.  
  6500. .CMNOD (26)     Parse a network node name.  A node name consists of up to six
  6501.                 alphanumeric characters followed by 2 colons ("::").
  6502.                 Lowercase characters are converted to uppercase characters.
  6503.                 The node name is copied into the atom buffer without the
  6504.                 colons.  Note that this function does not verify the existence
  6505.                 of the node.
  6506.  
  6507. In addition to the .CMFNP word of the function descriptor block containing the
  6508. function code in bits 0-8 (CM%FNC), this word also contains function-specific
  6509. flag bits in bits 9-17 (CM%FFL) and the address of another function descriptor
  6510. block in bits 18-35 (CM%LST).
  6511.  
  6512. The flag bits that can be set in bits 9-17 (CM%FFL) are as follows:
  6513.  
  6514. Symbol (bit)    Meaning
  6515.  
  6516. CM%PO (14)      The field is to be parsed only and the field's existence is
  6517.                 not to be verified.  This bit currently applies to the .CMDIR
  6518.                 and .CMUSR functions and is ignored for the remaining
  6519.                 functions.  On return, COMND sets B1(CM%NOP-no parse) only if
  6520.                 the field typed is not in the correct syntax.  Also, data
  6521.                 returned in AC2 may not be correct.
  6522.  
  6523. CM%HPP (15)     A byte pointer to a program-supplied help message for this
  6524.                 field is given in word 2 (.CMHLP) of this function descriptor
  6525.                 block.
  6526.  
  6527. CM%DPP (16)     A byte pointer to a program-supplied default string for this
  6528.                 field is given in word 3 (.CMDEF) of this function descriptor
  6529.                 block.
  6530. COMND JSYS                                                           Page 117
  6531.  
  6532. CM%SDH (17)     The output of the default help message is to be suppressed if
  6533.                 the user types a question mark.  (See below for the default
  6534.                 messages.)
  6535.  
  6536. The address of another function descriptor block can be given in bits 18-35
  6537. (CM%LST) of the .CMFNP word.  The use of this second descriptor block is
  6538. described below.
  6539.  
  6540. Usually one COMND call is executed for each field in the command.  However,
  6541. for some fields, more than one type of input may be possible (e.g., after a
  6542. keyword field, the next field could be a switch or a filename field).  In
  6543. these cases, all the possibilities for a field must be tried in an order
  6544. selected to test unambiguous cases first.
  6545.  
  6546. When the COMND call cannot parse the field as indicated by the function code,
  6547. it does one of two things:
  6548.  
  6549.    1. It sets the current pointer and counts such that the next call will
  6550.       attempt to parse the same input over again.  It then returns with
  6551.       B1(CM%NOP) set in the left half of the .CMFLG word in the command
  6552.       state block.  The caller can then issue another COMND call with a
  6553.       function code indicating another of the possible fields.  After the
  6554.       execution of each call, the caller should test the CM%NOP flag to
  6555.       see if the field was parsed successfully.
  6556.  
  6557.    2. If an address of another function descriptor block is given in
  6558.       CM%LST, the COMND call moves to this descriptor block automatically
  6559.       and attempts to parse the field as indicated by the function code
  6560.       contained in B0-B8(CM%FNC) in word .CMFNP of that block.  If the
  6561.       COMND call fails to parse the field using this new function code,
  6562.       it moves to a third descriptor block if one is given.  This
  6563.       sequence continues until either the field is successfully parsed or
  6564.       the end of the chain of function blocks is reached.  Upon
  6565.       completion of the COMND call, AC3 contains the addresses of the
  6566.       first and last function blocks used.
  6567.  
  6568. By specifying a chained list of function blocks, the program can have the
  6569. COMND call automatically check all possible alternatives for a field and not
  6570. have to issue a separate call for each one.  In addition, if the user types a
  6571. question mark, a list is output of all the alternatives for the field as
  6572. indicated by the list of function descriptor blocks.
  6573.  
  6574.  
  6575.  
  6576. 5.4.2. Word .CMHLP of the FDB
  6577.  
  6578. This word contains a byte pointer to a program-supplied help text to be output
  6579. if the user types a question mark when entering his command.  The default help
  6580. message is appended to the output of the program-supplied message if
  6581. B17(CM%SDH) is not set.  If B17(CM%SDH) is set, only the program-supplied
  6582. message is output.  If this word in the descriptor block is zero, only the
  6583. default message is output when the user types a question mark.  Bit 15(CM%HPP)
  6584. must be set in word 0 (.CMFNP) of the function descriptor block for this
  6585. pointer to be used.  The default help message depends on the particular
  6586. function being used to parse the current field.  The table below lists the
  6587. default help message for each function available in the COMND call.
  6588. COMND JSYS                                                           Page 118
  6589.  
  6590. 5.4.3. Default Help Messages
  6591.  
  6592. Function        Message
  6593.  
  6594. .CMKEY (keyword) ONE OF THE FOLLOWING followed by the alphabetical list of
  6595.                 valid keywords.  If the user types a question mark in the
  6596.                 middle of the field, only the keywords that can possibly match
  6597.                 the field as currently typed are output.  If no keyword can
  6598.                 possibly match the currently typed field, the message KEYWORD
  6599.                 (NO DEFINED KEYWORDS MATCH THIS INPUT) is output.
  6600.  
  6601. .CMNUM (number) The help message output depends on the radix specified in
  6602.                 .CMDAT in the descriptor block.  If the radix is octal, the
  6603.                 help message is OCTAL NUMBER If the radix is decimal, the help
  6604.                 message is DECIMAL NUMBER If the radix is any other radix, the
  6605.                 help message is A NUMBER IN BASE nn where nn is the radix.
  6606.  
  6607. .CMNOI (guide word) None
  6608.  
  6609. .CMSWI (switch) ONE OF THE FOLLOWING followed by the alphabetical list of
  6610.                 valid switch keywords.  The same rules apply as for .CMKEY
  6611.                 function.  (See above.)
  6612.  
  6613. .CMIFI (input file) The help message output depends on the
  6614.  
  6615. .CMOFI (output file) settings of certain bits in the GTJFN call.
  6616.  
  6617. .CMFIL (any file) If bit GJ%OLD is off and bit GJ%FOU is on, the help message
  6618.                 is OUTPUT FILESPEC Otherwise, the help message is INPUT
  6619.                 FILESPEC
  6620.  
  6621. .CMFLD (any field) None
  6622.  
  6623. .CMCFM (confirm) CONFIRM WITH CARRIAGE RETURN
  6624.  
  6625. .CMDIR (directory) DIRECTORY NAME
  6626.  
  6627. .CMUSR (user)   USER NAME
  6628.  
  6629. .CMCMA (comma)  COMMA
  6630.  
  6631. .CMINI (initialize) None
  6632.  
  6633. .CMFLT (floating point) NUMBER
  6634.  
  6635. .CMDEV (device) DEVICE NAME
  6636.  
  6637. .CMTXT (text)   TEXT STRING
  6638.  
  6639. .CMTAD (date)   The help message depends on the bits set in .CMDAT in the
  6640.                 descriptor block.  If CM%IDA is set, the help message is DATE
  6641.                 If CM%ITM is set, the help message is TIME If both are set,
  6642.                 the help message is DATE AND TIME
  6643.  
  6644. .CMQST (quoted) QUOTED STRING
  6645.  
  6646. .CMUQS (unquoted) None
  6647. COMND JSYS                                                           Page 119
  6648.  
  6649. .CMTOK (token)  None
  6650.  
  6651. .CMNUX (number) Same as .CMNUM
  6652.  
  6653. .CMACT (account) None
  6654.  
  6655. .CMNOD (node)   NODE NAME
  6656.  
  6657.  
  6658.  
  6659. 5.4.4. Word .CMDEF of the FDB
  6660.  
  6661. This word contains a byte pointer to the ASCIZ string to be used as the
  6662. default for this field.  For this pointer to be used, bit 16 (CM%DPP) must be
  6663. set in word 0 (.CMFNP) of the descriptor block.  The string is output to the
  6664. destination, as well as copied to the text buffer, if the user types an ESC or
  6665. CTRL/F as the first non-blank character in the field.  If the user types a
  6666. carriage return, the string is copied to the atom buffer but is not output to
  6667. the destination.
  6668.  
  6669. When the caller supplies a list of function descriptor blocks, the byte
  6670. pointer for the default string must be included in the first block.  The
  6671. CM%DPP bit and the pointer for the default string are ignored when they appear
  6672. in subsequent blocks.  However, the default string can be worded so that it
  6673. will apply to any of the alternative fields.  The effect is the same as if the
  6674. user had typed the given string.
  6675.  
  6676. Defaults for fields of a file specification can also be supplied with the
  6677. .CMFIL function.  If both the byte pointer to the default string and the GTJFN
  6678. defaults have been provided, the COMND default will be used first and then, if
  6679. necessary, the GTJFN defaults.
  6680.  
  6681.        NOTE: The function descriptor block, whose address is given in AC2,
  6682.     can be set up by the FLDDB. and FLDBK. macros defined in MACSYM.  (See
  6683.     end of COMND section for a description of these macros.)
  6684.  
  6685.  
  6686.  
  6687. 5.4.5. Word .CMBRK of the FDB
  6688.  
  6689. This word contains a pointer to a 4-word user-specified mask that determines
  6690. which characters constitute end of field.  The leftmost 32 bits of each word
  6691. correspond to a character in the ASCII collating sequence (in ascending
  6692. order).  If the bit is on for a given character, typing that character will
  6693. cause the COMND JSYS to treat the characters typed so far as a separate field
  6694. and parse it according to the function being used.  CM%BRK (B13) must be on in
  6695. the first word of the function descriptor block or COMND will ignore word
  6696. .CMBRK.
  6697.  
  6698. Ordinarily, the user would rely on COMND's default masks (varying according to
  6699. function) to specify which characters signal end of field and thus would not
  6700. be concerned with word .CMBRK of the function block.  However, for special
  6701. purposes such as allowing "*" or "%" to be part of a field rather than a field
  6702. delimiter, the user must specify his own mask.  (In this example, the bits for
  6703. "*" and "%" would be off in the mask word.) The user may inspect COMND's
  6704. default masks (defined in MONSYM) for help in designing a custom mask.
  6705.  
  6706. The following is a list of the COMND functions that use masks:
  6707. COMND JSYS                                                           Page 120
  6708.  
  6709.  
  6710.   Mask              COMND       Changeable
  6711.   Symbols           Function    by User
  6712.  
  6713.   KEYB0. - KEYB3.   .CMKEY      Yes
  6714.   DEVB0. - DEVB3.   .CMDEV      Yes (only if parse-only)
  6715.   FLDB0. - FLDB3.   .CMFLD      Yes
  6716.   EOLB0. - EOLB3.   .CMTXT      Yes
  6717.   KEYB0. - KEYB3.   .CMSWI      Yes
  6718.   User specified    .CMDAT      Yes
  6719.   USRB0. - USRB3.   .CMUSR      No
  6720.   FILB0. - FILB3.   .CMFIL      No
  6721.   FILB0. - FILB3.   .CMIFI      No
  6722.   FILB0. - FILB3.   .CMOFI      No
  6723.   internal          .CMNUM      No
  6724.   FILB0. - FILB3.   .CMDIR      No
  6725.   internal          .CMFLT      No
  6726.   ACTB0. - ACTB3.   .CMACT      No
  6727.  
  6728. COMND will ignore any break masks that are specified for functions that do not
  6729. allow user-modified masks.
  6730.  
  6731. Note that specifying a zero mask with CM%BRK set will cause the TTY line
  6732. buffer to fill up and generate an error.
  6733.  
  6734. On a successful return, the COMND call returns flag bits in the left half of
  6735. AC1 and preserves the address of the command state block in the right half of
  6736. AC1.  These flag bits are copied from word .CMFLG in the command state block
  6737. and are described as follows.
  6738.  
  6739.  
  6740.  
  6741. 5.5. Bits Returned on COMND Call
  6742.  
  6743. Symbol (bit)    Meaning
  6744.  
  6745. CM%ESC (0)      An ESC was typed by the user as the terminator for this field.
  6746.  
  6747. CM%NOP (1)      The field could not be parsed because it did not conform to
  6748.                 the specified function(s).  An error code is returned in AC2.
  6749.  
  6750. CM%EOC (2)      The field was terminated with a carriage return.
  6751.  
  6752. CM%RPT (3)      Characters already parsed need to be reparsed because the user
  6753.                 edited them.  This bit does not need to be examined if the
  6754.                 program has supplied a reparse dispatch address in the right
  6755.                 half of .CMFLG in the command state block.
  6756.  
  6757. CM%SWT (4)      A switch field was terminated with a colon.  This bit is on if
  6758.                 the user either used recognition on a switch that ends with a
  6759.                 colon or typed a colon at the end of the switch.
  6760.  
  6761. CM%PFE (5)      The previous field was terminated with an ESC.
  6762.  
  6763. When a field cannot be parsed, B1(CM%NOP) is set in AC1, and one of the
  6764. following error codes is returned in AC2.  Note that if a list of function
  6765. descriptor blocks is given and an error code is returned, the error is
  6766. associated with the last function descriptor block in the list.
  6767. COMND JSYS                                                           Page 121
  6768.  
  6769. NPXAMB:  ambiguous
  6770.  
  6771. NPXNSW:  not a switch - does not begin with slash
  6772.  
  6773. NPXNOM:  does not match switch or keyword
  6774.  
  6775. NPXNUL:  null switch or keyword given
  6776.  
  6777. NPXINW:  invalid guide word
  6778.  
  6779. NPXNC:  not confirmed
  6780.  
  6781. NPXICN:  invalid character in number
  6782.  
  6783. NPXIDT:  invalid device terminator
  6784.  
  6785. NPXNQS:  not a quoted string - does not begin with double quote
  6786.  
  6787. NPXNMT:  does not match token
  6788.  
  6789. NPXNMD:  does not match directory or user name
  6790.  
  6791. NPXCMA:  comma not given
  6792.  
  6793. COMX18:  invalid character in node name
  6794.  
  6795. COMX19:  too many characters in node name
  6796.  
  6797.  
  6798.  
  6799. 5.6. Macros
  6800.  
  6801. Several macros (defined in MACSYM) are available to make using the COMND JSYS
  6802. more convenient.  These macros are as follows:
  6803.  
  6804.  
  6805.  
  6806. 5.6.1. FLDDB.(TYP,FLGS,DATA,HLPM,DEFM,LST)
  6807.  
  6808.  
  6809.     where:
  6810.  
  6811.          TYP  = function type
  6812.          FLGS = function flags
  6813.          DATA = function-specific data
  6814.          HLPM = help message
  6815.          DEFM = default text
  6816.          LST  = additional invocations of the FLDDB. macro (used
  6817.                  only if multiple function blocks are required)
  6818.  
  6819. This macro generates function descriptor blocks for COMND.  For example, the
  6820. following code would perform a .CMINI function:
  6821.  
  6822.  
  6823.          MOVEI T1,STEBLK           ; Get address of COMND state block
  6824.          MOVEI T2,[FLDDB.(.CMINI)] ; Get address of function block
  6825.          COMND
  6826. COMND JSYS                                                           Page 122
  6827.  
  6828. The following code would perform a .CMKEY function (assuming that the keyword
  6829. table started at address CMDTAB:
  6830.  
  6831.  
  6832.          MOVEI T1,STEBLK            ; Get address of COMND state block
  6833.          MOVEI T2,[FLDDB(.CMKEY,<CM%DPP+CM%+CM%HPP>,CMDTAB,
  6834.                   <help text>,<default text>)]
  6835.          COMND
  6836.  
  6837.  
  6838.  
  6839. 5.6.2. FLDBK.(TYP,FLGS,DATA,HLPM,DEFM,BRKADR,LST)
  6840.  
  6841. This is exactly the same as FLDDB. except that a provision has been made for
  6842. the address of the first word of a 4-word character mask (BRKADR).  This
  6843. version is for use when a user-specified character mask is required.
  6844.  
  6845.  
  6846.  
  6847. 5.6.3. BRMSK.(INI0,INI1,INI2,INI3,ALLOW,DISALLOW)
  6848.  
  6849.  
  6850.      where:
  6851.  
  6852.          INI0 =     first word of character mask
  6853.          INI1 =     second word of character mask
  6854.          INI2 =     third word of character mask
  6855.          INI3 =     fourth word of character mask
  6856.          ALLOW =    characters to allow in the mask
  6857.          DISALLOW = characters to disallow in the mask
  6858.  
  6859.  
  6860. This macro generates 4-word character masks for use with those COMND functions
  6861. that allow the user to specify his own mask.  For example, executing the
  6862. following code would allow "*" in the predefined mask for the .CMFLD function
  6863. (FLDB0 thru BLDB3):
  6864.  
  6865.     BRMSK.(FLDB0.,FLDB1.,FLDB2.,FLDB3.,<*>,)
  6866.  
  6867.  
  6868.  
  6869. 5.6.4. FLDBK.
  6870.  
  6871. Also, the BRMSK. macro may be invoked within the FLDBK. macro:
  6872.  
  6873.  
  6874.     FLDBK.(TYP,FLGS,DATA,HLPM,DEFM,[
  6875.            BRMSK.(INI0,INI1,INI2,INI3,ALLOW,DISALLOW)],LST)
  6876.  
  6877. The COMND call causes other monitor calls to be executed, depending on the
  6878. particular function that is requested.  Failure of these calls usually results
  6879. in the failure to parse the requested field.  In these cases, the relevant
  6880. error code can be obtained via the GETER and ERSTR monitor calls.
  6881.  
  6882.    - Any TBLUK error can occur on the keyword and switch functions.
  6883.  
  6884.    - Any NIN/NOUT and FLIN/FLOUT error can occur on the number functions.
  6885. COMND JSYS                                                           Page 123
  6886.  
  6887.    - Any GTJFN error except for GJFX37 can occur on the file
  6888.      specification functions.
  6889.  
  6890.    - Any IDTNC error can occur on the date/time function.
  6891.  
  6892.    - Any RCDIR or RCUSR error can occur on the directory and user
  6893.      functions.
  6894.  
  6895.    - Any STDEV error can occur on the device function.
  6896.  
  6897.  
  6898.  
  6899. 5.7. Errors
  6900.  
  6901. Generates an illegal instruction interrupt on error conditions below.
  6902.  
  6903. COMND ERROR MNEMONICS:
  6904.  
  6905. COMNX1:  invalid COMND function code
  6906.  
  6907. COMNX2:  field too long for internal buffer
  6908.  
  6909. COMNX3:  command too long for internal buffer
  6910.  
  6911. COMNX5:  invalid string pointer argument
  6912.  
  6913. COMNX8:  number base out of range 2-10
  6914.  
  6915. COMNX9:  end of input file reached
  6916.  
  6917. COMX10:  invalid default string
  6918.  
  6919. COMX11:  invalid CMRTY pointer
  6920.  
  6921. COMX12:  invalid CMBFP pointer
  6922.  
  6923. COMX13:  invalid CMPTR pointer
  6924.  
  6925. COMX14:  invalid CMABP pointer
  6926.  
  6927. COMX15:  invalid default string pointer
  6928.  
  6929. COMX16:  invalid help message pointer
  6930.  
  6931. COMX17:  invalid byte pointer in function block
  6932. MACSYM                                                               Page 124
  6933.  
  6934.                            6. MACSYM System Macros
  6935.  
  6936.  
  6937.        This chapter was written by Dan Murphy, Digital Equipment
  6938.     Corporation, July 1976.
  6939.  
  6940.  
  6941.  
  6942. 6.1. Introduction
  6943.  
  6944. MACSYM is a file of standard macro and symbol definitions for use with TOPS20
  6945. machine language programs.  Use of these definitions is recommended as a means
  6946. of producing more consistent and readable MACRO sources.  Some of the
  6947. definitions were obtained from C.MAC; others will be added if they are
  6948. generally useful.
  6949.  
  6950. MACSYM is available on SYS:  in two forms, MACSYM.UNV and MACREL.REL.  The
  6951. first is the universal file of macro and symbol definitions; the second is a
  6952. file of small support routines used by certain of the facilities (e.g., stack
  6953. variables).  The universal file is normally obtained at assembly time by the
  6954. source statement
  6955.  
  6956.     SEARCH MACSYM
  6957.  
  6958. The object file, if necessary, may be obtained by the source statement
  6959.  
  6960.     .REQUIRE SYS:MACREL
  6961.  
  6962. This instructs LINK to load the object file along with the main program.  The
  6963. file is loaded only once even if the .REQUIRE appears in several source
  6964. modules, and no explicit LINK command need be given.
  6965.  
  6966. Certain conventions are observed regarding the construction of symbols as
  6967. follows:  ("x" represents any alphanumeric)
  6968.  
  6969. xxxxx.          an opdef or macro defininition
  6970.  
  6971. .xxxxx          a constant value
  6972.  
  6973. xx%xxx          a mask, i.e., a bit or bits which specify a field.
  6974.  
  6975. Symbols containing multiple periods may be used internally by some macros.
  6976.  
  6977. Symbols containing "$" are not used or defined by DEC and are reserved for
  6978.                 customer use.
  6979.  
  6980.  
  6981.  
  6982. 6.2. Definitions
  6983.  
  6984. The following definitions are available in MACSYM and are arranged into groups
  6985. as shown.
  6986. MACSYM                                                               Page 125
  6987.  
  6988. 6.2.1. Standard Program Version
  6989.  
  6990. This macro assembles the standard contents of .JBVER.
  6991.  
  6992.     PGVER.  VERS,UPDAT,EDIT,CUST
  6993.  
  6994. where
  6995.  
  6996. VERS            is the major version number
  6997.  
  6998. UPDAT           is the update or minor version number (1=A, 2=B, ...)
  6999.  
  7000. EDIT            is the edit number
  7001.  
  7002. CUST            is the customer/SWS edit code (1=SWS, 2-7= customer)
  7003.  
  7004. A word constructed from these quantities is assembled into absolute location
  7005. .JBVER (137); the current assembly location is restored.
  7006.  
  7007.  
  7008.  
  7009. 6.2.2. Miscellaneous Constants (Symbols)
  7010.  
  7011.         .INFIN = 377777,,777777         ;plus infinity
  7012.         .MINFI = 400000,,0              ;minus infinity
  7013.         .LHALF = 777777,,0              ;left half
  7014.         .RHALF =      0,,777777         ;right half
  7015.         .FWORD = 777777,,777777         ;full word
  7016.  
  7017.  
  7018.  
  7019. 6.2.3. Control Characters (Symbols)
  7020.  
  7021. Symbols are defined for all control character codes 0 to 37 and 175-177.  The
  7022. following are the commonly used characters; see source listing for others.
  7023.  
  7024.  
  7025.         .CHBEL = 07     ;bell
  7026.         .CHBSP = 10     ;backspace
  7027.         .CHTAB = 11     ;tab
  7028.         .CHLFD = 12     ;linefeed
  7029.         .CHFFD = 14     ;formfeed
  7030.         .CHCRT = 15     ;carriage return
  7031.         .CHESC = 33     ;escape
  7032.         .CHDEL = 177    ;delete (rubout)
  7033.  
  7034.  
  7035.  
  7036. 6.2.4. PC Flags (Mask Symbols)
  7037.  
  7038.  
  7039.         PC%OVF = 1B0    ;overflow
  7040.         PC%CYO = 1B1    ;carry 0
  7041.         PC%CY1 = 1B2    ;carry 1
  7042.         PC%FOV = 1B3    ;floating overflow
  7043.         PC%BIS = 1B4    ;first  part   done   (byte   increment
  7044.                          suppress)
  7045.         PC%USR = 1B5    ;user mode
  7046. MACSYM                                                               Page 126
  7047.  
  7048.         PC%UIO = 1B6    ;user IO mode
  7049.         PC%LIP = 1B7    ;last instruction public
  7050.         PC%AFI = 1B9    ;ADDRESS FAILURE INHIBIT
  7051.         PC%ATN = 1B10   ;apr trap number
  7052.         PC%FUF = 1B11   ;floating underflow
  7053.         PC%NDV = 1B12   ;no divide
  7054.  
  7055.  
  7056.  
  7057. 6.2.5. Macros to Manipulate Field Masks
  7058.  
  7059. Many of the symbols in MACSYM and MONSYM define flag bits and fields.  A field
  7060. mask is a full-word value with a single contiguous group of 1's in the field.
  7061. E.g., 000000,,777000 defines a field consisting of bits 18-26.  The following
  7062. macros may be used in expressions to deal with these masks.
  7063.  
  7064.  
  7065.  
  7066. 6.2.5.1. WID(MASK)
  7067.  
  7068. Width - computes the width of the field defined by the mask, i.e., the number
  7069. of contiguous 1-bits.  Value is not defined if mask contains non-contiguous
  7070. 1-bits.
  7071.  
  7072.  
  7073.  
  7074. 6.2.5.2. POS(MASK)
  7075.  
  7076. Position - computes the position of the field defined by the mask.  The
  7077. position of a field is always represented by the bit number of the rightmost
  7078. bit of the field regardless of the width of the field.  This is sufficient to
  7079. specify the entire field in the case of flags (1-bit fields).
  7080.  
  7081.  
  7082.  
  7083. 6.2.5.3. POINTR(LOC,MASK)
  7084.  
  7085. Byte pointer - constructs a byte pointer to location LOC which references the
  7086. byte defined by MASK, e.g.,
  7087.  
  7088.     POINTR(100,77) = POINT 6,100,35 = 000600,,100
  7089.  
  7090.  
  7091.  
  7092. 6.2.5.4. FLD(VAL,MASK)
  7093.  
  7094. Field value - Places the value VAL into the field defined by MASK, e.g.,
  7095. FLD(3,700) = 0,,000300
  7096.  
  7097.  
  7098.  
  7099. 6.2.5.5. .RTJST(VAL,MASK)
  7100.  
  7101. Right-justify - Shift VAL right such that the field defined by MASK is moved
  7102. to the low-order bits of the word, e.g.,
  7103.  
  7104.     .RTJST(300,700) = 3
  7105. MACSYM                                                               Page 127
  7106.  
  7107. 6.2.5.6. MASKB(LBIT,RBIT)
  7108.  
  7109. Mask - construct a mask word which defines a field from bit LBIT to bit RBIT
  7110. inclusive.  E.g., MASKB(18,26) = 0,,777000.
  7111.  
  7112.  
  7113.  
  7114. 6.2.6. Instructions Using Field Masks (Macros)
  7115.  
  7116. The following mnemonics are similar to certain machine instructions used to
  7117. move and test bits and fields.  These macros select the most efficient
  7118. instruction for the mask being used.
  7119.  
  7120.  
  7121.  
  7122. 6.2.6.1. MOVX AC,MASK
  7123.  
  7124. Load AC with constant.  MASK may be any constant; this assembles one of the
  7125. following instructions: MOVEI, MOVSI, HRROI, HRLOI, or MOVE literal.
  7126.  
  7127.  
  7128.  
  7129. 6.2.6.2. TXmn AC,MASK
  7130.  
  7131. where m is:  N, Z, O, C
  7132.       n is:  E, N, A, null
  7133.  
  7134. There are 16 definitions of this form which include all of the modification
  7135. and testing combinations fo the test instructions, i.e., TXNN, TXNE, TXO,
  7136. TXON, etc.  A TL, TR, or TD literal is assembled as appropriate.
  7137.  
  7138.  
  7139.  
  7140. 6.2.6.3. IORX AC,MASK; ANDX AC,MASK; XORX AC,MASK
  7141.  
  7142. These are equivalent to certain of the TX functions but are provided for
  7143. mnemonic value.
  7144.  
  7145.  
  7146.  
  7147. 6.2.6.4. JXm AC,MASK,ADDRESS
  7148.  
  7149. This is a set of four definitions which jump to ADDRESS if the field specified
  7150. by MASK meets a certain condition.  The condition (m) may be:
  7151.  
  7152.  
  7153.         E - jump if all masked bits are 0
  7154.         N - jump if not all masked bits are 0
  7155.         O - jump if all masked bits are 1
  7156.         F - jump if not al masked bits are 1 (false)
  7157.  
  7158. These macros will assemble into one, two, or three instructions as necessary
  7159. to effect the specified result, e.g.
  7160.  
  7161.  
  7162.         JXN T1,1B0,FOO  = JUMPL T1,FOO
  7163.         JXE T1,770,FOO  = TRNN T1,770
  7164.                          JRST FOO
  7165. MACSYM                                                               Page 128
  7166.  
  7167. 6.2.7. Data Structure Facility (Macros)
  7168.  
  7169. This set of macros provides a comprehensive facility for the definition and
  7170. use of data structures.  It is an extension of some of the techniques
  7171. represented by the field mask facilities above.  Typically, a data structure
  7172. definition will include some information about the location of the data in
  7173. memory as well as its position within a word.  These facilities are intended
  7174. to provide the following advantages:
  7175.  
  7176.    - Data items may be referenced more mnemonically, e.g., two data items
  7177.      in the same word would be given different names rather than merely
  7178.      being known as the left half or right half of the word.
  7179.  
  7180.    - Should the need arise, storage formats may be changed without
  7181.      incurring the expense of a search of the code to change each
  7182.      reference.
  7183.  
  7184.  
  7185.  
  7186. 6.2.7.1. DEFSTR and MSKSTR
  7187.  
  7188.     DEFSTR NAME,LOCATION,POSITION,SIZE
  7189.  
  7190.     MSKSTR NAME,LOCATION,MASK
  7191.  
  7192. These macros both define a data structure called NAME.  LOCATION specifies the
  7193. memory location of the desired word and consists of address, index, and
  7194. indirect fields in the usual form, i.e., @address(index).  Any of the fields
  7195. may be omitted if not needed, and the entire location argument may be null in
  7196. some circumstances.  The remaining arguments define the desired field.  DEFSTR
  7197. specifies the field in terms of its position (right-most bit number) and size
  7198. (number of bits), while MSKSTR specifies the field by a full-word mask as
  7199. described earlier.  Normally, the actual storage to be used is declared
  7200. separately, e.g., by a BLOCK statement.
  7201.  
  7202. As a simple example, consider an array of full-word data items.  We wish to
  7203. use the name FOO for the data itself, so we declare the actual storage by some
  7204. other name, e.g.,
  7205.  
  7206.     FOO1:   BLOCK n
  7207.  
  7208. Then we declare the structure by
  7209.  
  7210.     DEFSTR FOO,FOO1(FOOX),35,36
  7211.  
  7212. This says that we declare a data item called FOO, that the items are addressed
  7213. by FOO1(FOOX) (assuming that the index is kept in register FOOX), that the
  7214. items are 36-bit quantities with the rightmost bit in bit 35 (i.e., full
  7215. words).  If instead, we wish to declare that each word of FOO1 consists of an
  7216. item in the left half and two 9-bit items in the right half, we could write:
  7217.  
  7218.  
  7219.                 DEFSTR FIRSTD,FOO1(FOOX),17,18  ; LH item.
  7220.                 DEFSTR SECOND,FOO1(FOOX),26,9   ; One 9-bit item
  7221.                 DEFSTR THIRDD,FOO1(FOOX),35,9   ; Another 9-bit item.
  7222.  
  7223.  
  7224. Data items defined with DEFSTR or MSKSTR may be referenced in a general way.
  7225. MACSYM                                                               Page 129
  7226.  
  7227. At each instance, additional location information may be given if necessary.
  7228. A set of reference functions (macros) is defined for most common operations,
  7229. some affecting AC and memory, others only memory.  For example, the LOAD
  7230. function loads a data item into an AC and is written as
  7231.  
  7232.     LOAD AC,NAME,LOCATION
  7233.  
  7234. where
  7235.  
  7236. AC              is the AC to be loaded
  7237.  
  7238. NAME            is the structure name as defined with DEFSTR
  7239.  
  7240. LOC             is location specification in addition to that declared in the
  7241.                 structure definition.  This field may be null in some cases.
  7242.  
  7243. Taking the example definitions above, we may write
  7244.  
  7245.     LOAD T1,FOO
  7246.  
  7247. which would assemble into
  7248.  
  7249.     MOVE T1,FOO1(FOOX)
  7250.  
  7251. or
  7252.  
  7253.     LOAD T1,SECOND   = LDB T1,[POINT 9,FOO1(FOOX),26]
  7254.  
  7255.     LOAD T1,FIRSTD   = HLRZ T1,FOO1(FOOX)
  7256.  
  7257. Note that the macro compiles the most efficient instruction available to
  7258. reference the specified field.
  7259.  
  7260. The optional third argument is provided to allow some of the location
  7261. information to be specified at each instance.  For example, if the definition
  7262. is
  7263.  
  7264.     DEFSTR FOO,FOO1,35,36
  7265.  
  7266. Then the index may be specified at each instance, e.g.,
  7267.  
  7268.     LOAD T1,FOO,(XX)
  7269.  
  7270.     LOAD T2,FOO,(T1)
  7271.  
  7272. The specification given in the definition is concatentated with the
  7273. specification given in the reference.
  7274.  
  7275. The following reference functions are presently defined:
  7276.  
  7277.  
  7278.         LOAD AC,NAME,LOC        load data item into AC
  7279.         STOR AC,NAME,LOC        store data item  from  AC  into
  7280.                                  memory
  7281.  
  7282. The data item is right justified in the AC.
  7283.  
  7284.  
  7285. MACSYM                                                               Page 130
  7286.  
  7287.         SETZRO NAME,LOC         set the data item to zero
  7288.         SETONE NAME,LOC         set the data item to all ones
  7289.         SETCMP NAME,LOC         complement the data item
  7290.         INCR NAME,LOC           increment the data item
  7291.         DECR NAME,LOC           decrement the data item
  7292.  
  7293. For functions not specifically provided, the following may be used:
  7294.  
  7295.  
  7296.         OPSTR OP,NAME,LOC
  7297.         OPSTRM OP,NAME,LOC
  7298.  
  7299. OP is any machine instruction written without an address field.  It will be
  7300. assembled such as to reference the specified data structure.  OPSTR is used if
  7301. memory is not modified, OPSTRM is used if memory is modified.  E.g.,
  7302.  
  7303.     OPSTRM <ADDM T1,>,FOO
  7304.  
  7305. to add the quantity in T1 to the data item FOO.
  7306.  
  7307. The following test and transfer functions are presently defined:
  7308.  
  7309.  
  7310.         JE NAME,LOC,ADDR        jump to ADDR if data is 0
  7311.         JN NAME,LOC,ADDR        jump to ADDR if data is not 0
  7312.  
  7313. The following test and transfer functions take a list of structure names
  7314. (surrounded by angle-brackets) or a single structure name.  They compile code
  7315. to test each data item in the order given, and will stop as soon as the result
  7316. of the function is known (e.g., AND encounters a false term).
  7317.  
  7318.  
  7319.   JOR NAMLST,LOC,ADDR   jump to ADDR if any data item is true
  7320.                           (non-0)
  7321.   JAND NAMLST,LOC,ADDR  jump to ADDR if all data items true
  7322.                           (non-0)
  7323.   JNOR NAMLST,LOC,ADDR  jump to ADDR if all data items false
  7324.                           (0)
  7325.   JNAND NAMLST,LOC,ADDR jump to ADDR if any data item is false
  7326.                           (0)
  7327.  
  7328. These functions optimize multiple fields in the same word if they are adjacent
  7329. in the structure list.  If the final location is an accumulator, further
  7330. optimization is done.
  7331.  
  7332. As a final example of the data structure facility, consider the typical case
  7333. of data organized into unit blocks with pointers to other blocks.  Such a
  7334. block may appear as
  7335.  
  7336.  
  7337.       Flag 1   Flag 2           Code            List pointer
  7338.           !    !                 !                   !
  7339.           V    V                 v                   V
  7340.         +---+---+---------+---------+-------------------------+
  7341.         !   !   !/////////!         !                         !
  7342.         +---+---+---------+---------+-------------------------+
  7343.         !       additional  node  data                        !
  7344.         +-----------------------------------------------------+
  7345.         !                       ''''''''                      !
  7346. MACSYM                                                               Page 131
  7347.  
  7348. We assume that n-word blocks will be allocated from a free pool at execution
  7349. time.  The structure of the block is declared as follows:
  7350.  
  7351.  
  7352.         MSKSTR FLAG1,0,1B0
  7353.         MSKSTR FLAG2,0,1B1
  7354.         DEFSTR CODE,0,17,9
  7355.         DEFSTR LINK,0,35,18
  7356.         DEFSTR NODDAT,1,35,36
  7357.  
  7358. Note that the location field contains only the offset address of the word
  7359. within the block; the address of the block will be specified in an index at
  7360. each reference.  References would appear as follows:
  7361.  
  7362.  
  7363.         LOAD T1,LINK,(T1)       ;step to next node in list
  7364.         STOR T2,CODE,(T1)       ;set new block code
  7365.         JE FLAG1,(T1),FLOFF     ;jump if flag1 is off
  7366.         JAND <FLAG1,FLAG2>,(T1),FLGSON  ;jump if flag1 and
  7367.                                         ; flag2 are both on
  7368.  
  7369.  
  7370.  
  7371. 6.2.8. Subroutine Conventions (Macros/opDefs)
  7372.  
  7373. The following definitions are used to make subroutine mechanics more mnemonic.
  7374. Reference is made to these conventions elsewhere in this document.
  7375.  
  7376.  
  7377.  
  7378. 6.2.8.1. CALL address
  7379.  
  7380. Call subroutine at address; equivalent to PUSHJ P,address
  7381.  
  7382.  
  7383.  
  7384. 6.2.8.2. RET
  7385.  
  7386. Return from subroutine; equivalent to POPJ P,
  7387.  
  7388.  
  7389.  
  7390. 6.2.8.3. RETSKP
  7391.  
  7392. Return from subroutine and skip; equivalent to
  7393.  
  7394.  
  7395.         JRST [AOS 0(P)
  7396.               RET]
  7397.  
  7398.  
  7399.  
  7400. 6.2.8.4. CALLRET address
  7401.  
  7402. Call the subroutine at address and return immediately thereafter; equivalent
  7403. to
  7404. MACSYM                                                               Page 132
  7405.  
  7406.  
  7407.         CALL address
  7408.          RET
  7409.         RETSKP
  7410.  
  7411. CALLRET assembles as JRST but should be treated as if it assembles into
  7412. several instructions and cannot be skipped over.
  7413.  
  7414.  
  7415.  
  7416. 6.2.8.5. AC Conventions
  7417.  
  7418. The facilities described here assume in some cases the following accumulator
  7419. naming conventions:
  7420.  
  7421. AC1-AC4         temporary, may be used to pass and return values
  7422.  
  7423. AC0,AC5-AC15    preserved, i.e., saved and restored if used by subroutine
  7424.  
  7425. AC16            temporary, used as scratch by some MACSYM facilities
  7426.  
  7427. AC17            stack pointer
  7428.  
  7429.  
  7430.  
  7431. 6.2.9. Named Variable Facilities (Macros and Runtime Code)
  7432.  
  7433. A traditional deficiency of machine language coding environments is facilities
  7434. for named transient storage ("automatic", etc.).  Sometimes, permanent storage
  7435. is assigned (e.g., by BLOCK statements) when no recursion is expected.  More
  7436. often, ACs are used for a small number of local variables.  In this case, the
  7437. previous contents must usually be saved, and a general mnemonic (e.g., T1, A,
  7438. X) is usually used.  In some cases, data on the stack is referenced, e.g.,
  7439.  
  7440.     MOVE T1,-2(P)
  7441.  
  7442. but this is completely non-mnemonic and likely to fail if addition storage is
  7443. added to or removed from the stack.  The facilities described here provide
  7444. local named variable storage.  Two of these allocate the storage on the stack;
  7445. the third allocates it in the ACs.
  7446.  
  7447.  
  7448.  
  7449. 6.2.9.1. STKVAR namelist
  7450.  
  7451. This statement allocates space on the stack and assigns local names.  The list
  7452. consists of one or more symbols separated by commas.  Each symbol is assigned
  7453. to one stack word.  If more than one word is needed for a particular variable,
  7454. then a size parameter may be given enclosed with the symbol in angle-brackets.
  7455. E.g.,
  7456.  
  7457.  
  7458.         STKVAR <AA,BB>
  7459.         STKVAR <AA,<BB,3>>
  7460.  
  7461. Variables declared in this way may be referenced as ordinary memory operands,
  7462. e.g.,
  7463. MACSYM                                                               Page 133
  7464.  
  7465.  
  7466.         MOVE T1,AA
  7467.         DPB T1,[POINT 6,BB,5]
  7468.  
  7469. Each variable is assembled as a negative offset from the current stack
  7470. location, e.g.,
  7471.  
  7472.  
  7473.         MOVE T1,AA      =       MOVE T1,-2(P)
  7474.  
  7475. Hence, no other index may be given in the address field.  Indirection may be
  7476. used if desired.  There is no explicit limit to the scope of the variables
  7477. defined by STKVAR, but the following logical constraints must be observed:
  7478.  
  7479.    1. The stack pointer must not be changed within the logical scope of
  7480.       the variables, e.g., by PUSH or PUSHJ instructions.  This also
  7481.       implies that the variables may not be referenced within a local
  7482.       subroutine called from the declaring routine.
  7483.  
  7484.    2. The declaring routine must return with a RET or RETSKP.  This will
  7485.       cause the stack storage to be automatically deallocated.
  7486.  
  7487. STKVAR assumes that the stack pointer is in P, and it uses .A16 (AC16) as a
  7488. temporary.
  7489.  
  7490.  
  7491.  
  7492. 6.2.9.2. TRVAR namelist
  7493.  
  7494. This statement allocates stack space and assigns local names.  It is
  7495. equivalent to STKVAR except that it uses one additional preserved AC and
  7496. eliminates some of the scope restrictions of STKVAR.  In particular, it uses
  7497. .FP (AC15) as a frame pointer.  .FP is setup (and the previous contents saved)
  7498. at the same time as the stack space is allocated, and references to the
  7499. variables use .FP as the index rather than P. This allows additional storage
  7500. to be allocated on the stack and allows the variables to be referenced from
  7501. local subroutines.  Note that all such subroutines (i.e., all variable
  7502. references) must appear after the declaration in the source.  STKVAR may be
  7503. used within TRVAR, e.g., by a local subroutine.
  7504.  
  7505. STKVAR and TRVAR declarations are normally placed at the beginning of a
  7506. routine.  They need not be the first statement.  If a routine has two or more
  7507. entry points, a single declaration may be placed in the common path, or
  7508. several identical declarations may be used in each of the separate paths.
  7509. Care must be taken that control passes through exactly one declaration before
  7510. any variables are referenced.  E.g.,
  7511. MACSYM                                                               Page 134
  7512.  
  7513.  
  7514.         ;MAIN ROUTINE
  7515.  
  7516.         ENT1:   TXO F,FLAG      ;entry 1, set flag
  7517.                 JRST ENT0       ;join common code
  7518.  
  7519.         ENT2:   TXZ F,FLAG      ;entry 2, clear flag
  7520.         ENT0:   TRVAR <AA,BB>   ;common code, declare locals
  7521.                 ..
  7522.                 CALL LSUBR      ;call local subroutine
  7523.                 ..
  7524.                 RET
  7525.  
  7526.         ;LOCAL SUBROUTINE
  7527.  
  7528.         LSUBR:  STKVAR <CC>     ;local subroutine, declare
  7529.                                 ; locals
  7530.                 MOVE T1,AA      ;reference outer routine
  7531.                                 ; variable
  7532.                 MOVEM T1,CC     ;reference local variable
  7533.                 ..
  7534.                 RETSKP          ;skip return
  7535.  
  7536.  
  7537.  
  7538. 6.2.9.3. ASUBR namelist
  7539.  
  7540. This statement is used to declare formals for a subroutine.  The namelist
  7541. consists of from one to four variable names.  The arguments are passed to the
  7542. subroutine in ACs T1 to T4, and values may be returned in these same ACs.
  7543. ASUBR causes these four ACs to be stored on the stack (regardless of how many
  7544. formals are declared), and defines the variable names as the corresponding
  7545. stack locations.  The return does not restore T1-T4.  The same frame pointer
  7546. AC is used by ASUBR and TRVAR, hence these declarations may not be used within
  7547. the same routine.  Scope rules are the same as for TRVAR.
  7548.  
  7549.  
  7550.  
  7551. 6.2.9.4. ACVAR namelist
  7552.  
  7553. This statement declares local storage which is allocated from the set of
  7554. preserved ACs.  An optional size parameter may be given for each variable.
  7555. The previous contents of the ACs are saved on the stack and automatically
  7556. restored on the next return.  Variables declared by ACVAR may be referenced as
  7557. ordinary AC operands.
  7558.  
  7559.  
  7560.  
  7561. 6.2.10. Miscellaneous
  7562.  
  7563.  
  7564.  
  7565. 6.2.10.1. TMSG string
  7566.  
  7567. Type literal string; uses AC1, outputs to primary output.  E.g., TMSG <TYPE
  7568. THIS TEXT>
  7569. MACSYM                                                               Page 135
  7570.  
  7571. 6.2.10.2. JSERR
  7572.  
  7573. Handle unexpected JSYS error; type "?JSYS ERROR:  message".  This is a single
  7574. instruction subroutine call which returns +1 always.
  7575.  
  7576.  
  7577.  
  7578. 6.2.10.3. JSHLT
  7579.  
  7580. Handle unexpected fatal JSYS error; same as JSERR except does HALTF instead of
  7581. returning.
  7582.  
  7583.  
  7584.  
  7585. 6.2.10.4. MOD.(DEND,DSOR)
  7586.  
  7587. Modulo - In assembly-time expression, gives remainder of DEND divided by DSOR;
  7588. e.g., MOD.  10,3 = 1.
  7589. Columbia                                                             Page 136
  7590.  
  7591.                        7. Columbia Macros and Packages
  7592.  
  7593.  
  7594. The items described in this chapter are peculiar to Columbia's DECSYSTEM-20.
  7595. Programs that use these facilities are not transportable to other
  7596. DECSYSTEM-20's (except in their .EXE form) unless the appropriate library
  7597. files are taken, too.
  7598.  
  7599.  
  7600.  
  7601. 7.1. Utility UUO Package for Macro-20
  7602.  
  7603.     [ Programs and text by Chris Ryland, 1978. ]
  7604.  
  7605.  
  7606.  
  7607.  
  7608.  
  7609.                               Preliminary Specs
  7610.  
  7611.        Note: all of these UUOs have a general restriction that must be
  7612.     observed: no strings addressed as arguments may live in the ACs.
  7613.     Further, none of the COMND functions may use FLDDBs that address
  7614.     indirectly through ac's t1-t4, .fp or p.
  7615.  
  7616.  
  7617.  
  7618. 7.1.1. Formatted Printing Package
  7619.  
  7620.     %print <format string>, <
  7621.             addr of arg1
  7622.             addr of arg2
  7623.                 ...>
  7624.  
  7625.  
  7626. This expands into a call on the %uprint uuo, with argument
  7627.  
  7628.     [[point 7,[asciz/string/], addr of arg1, addr of arg2, ...]
  7629.  
  7630. If you understand that the arguments are just part of a literal, then you can
  7631. understand why they're in this format, and how to extend it; e.g., you might
  7632. also say
  7633.  
  7634.     %print <format>, <exp arg1-addr, arg2-addr, ...>
  7635.  
  7636. or call the %uprint uuo directly, if the format string is a variable, e.g.,
  7637.  
  7638.     %uprint [exp fmstr, arg1-addr, arg2-addr]
  7639.  
  7640. The semantics of this beast are:  the characters in the format string are
  7641. output sequentially, until an escape character `%' is seen; then, a argument
  7642. descriptor is eaten from the format string (see below for the definition of
  7643. the argument descriptor), and one or more arguments are eaten from the
  7644. argument list, and used for output, as directed by the descriptor.  the basic
  7645. idea here is that each argument descriptor item directs special output
  7646. handling for a group of argument items (usually one).  to make this discussion
  7647. more concrete, here is an example of how this macro might be used:
  7648. Columbia                                                             Page 137
  7649.  
  7650.  
  7651.         %print <Here's a number: %d, and the time: %@n%/>, <
  7652.                 [^d234]
  7653.                 [ot%day!ot%fdy]
  7654.         >
  7655.  
  7656. What happens here is that "Here's a number: " is printed on the primary
  7657. output, and then the argument descriptor %d is processed, which slurps up the
  7658. next argument, [^d234] (remember, all arguments are actually addresses of the
  7659. object in question), and prints it as a decimal number.  then, ", and the
  7660. time: " is printed --nothing special here--, and the argument descriptor %@n
  7661. is hit; this descriptor, mnemonic for `the time as of now', has a @ modifier
  7662. (described in detail below) which causes the print package to pick up the next
  7663. argument from the list and use it as the date/time format value (again, what's
  7664. actually there is a literal, since arguments are always addresses of the value
  7665. to be used).  finally, the arg descriptor `%/' is seen, which means print a
  7666. CRLF, and we're all done (because we hit the end of the asciz format string).
  7667.  
  7668. Each argument descriptor is of the form `%<@><key>'.  The `@' means pick up
  7669. additional data to modify the action of the <key>, from the argument list
  7670. (this data is eaten just like data that is output; see below).  Then, the
  7671. action denoted by <key> is taken, which results in one or more data items
  7672. being eaten from the argument list and output according the the format <key>.
  7673. these constant references to `eating' are to graphically state that when an
  7674. argument is used, it disappears from the argument list.  thus, you can think
  7675. of the argument list as being eaten one argument at a time, from the top to
  7676. the bottom (or left to right, depending on how you coded it).
  7677.  
  7678. Note that this type of output differs from Fortran-style formatting, in that
  7679. it is format-driven, not argument-driven.  E.g., in Fortran, each list item
  7680. (argument) is taken in turn, and the next format item selected to be used as
  7681. the output specification.  in this package, just the reverse is done; the
  7682. format items cause argument-handling.
  7683.  
  7684. If any Jsys errors occur during printing, then if the %print is followed by an
  7685. erjmp or ercal, the jump or call is taken, just as in a jsys invocation.
  7686. Otherwise, a fatal error occurs.
  7687.  
  7688. The equivalent, but skipping, UUO is %prSkp; it returns +2 on success (or +3
  7689. if it has an erjmp or ercal after it).
  7690.  
  7691. The various argument descriptors, also known as format items, are:
  7692.  
  7693. %%              print a `%'
  7694.  
  7695. %!              ignore all following characters until a `!' is seen, at which
  7696.                 point formatting resumes normally.  This is designed to allow
  7697.                 formats to nicely cross line boundaries.
  7698.  
  7699. %{              print a <
  7700.  
  7701. %}              print a > (these last two are for non-paired <>)
  7702.  
  7703. %/              print a Carriage-Return/Line-feed pair
  7704.  
  7705. %=              use the argument as a destination designator for the remainder
  7706.                 of the output for this %print call; note that any JFN
  7707.                 top-of-stack is then ignored for the rest of the %print (and
  7708. Columbia                                                             Page 138
  7709.  
  7710.                 is NOT updated after the %print is done).
  7711.  
  7712. %_              print a Horizontal Tab
  7713.  
  7714. %^              print a Form-Feed (^L)
  7715.  
  7716. %c              print the name of the Connected directory, with punctuation
  7717.                 (str:<...>); use any @ modifier value as a directory number,
  7718.                 and print its name instead
  7719.  
  7720. %d              print a Decimal number; use any @ modifier as the NOUT format.
  7721.                 If no radix is given in the @ modifier case, decimal radix is
  7722.                 used.
  7723.  
  7724. %e              with no modifier, print the last error message encountered by
  7725.                 this process; with a modifier, use the argument value as an
  7726.                 error number to print symbolically.
  7727.  
  7728. %?              do error synchronization: clear terminal input and wait for
  7729.                 terminal output to drain, and print a newline, followed by a
  7730.                 "?".  Rest of this %print will go to the physical terminal
  7731.                 device.
  7732.  
  7733. %f              print the Floating (single-precision) value of the argument;
  7734.                 use any @ modifier as the FLOUT format
  7735.  
  7736. %h              print the ascii cHaracter value of the argument
  7737.  
  7738. %i              like %d, but print +Inf if negative (for printing positive
  7739.                 numbers)
  7740.  
  7741. %j              print the name of the file as given by the Jfn argument; use
  7742.                 any @ modifier value as the JFNS format
  7743.  
  7744. %n              print the date and time of Now; use any @ modifier value as
  7745.                 the ODTIM format
  7746.  
  7747. %o              print the argument as an (unsigned) Octal number; use any
  7748.                 @ modifier value as the NOUT format.  If no radix is given in
  7749.                 the @ modifier case, octal radix is used.
  7750.  
  7751. %s              print the argument as an asciz String (of byte size as given
  7752.                 by the argument's byte size); -1 in the left half of the
  7753.                 argument means treat it as 7-bit asciz (NB: the argument is a
  7754.                 really the address of a byte pointer, not a byte pointer
  7755.                 itself; see examples below)
  7756.  
  7757. %t              print the date and Time as given by the argument; use any
  7758.                 @ modifier value as the ODTIM format
  7759.  
  7760. %u              print the user's login ID, with no punctuation; with a
  7761.                 @ modifier, print the user name of the given user number
  7762.  
  7763. %v              print the deVice name for the designator given as argument
  7764.  
  7765. %x              print the argument as a siX-bit value.
  7766. Columbia                                                             Page 139
  7767.  
  7768. 7.1.2. %prPush and %prPop
  7769.  
  7770.     Warning: this facility is not implemented yet!
  7771.  
  7772. These two instructions push and pop the %print UUO's output JFN stack,
  7773. respectively.  The top-of-stack entry (or .priou if the stack is empty) is
  7774. used as the destination designator, and is updated after each %print (unless a
  7775. %= or %? is used in the format string, see above), so that a byte pointer may
  7776. be effectively used as the output destination.  %prPush takes an argument
  7777. which is an address of the output designator (a JFN or a byte pointer).
  7778. %prPop simply pops off the top of stack and discards it.  (Note that you can't
  7779. have indexed or indirected byte pointers, as this is doable but infinitely
  7780. hairy for the UUO package.  Also note that since the destination designator
  7781. itself is updated after each %print, you can't use a literal (e.g. a byte
  7782. pointer) for the argument to %prPush, unless you don't mind modifying pure
  7783. data (which you should!).)
  7784.  
  7785.  
  7786. Some examples are:
  7787.  
  7788. sPtr:   point 7, buffer         ; Byte pointer to a memory buffer.
  7789.           :
  7790.         %prPush sPtr            ; Use buffer as general
  7791.           :                     ;   output area.
  7792.         %print <foo, bar>       ; Output to it.
  7793.           :                     ; (sPtr now points at last char).
  7794.         %prPop                  ; Get rid of this destination
  7795.           :                     ;  now that we're done.
  7796. Columbia                                                             Page 140
  7797.  
  7798. 7.1.3. COMND-Jsys-Made-Easy Package
  7799.  
  7800. This set of macros implements an easy access route to the COMND Jsys;
  7801. familiarity with COMND and its functions IS required, though - we're only
  7802. trying to ease the pain of using it, not learning about it.
  7803.  
  7804. Following are the macros used to invoke the different functions of the COMND
  7805. Jsys as well as ancillary tasks such as setting up various control blocks,
  7806. getting information out of some of the data structures deliberately hidden to
  7807. ease use of COMND, etc.  The naming conventions used are designed to follow as
  7808. much as possible the names of each of the COMND functions, with slightly
  7809. varied punctuation that corresponds to CUsym conventions.  E.g., the .cmkey
  7810. function of COMND is invoked with the %cmkey macro; induction should get you
  7811. the rest.
  7812.  
  7813. Some philosophy about error-handling: any COMND function can fail in two ways
  7814. (actually, three, but the third is merged into the first to make your job all
  7815. that much easier):  the function can't be parsed with the given input, or the
  7816. user deletes input back into an already-parsed field.  We treat these two
  7817. `errors' uniformly: each invocation of a function either returns normally if
  7818. no error occurs, or takes an erjmp or ercal path (if provided) if an error is
  7819. found.  Thus, a simple, uniform method of handling parse errors and reparse
  7820. conditions is provided: each subroutine of the main parse routine can always
  7821. return non-skip on any error (real or reparse), or skip on success.  The main
  7822. parse routine can worry about whether a real error occurred, and print an
  7823. appropriate message, restarting the parse from scratch, or whether just a
  7824. reparse is needed, restarting from the first parse step.  When an error
  7825. occurs, t1 contains the flags from COMND (note in the success case that t1
  7826. isn't modified), and t1 is not set.  If a real COMND Jsys error (i.e., not a
  7827. user parse error occurs, like a COMND internal buffer overflow), the parse
  7828. error bit will be set, and the error return will happen as usual; this is done
  7829. to make COMND errors be treated uniformly.
  7830.  
  7831. Note that each COMND function, if it succeeds, returns a value in t2 (even if
  7832. it doesn't return any useful result).
  7833.  
  7834. Also, if any COMND function is invoked with more than one FDB (i.e., alternate
  7835. FDBs are used), then upon return t3 contains what it normally after the COMND
  7836. Jsys (q.v.):  the FDB actually used, and the first FDB given.
  7837.  
  7838.     %cmini (prompt, flags, iojfn, gjfblk)
  7839.  
  7840. This macro prepares everything for a command parse.  All the arguments are
  7841. optional; their use is:
  7842.  
  7843. prompt          a text string used as the prompt; e.g., <<CRDIR>>.  If not
  7844.                 supplied, the prompt `>' is used.  Note that if a `>' is
  7845.                 required on the end of this prompt, then you must use the form
  7846.                 <<prompt>>.  Blame macro.
  7847.  
  7848. flags           the flags destined for the (left half of the) CSB .cmflg word,
  7849.                 such as raise all input, wake on every field, etc.
  7850.  
  7851. iojfn           the <input jfn,,output jfn> pair for the parse.
  7852.  
  7853. gjfblk          the address of the GTJFN argument block, used in the .cmifi,
  7854.                 .cmofi, .cmfil functions (and it must be supplied if you plan
  7855.                 to use these functions).  Its length must be at least .gjln
  7856. Columbia                                                             Page 141
  7857.  
  7858.                 (defined in CUsym).
  7859.  
  7860. This function will only fail if some horrible mistake has been made, usually
  7861. by the COMND package, so expect success.  Note that this UUO only does a
  7862. .CMini COMND Jsys on the second and subsequent invocations, until a %cmres UUO
  7863. is done, at which point it will re-initialize everything (see the %cmres UUO
  7864. description below for an explanation).
  7865.  
  7866.  
  7867.  
  7868. 7.1.3.1.  %cmRes
  7869.  
  7870. This UUO, automatically done by %setUp at normal program startup, resets all
  7871. COMND parsing information, so that the next %cmini UUO will cause a full setup
  7872. of the Command State Block (set up the prompt, reset all the buffer pointers,
  7873. etc.).  It should be invoked whenever you intend to start a whole new section
  7874. of parsing (e.g., changing the prompt or the set of commands, such as
  7875. subcommand mode).  In the simplest case, you never have to worry about it, as
  7876. it's automatically done at startup.  In the most usual case where it would be
  7877. needed, a subroutine called to do some subsidiary parsing (e.g., the GetOK
  7878. routine in mac:), the safest approach is to do a %cmres before the
  7879. subroutine's %cmini, and a %cmres after finishing its parsing job.  This
  7880. guarantees that the caller won't get hurt.
  7881.  
  7882.  
  7883.  
  7884. 7.1.3.2. %cmKey (keytab, help, default, flags)
  7885.  
  7886. This macro invokes the .cmkey COMND function; upon success, t2 contains the
  7887. address of the table entry where the parsed keyword was found.  All but the
  7888. first arguments are optional.
  7889.  
  7890. keytab          address of a TBLUK keyword table
  7891.  
  7892. help            a literal string (usually enclosed in <> if it contains
  7893.                 anything other than alphanumerics and spaces) that will be
  7894.                 used as the help message.  if not given, the default help
  7895.                 message is used.
  7896.  
  7897. default         a literal string that will be used as the default keyword if
  7898.                 none is supplied; if not given, no default is possible.
  7899.  
  7900. flags           flags, such as suppress default help, etc.
  7901.  
  7902. Note that these arguments are just used to build a function descriptor block,
  7903. and thus the usual things happen in their absence or presence.  Many of the
  7904. other macros use the same structure for their arguments, and the same comments
  7905. apply as here, so they will usually be elided.  If you need to use a
  7906. hand-crafted function descriptor block, you can call the COMND package uuo
  7907. directly, with the address of the FDB, as in %comnd [flddb. .cmkey,...].
  7908.  
  7909. Rather than give each COMND function as above, we will let you induce on the
  7910. `base step' above and assume that the remaining functions are invoked
  7911. similarly.  What follows are those functions that do not map directly to a
  7912. COMND function.
  7913. Columbia                                                             Page 142
  7914.  
  7915. 7.1.3.3. %cmgab bp
  7916.  
  7917. This function asks the COMND interface package to get the current contents of
  7918. the atom buffer into the string pointed to by the byte-pointer given as
  7919. argument; this cannot fail.  Note that the atom buffer can be quite long --how
  7920. long depends on the current implementation of the COMND package, but a
  7921. reasonable size would be 100 words--, so be wary of extremely long atoms.  The
  7922. byte pointer is updated.
  7923.  
  7924. Note that `bp' is the address of where the byte pointer can be found; i.e.,
  7925. the effective address of this UUO is the address of the byte pointer.  BEWARE:
  7926. if you supply the argument as a literal, the byte pointer gets updated in the
  7927. literal pool; if you use the same literal later, it will not be pointing where
  7928. you think!
  7929.  
  7930.  
  7931.  
  7932. 7.1.3.4. %comnd flddb
  7933.  
  7934. This is the general COMND function interface, for doing things not directly
  7935. supported by this package.  `flddb' is the address of a function descriptor
  7936. block.  It returns the data as the COMND jsys does, except that t1 is not used
  7937. to return the parse flags (see %cmgfg below, if you want to do this).
  7938.  
  7939.  
  7940.  
  7941. 7.1.3.5. %cmgfg flag
  7942.  
  7943. This function get the flags from the .cmflg word of the Command State Block
  7944. into the word addressed by `flag'; e.g., to get the parse flags into t1, a
  7945. %cmgfg t1 will do just fine.
  7946.  
  7947. Some notes about using these COMND support macros in a structured fashion:
  7948.  
  7949.    - The basic idea, as hinted at in the description above, is that each
  7950.      COMND function either returns successfully if the parse succeeded
  7951.      (including no reparse needed), or takes an erjmp/ercal path if one
  7952.      is provided.  Thus, each subroutine that is doing some `piece' of
  7953.      the parsing can, at each step in its job, simply return non-skip on
  7954.      error, or go on if each parse step succeeds, returning skip when it
  7955.      finally finishes successfully.  Only the top-level parse routine has
  7956.      to worry about whether a reparse is needed, or an actual parse error
  7957.      occurred; in the former case, the routine only needs to start the
  7958.      parse over (without re-initializing); in the latter, an error
  7959.      message can be issued, and the parse started over from scratch.
  7960.  
  7961.    - There are several macros to help with this philosophy of parsing:
  7962.  
  7963.      %pret           To be used in a parse subroutine after each COMND
  7964.                      function; it just returns non-skip if a parse error
  7965.                      occurs.
  7966.  
  7967.      %errep errlab, replab
  7968.  
  7969.                      To be used in a situation (either top-level or a
  7970.                      subroutine) where an error or reparse must be
  7971.                      handled specially.  Mostly useful in the top-level
  7972.                      parse routine.
  7973. Columbia                                                             Page 143
  7974.  
  7975.      %merrep errlab, replab
  7976.  
  7977.                      Mostly like %errep, but it prints a parse error
  7978.                      message before going to errlab; this is useful in
  7979.                      the top-level parse routine.
  7980.  
  7981. Note that an erjmp or ercal after a COMND function invocation is usually
  7982. sufficient for handling most errors; e.g., after a %cmfil invocation in a
  7983. parse subroutine, if any errors occur later in the same routine, an erjmp to a
  7984. cleanup segment (that releases the jfn gotten by the %cmfil) is quite
  7985. sufficient for handling both noparse and reparse errors.
  7986. Columbia                                                             Page 144
  7987.  
  7988. 7.2. CUrel Utility Subroutines
  7989.  
  7990. CUrel.rel is an indexed library that can be searched for the handlers for the
  7991. Columbia UUOs for COMND Jsys calls and formatted printing (described in
  7992. CUUOs.doc) and for the routines described below.
  7993.  
  7994.  
  7995.  
  7996. 7.2.1. Helper
  7997.  
  7998. Types the desired help file at the job's controlling terminal.  Actually, it
  7999. will type any 7-bit ASCII file, but the error messages all refer to help
  8000. files.
  8001.  
  8002.  
  8003. Input:
  8004.   t2/ 7-bit byte pointer to ASCIZ filespec.
  8005.  
  8006. Effects:
  8007.   If the specified file is found and accessible then it is typed,
  8008.   otherwise an appropriate error message is typed.
  8009.  
  8010. Returns +1 always.
  8011.  
  8012. Calling sequence:
  8013.  
  8014.         search  CUsym
  8015.         extern  helper
  8016.           :
  8017.         %setup
  8018.           :
  8019.         move    t2, [point 7, [asciz\HLP:FILE.HLP\]]
  8020.         call    helper
  8021.           :
  8022.  
  8023. - F. da Cruz, CUCCA, 1978
  8024.  
  8025.  
  8026.  
  8027. 7.2.2. GetOK
  8028.  
  8029. Get affirmative or negative response to a question, using the COMND Jsys (help
  8030. is given on '?', recognition on ESC).
  8031.  
  8032. A default answer can be specified, which will be supplied automatically if the
  8033. user types carriage return alone in response to the question.
  8034. Columbia                                                             Page 145
  8035.  
  8036.  
  8037. Input:
  8038.  
  8039.   t1/ 7-bit byte pointer to ASCIZ string posing the question.
  8040.   t2/ zero -- no default answer.
  8041.       positive (nonzero) -- default answer is "yes".
  8042.       negative -- default is "no".
  8043.  
  8044. Returns:
  8045.   +1 if response was negative.
  8046.   +2 if response was affirmative.
  8047.  
  8048. Caution:
  8049.   Don't call this routine while processing
  8050.   another COMND Jsys (i.e. after .CMINI but before .CMCFM).
  8051.  
  8052. Example:
  8053.  
  8054.         move t1, [point 7, [asciz\Really delete all your files? \]]
  8055.         move t2, [-1]           ; default is 'no'.
  8056.         call getok
  8057.          jrst dont              ; answer was no, don't do it.
  8058.  
  8059.         ; code here will be executed if answer was 'yes'.
  8060.  
  8061. - F. da Cruz, C. Ryland, CUCCA, 1978
  8062.  
  8063.  
  8064.  
  8065. 7.2.3. Gfcpg
  8066.  
  8067. This routine will allocate a page to the user.  This is useful, for instance,
  8068. when PMAPping is to be done to a single page in memory.
  8069.  
  8070.  
  8071. Returns:
  8072.  +1: error, no free core pages;
  8073.  +2: success, page number in t1.
  8074.  
  8075. Example:
  8076.         call %gfcpg
  8077.          %ermsg <couldn't get a page>,nopage ; do this on +1 return
  8078.  
  8079.         ; come here when a page has been successfully allocated
  8080.  
  8081. - George Lotridge (DEC), CUCCA, 1977
  8082.  
  8083.  
  8084.  
  8085. 7.2.4. pagMgr
  8086.  
  8087. A page management facility.  Gives greater functionality that gfcpg at a
  8088. slightly greater cost in overhead.  Allows allocation and deallocation of
  8089. consecutive blocks of pages.  Keeps an internal 'own' page table for page
  8090. management.
  8091. Columbia                                                             Page 146
  8092.  
  8093.  
  8094. Call with:
  8095.  
  8096.   Function codes in t1:
  8097.         0: Get pages, searching from 770 -> 0.
  8098.         1: Get pages, searching from 0 -> 770.
  8099.         2: Free pages.
  8100.         3: Initialize the pages-in-use vector.
  8101.              (this is done automatically the first time this routine
  8102.               is called, before the selected function is executed).
  8103.  
  8104.   Arguments in t2:
  8105.         For get-page functions:
  8106.           Left half contains number of consecutive pages to get,
  8107.           Right half contains starting page number to search from.
  8108.  
  8109.         For free-page function:
  8110.           Left half contains number of consecutive pages to free,
  8111.           Right half contains starting page number to free from.
  8112.  
  8113.         (in these functions, if the number of pages given is 0,
  8114.          it will be treated as 1.)
  8115.  
  8116.         For reinitialize function:
  8117.           t2 is not examined.
  8118.  
  8119. Returns
  8120.   +1: Not enough pages available; t2 contains maximum
  8121.       number available of type requested.
  8122.       If there was an error on initialization (e.g. invalid argument),
  8123.       a message is typed at the terminal, and t1 is set to -1.
  8124.  
  8125.   +2: t1/ Address of block of pages in right half, and page
  8126.           number in the left.
  8127.       t2/ page count.
  8128.  
  8129.  
  8130. Joel Rosenblatt, CUCCA, 1978.
  8131.  
  8132.  
  8133.  
  8134. 7.2.5. Subbp
  8135.  
  8136. Subroutine to subtract two byte pointers, i.e. to tell the number of bytes
  8137. between the bytes pointed by the first one and the second one.  The two byte
  8138. pointers must point to bytes of the same size.  Indirection (@) and indexing
  8139. is handled properly.
  8140. Columbia                                                             Page 147
  8141.  
  8142.  
  8143. Call with:
  8144.   t1/ First byte pointer.
  8145.   t2/ Second byte pointer.
  8146.  
  8147. Returns:
  8148.   +1 if the byte sizes are different, with t1-t3 unchanged, or else
  8149.   +2 with:
  8150.     t1/ Unchanged.
  8151.     t2/ Unchanged.
  8152.     t3/ The number of bytes of the specified bytesize in
  8153.         thee string pointed to by the first byte pointer (in t1)
  8154.         up to, but  not including, the byte pointed to by the
  8155.         second byte pointer (in t2).
  8156.  
  8157. Example:
  8158.  
  8159.         ; assume a SIN has just been done to get a string into location
  8160.         ;  'buffer'. SIN returns the updated byte pointer in t2.  This
  8161.         ;  call to Subbp will tell how many characters were in the string.
  8162.  
  8163.         move t1, [point 7, buffer] ; Point to beginning of buffer.
  8164.         call subbp              ; (t2 already has the pointer to the end).
  8165.          %ermsg <bytesize error>,error  ; Do this on error.
  8166.         movem t3, count         ; Save the byte count.
  8167.  
  8168. - F. da Cruz, CUCCA, November 1977
  8169.  
  8170.  
  8171.  
  8172. 7.2.6. Rescan
  8173.  
  8174. Allow arguments to be passed to programs via the Exec command line.
  8175.  
  8176. Look in the rescan buffer for the name of the calling program followed by any
  8177. arguments.  If the first field found in the rescan buffer is not the same as
  8178. the program name, or if the program name matches but there are no arguments
  8179. after it then this routine returns +2 with no other effect.  Otherwise it
  8180. returns +1 to indicate that special handling (usually the setting of a flag)
  8181. can be done.
  8182.  
  8183.  
  8184. Enter with:
  8185.    t1/  Byte pointer to asciz program name.
  8186.  
  8187. Returns:
  8188.    +1: If arguments found in rescan buffer,
  8189.         with updated pointer in t1.
  8190.            +2: otherwise.
  8191.  
  8192. Example:
  8193.         extern Rescan
  8194.  
  8195.         %trnOff rscFlg          ; Assume no rescan args.
  8196.         move t1, [point 7, [asciz/foo/]] ; Name of this program.
  8197.         call rescan             ; Rescan args on command line?
  8198.          %trnOn rscFlg          ;  Yes, turn on the flag.
  8199. Columbia                                                             Page 148
  8200.  
  8201. If arguments were detected then subsequent requests for tty input will be
  8202. satisfied by the data in the rescan buffer until the rescan buffer is
  8203. exhausted or the program issues a .CMINI (or otherwise clears the input
  8204. buffer), at which time tty input will automatically revert to the physical
  8205. tty.  The caller should skip over the first .CMINI after return from this
  8206. routine, which has already issued a .CMINI.
  8207.  
  8208. The contents of the rescan buffer are discarded if the first field found on
  8209. rescan does not match the program name passed in t1.
  8210.  
  8211. - Jeff Langer, CUCCA, April 1979
  8212. Columbia                                                             Page 149
  8213.  
  8214. 7.3. CUsym MACSYM Augmentation Macros
  8215.  
  8216.        The CUsym macros and documentation were written by George
  8217.     L. Lotridge of Digital Equipment Corporation (while he was assigned to
  8218.     Columbia University as a resident software specialist) and Chris
  8219.     Ryland of Columbia.
  8220.  
  8221. CUsym contains a whole set of symbol and macro definitions to augment MONSYM
  8222. and MACSYM.  Included are the standard register definitions, macros for
  8223. interfacing to the UUO package (which supports standard I/O, simple uses of
  8224. the COMND Jsys, etc.), and generally any macro which has been found to be
  8225. useful and which is missing from MONSYM and MACSYM (a working knowledge of
  8226. which is assumed).
  8227.  
  8228.        NOTE: you should have a good feel for the contents of MACSYM (6)
  8229.     document and the Macro coding standards document (8) before using this
  8230.     package.
  8231.  
  8232. A word about naming conventions: all names in this module are of the form
  8233. %symbol; this will hopefully sidestep any name conflicts with a SEARCHing
  8234. program.  DEC has reserved names with % and .  in them, but their use of % is
  8235. restricted to other than the first char- acter, so we're safe.  (Actually, a
  8236. few of our Useful Symbols, below, use a "." as their first character, which is
  8237. also DEC-reserved, but they're simple and few enough to cause no problems.)
  8238. Also, a few of the 'hidden' symbols used herein (e.g., the stack, or global
  8239. symbols in the support package) begin with "%%".
  8240.  
  8241.  
  8242.  
  8243. 7.3.1. Accumulator Support
  8244.  
  8245. Accumulator (register) definitions (conform to the DEC coding standard) These
  8246. must be used exclusively, unless specifically redefined at the start of a
  8247. module with the %DefAC macro (see below).
  8248.  
  8249.  
  8250. p=:17                           ; Stack pointer
  8251. cx=:16                          ; Call/Return temporary
  8252. .sac=:16                        ; CU/MacSym utility reg
  8253. f=:0                            ; Flag register (preserved)
  8254. t1=:1                           ; General temp and Jsys registers:
  8255. t2=:2                           ;  never preserved
  8256. t3=:3                           ;  ...
  8257. t4=:4                           ;
  8258. q1=:5                           ; First set of preserved regs
  8259. q2=:6                           ;  (must be preserved by callee
  8260. q3=:7                           ;   across a call)
  8261. p1=:10                          ; Second set of preserved regs
  8262. p2=:11                          ;  (ditto)
  8263. p3=:12                          ;
  8264. p4=:13                          ;
  8265. p5=:14                          ;
  8266. p6=:15                          ; NB: not useable with TrVar MacSym facility
  8267. .fp=:15                         ; Frame pointer for TrVar facility
  8268. Columbia                                                             Page 150
  8269.  
  8270. 7.3.2. %DefAC
  8271.  
  8272. Define an alternate name for one of the registers; this macro should egisters
  8273. are re-defined, and the new definition should be made in terms of one of the
  8274. definitions above.  This macro purges the old name, thus preventing multiple
  8275. names for one register.
  8276.  
  8277.     define %defac(new, old)
  8278.  
  8279.  
  8280.  
  8281. 7.3.3. Useful Symbols
  8282.  
  8283. .prjfn=<.priin,, .priou>        ; Symbol for usual primary JFN pair
  8284. .null==0                        ; General nothing value
  8285. .nil==0                         ; General nothing pointer
  8286. .True==1                        ; General boolean truth value
  8287. .False==0                       ;  and its complement
  8288.  
  8289.  
  8290. ; Lengths of various Jsys control blocks; ommitted from MONSYM, sadly.
  8291.  
  8292. .acln                           ; Length of ACCES arg block
  8293. .ckln                           ; Length of CHKAC arg block
  8294. .cmln                           ; Length of Command State Block
  8295. .cmfln                          ; Length of Function Descriptor Block
  8296. .cdln                           ; Length of CRDIR arg block
  8297. .cjln                           ; Length of CRJOB arg block
  8298. .jiln                           ; Length of GETJI arg block
  8299. .gjln                           ; Length of (long form) GTJFN arg block
  8300. .ipln                           ; Length of ipcf packet descriptor block
  8301. .rsln                           ; Length of SFTAD arg block
  8302. .rdln                           ; Length of TEXTI arg block
  8303.  
  8304.  
  8305.  
  8306. 7.3.4. UUO Package OPDEFs and Interface Symbols
  8307.  
  8308. %uprin                          ; Print UUO
  8309. %comnd                          ; COMND interface UUO
  8310. %ucmin                          ; COMND initializer UUO
  8311. %cmgfg                          ; Get COMND flags UUO
  8312. %cmgab                          ; Get COMND atom buffer UUO
  8313. %nuuo                           ; Add-new-UUO UUO
  8314. %cmres                          ; COMND reset UUO
  8315. %prPush                         ; JFN-stack push (%print package) UUO
  8316. %prPop                          ; JFN-stack pop (ditto) UUO
  8317.  
  8318. ; length of COMND interface UUO atom buffer:
  8319.  
  8320. %atmbl==^d250/5+1               ; in words
  8321.  
  8322.         extern %csb             ; command state block, for you hackers
  8323. Columbia                                                             Page 151
  8324.  
  8325. 7.3.5. Setup Environment Macros
  8326.  
  8327.  
  8328.  
  8329. 7.3.5.1. %setEnv
  8330.  
  8331. %SetEnv is a macro that must be used as the first thing after your Title and
  8332. Search CUsym statements; it sets up the CUsym, MonSym, and MacSym environments
  8333. properly.  Its use is envisioned as:
  8334.  
  8335.  
  8336.         title Baz - tweak the frob's runtime
  8337.         search CUsym                    ; (No MAC: needed!)
  8338.         %setenv                         ; Set up our environment
  8339.          ...
  8340.  
  8341.  
  8342.  
  8343. 7.3.5.2. %setUp
  8344.  
  8345. %SetUp is a macro that you should use as the first executable action in your
  8346. program; it Resets the execution environment, sets up a stack, clears the flag
  8347. register F, sets up for UUO calls, sets up for COMND parsing (resetting) (and
  8348. starts off your code in %Pure mode).
  8349.  
  8350.  
  8351.  
  8352. 7.3.6. Storage Declaration Macros
  8353.  
  8354. %Pure, %Impure, %Routine
  8355.  
  8356. Use these macros to declare what sort of storage follows them: either %pure
  8357. code (or read-only data) or %impure data (read-write).  Thus, before beginning
  8358. a new logical section of code or data, always use one of them to declare what
  8359. follows (if you don't use them, you may be surprised!).  It goes without
  8360. saying that %Pure should precede all code (which is NEVER impure).  Using this
  8361. pair of macros is a good way of keeping impure data, which belongs to a
  8362. routine, physically (on the written page, that is) together with the routine.
  8363.  
  8364. The alias %routine for %pure exists for purely mnemonic purposes; its use is
  8365. suggested, as in:
  8366.  
  8367.  
  8368.                 %routine
  8369.         openit: stkvar  <fee,<foo,,5>>
  8370.  
  8371.  
  8372.  
  8373. 7.3.7. General-Purpose Macros
  8374.  
  8375.  
  8376.  
  8377. 7.3.7.1. %Stack
  8378.  
  8379. This macro creates the stack area, and loads P with the stack pointer.  Its
  8380. argument, the stack height, is optional, and defaults reasonably.
  8381. Columbia                                                             Page 152
  8382.  
  8383. 7.3.7.2. %Version
  8384.  
  8385. This macro builds a standard DEC version word from its arguments.  In order,
  8386. its arguments are the major version, the edit number, the minor version, and
  8387. the customer version.  Omitted fields default to zero.
  8388.  
  8389.  
  8390.  
  8391. 7.3.7.3. %Clear
  8392.  
  8393. This macro takes three args, two of which are optional.  The first,
  8394. non-optional, argument is the starting address of the area to be cleared.  The
  8395. next is the number of locations to clear, which defaults to one.  The last
  8396. argument is the desired filler, which defaults to zero.
  8397.  
  8398.  
  8399.  
  8400. 7.3.8. Macros Used for Common Primary I/O
  8401.  
  8402. Note that since these macros use %print, that any string argument shouldn't
  8403. include `%'s, or things may get very confusing.  Also note that %typnum's
  8404. first argument, the address of the number, must conform to the %print argument
  8405. standard (q.v.).
  8406.  
  8407.  
  8408.  
  8409. 7.3.8.1. %typeCR(string)
  8410.  
  8411. Types the given literal string at your terminal, followed by a carriage return
  8412. (CR).
  8413.  
  8414. Example:
  8415.  
  8416.     %typeCR <And your little dog, too!>
  8417.  
  8418.  
  8419.  
  8420. 7.3.8.2. %crType(string)
  8421.  
  8422. Like %typeCR, but types the CR before, instead of after, the string.
  8423.  
  8424.        To type a literal string with no CR, either before or after, use
  8425.     the MACSYM macro TMSG.
  8426.  
  8427.  
  8428.  
  8429. 7.3.8.3. %typNum(num,cols,rdx)
  8430.  
  8431. Types the number in location 'num' at your terminal.  The two trailing
  8432. arguments are optional.
  8433.  
  8434. cols            Field width in which to print the number.  Default is 0, i.e.
  8435.                 use only as many character positions as are necessary to type
  8436.                 the number.
  8437.  
  8438. rdx             Radix in which to type the number.  Default is 10 (decimal).
  8439. Columbia                                                             Page 153
  8440.  
  8441. 7.3.8.4. %crlf
  8442.  
  8443. Types a carriage-return/linefeed sequence at your terminal.
  8444.  
  8445.  
  8446.  
  8447. 7.3.8.5. %tab
  8448.  
  8449. Types a horizontal tab at your terminal.
  8450.  
  8451.  
  8452.  
  8453. 7.3.9. JSYS Support Macros
  8454.  
  8455.  
  8456.  
  8457. 7.3.9.1. %jsErr
  8458.  
  8459. Macro to be used after a Jsys that either returns +1 on error or always
  8460. returns +1 (i.e., all but two of the Jsysi); %JSerr types the user's error
  8461. message (if given) or the Jsys error that caused it to be invoked (if no
  8462. message is given); it then either halts (if no address is supplied) or goes to
  8463. the address (if given).
  8464.  
  8465.        Note: this is similar to the MacSym macro JSERR, but it only works
  8466.     after a Jsys, since it is invoked by an erjmp; %JSerr has the
  8467.     advantage, though, that it ALWAYS works after a Jsys, which JSERR
  8468.     doesn't.
  8469.  
  8470. Note also that both %Jserr and %ErMsg, if they halt and are continued, will
  8471. simply return to the point after the invocation of the %Jserr or %ErMsg.
  8472.  
  8473. Both of these macros, since they use %print, can produce customized error
  8474. messages (eg, %jsErr <CUsym: Bad command %s [%e]>,,<ptrToS> will print an
  8475. error-synchronized message, with a string argument and the monitor error
  8476. message in brackets, and then halt).
  8477.  
  8478.  
  8479.  
  8480. 7.3.9.2. %erMsg
  8481.  
  8482. This macro, which, in contrast to %JSerr, is designed to be used in a non-Jsys
  8483. skip context, will print a message (if given) or the last fork error (if not
  8484. given); finally, it either jumps to an address (if given), or halts (if not
  8485. given).  See %Jserr comments for more info.
  8486.  
  8487.  
  8488.  
  8489. 7.3.10. Local Label Support Macros
  8490.  
  8491. The intent of this set of macros is to provide a facility usually available in
  8492. good assemblers (hint, hint): local labels.  The idea, due to Knuth, is that
  8493. instead of agonizing over choosing a label for each little local motion within
  8494. some code, you simply plant one of nine local labels, of the form %N, and
  8495. refer to the next local label %N by %NF, and the previous local label %N by
  8496. %NB - a simple example of all this is:
  8497. Columbia                                                             Page 154
  8498.  
  8499.  
  8500.         some:   stkvar <from,to>
  8501.                 txne t1,gj%old          ; Does he want an old file?
  8502.                 jrst %1f                ; Yes, go handle it
  8503.                 txz t1,gj%fou           ; No, reset this
  8504.                 setom from              ;  and set 'from' flag
  8505.         %1      call foo                ; Continue with processing
  8506.                  jrst %1b               ; Failed: try it again
  8507.                 ...                     ;  etc etc
  8508.  
  8509. These macros (internally) use symbols of the form %n% and %n%m, where n ranges
  8510. from 1 to 9, and m from 0 to 777, so be wary.
  8511.  
  8512.  
  8513.  
  8514. 7.3.10.1. %Cat(a,b)
  8515.  
  8516. Useful macro that just returns its two arguments (as text strings),
  8517. concatenated.
  8518.  
  8519.  
  8520.  
  8521. 7.3.11. COMND JSYS Support Macros
  8522.  
  8523.  
  8524.  
  8525. 7.3.11.1. %Ptr(string)
  8526.  
  8527. Build a standard 7-bit ASCIZ pointer to a literal string.
  8528.  
  8529.  
  8530.  
  8531. 7.3.11.2. %table and %tbEnd
  8532.  
  8533. %table is used to start a keyword table definition; %tbEnd ends a keyword
  8534. table definition.  Suggested use is as in the following example, which also
  8535. illustrates %key.
  8536.  
  8537.  
  8538. cmtb:   %table                          ; Keywords for frotz program
  8539.         %key Mumble,domum,cm%inv        ;  mumble command (invisible)
  8540.         %key Noodle,donood              ;  noodle command
  8541.         %key Zork,dungeo                ;  invoke dungeon command
  8542.         %tbend                          ; End of this keyword table
  8543.  
  8544.  
  8545.  
  8546. 7.3.11.3. %key(name, data, flags)
  8547.  
  8548. This macro takes three arguments: an (alphanumerics only!) name, the data to
  8549. be associated with the name, and an (optional) flag value.  It creates either
  8550. a flag-less keyword (the normal case), or, if flags are given, a keyword with
  8551. flags in the first word (and cm%fw set).  Thus, the result is a TBLUK table
  8552. entry, suitable for use by the .CMkey COMND Jsys function.  Note that all %Key
  8553. words in a table must be bracketted by %table and %TbEnd macros (see above).
  8554. Columbia                                                             Page 155
  8555.  
  8556. 7.3.11.4. %Flddb (typ, flgs, data, hlpm, defm, lst)
  8557.  
  8558. This macro is useful for building function descriptor blocks that don't
  8559. contain just literal strings for the help and default components; otherwise,
  8560. it's the same as the MONSYM flddb. macro.
  8561.  
  8562.  
  8563.  
  8564. 7.3.11.5. %Handlr(p,e), %PrsAdr, %EvlAdr
  8565.  
  8566. Macros to support structured parse/evaluation; %Handlr builds a structure
  8567. comprised of the parse routine address (p) and evaluation routine address (e),
  8568. for a given keyword (it should be in a literal in the %Key macro); %prsAdr and
  8569. %evlAdr are the DEFSTR structures for accessing these two elements of a
  8570. structure, respectively.
  8571.  
  8572. An example of all this:
  8573.  
  8574.  
  8575.           :
  8576.         %cmkey comtab, <command,> ; Get a top-level keyword
  8577.          %merrep restart, repars; Usual error handling
  8578.         hrrz t2, (t2)           ; Pick up data value from keyword
  8579.         load t2, %evladr, (t2)  ; Get evaluation routine
  8580.         movem t2, evaler        ; Save its address
  8581.         load t2, %prsadr, (t2)  ; Now, get parse routine
  8582.         call (t2)               ; And call it
  8583.          %jmerrep restart, repars, restart ; Handle errors
  8584.           :                     ; Continue
  8585.  
  8586. ; Pure data for main parse
  8587.  
  8588.         %table                  ; Main command table
  8589.         %key bletch, [%handlr(bletcm, doblet)] ; Bletch mode
  8590.         %key mumble, [%handlr(mumbcm, domumbl)] ; Mumble mode
  8591.         %tbend
  8592.           :
  8593.  
  8594.  
  8595.  
  8596. 7.3.11.6. %CMxxx Macros to Invoke .CMxxx COMND Functions
  8597.  
  8598. See the CUUOS document (7.1) for information about using these.  They are
  8599. listed here for convenience:
  8600.  
  8601.    - %cmIni (prompt, flags, ioJfn, gjfBlk): Initialize parse.
  8602.  
  8603.    - %cmKey (keyTab, help, defalt, flags): Parse a keyword.
  8604.  
  8605.    - %cmNum (radx, help, defalt, flags): Parse a number.
  8606.  
  8607.    - %cmNoi (guide-word): Parse guide words.
  8608.  
  8609.    - %cmSwi (swTab, help, defalt, flags): Parse a switch.
  8610.  
  8611.    - %cmIfi (help, defalt, flags): Parse an input filespec.
  8612.  
  8613.    - %cmOfi (help, defalt, flags): Parse an output filespec.
  8614. Columbia                                                             Page 156
  8615.  
  8616.    - %cmFil (help, defalt, flags): Parse a general filespec.
  8617.  
  8618.    - cmFld (help, defalt, flags): Parse a "field".
  8619.  
  8620.    - %cmCfm (help, flags): Get confirmation (CR).
  8621.  
  8622.    - %cmDir (data, help, defalt, flags): Parse a directory name.
  8623.  
  8624.    - %cmUsr (help, defalt, flags): Parse a user name.
  8625.  
  8626.    - %cmCma (help, flags): Parse a comma.
  8627.  
  8628.    - %cmFlt (help, defalt, flags): Parse a floating-point number.
  8629.  
  8630.    - %cmDev (help, defalt, flags): Parse a device name.
  8631.  
  8632.    - %cmTxt (help, defalt, flags): Parse a text string.
  8633.  
  8634.    - %cmTad (tadBlk, help, defalt, flags): Parse time and date.  Note
  8635.      that the Time-and-Date flags belong to the first argument, since
  8636.      they're part of the data to the function.
  8637.  
  8638.    - %cmQst (help, defalt, flags): Parse a quoted string.
  8639.  
  8640.    - %cmUqs (brkTab, help, defalt, flags): Parse an unquoted string.
  8641.  
  8642.    - %cmTok (token, help, defalt, flags):  Parse a token.  The token as
  8643.      given should be a string in double quotes, as in %cmtok "*"; if you
  8644.      need some other form, use the %comnd UUO bare.
  8645.  
  8646.    - %cmNux (radix, help, defalt, flags): Parse a number.
  8647.  
  8648.    - %cmAct (help, defalt, flags): Parse an account string.
  8649.  
  8650.    - %cmNod (help, defalt, flags): Parse a network node name.
  8651.  
  8652.  
  8653.  
  8654. 7.3.12. Macros to Handle COMND Errors
  8655.  
  8656.  
  8657.  
  8658. 7.3.12.1. %pret
  8659.  
  8660. For use in secondary parsing subroutines.  Handle a parse error or reparse by
  8661. just returning non-skip.
  8662.  
  8663.  
  8664.  
  8665. 7.3.12.2. %errep errlab, replab
  8666.  
  8667. For use in top-level command parser.  Handle an error by going to errlab, and
  8668. a reparse by going to replab.
  8669. Columbia                                                             Page 157
  8670.  
  8671. 7.3.12.3. %merrep errlab, replab
  8672.  
  8673. For use in top-level command parser.  Handle an error by giving an error
  8674. message and going to errlab, and a reparse by going to replab.
  8675.  
  8676.  
  8677.  
  8678. 7.3.12.4. Macros for Fail-Return from Parsing Routines
  8679.  
  8680. These macros help with error- and reparse-handling after a parse subroutine
  8681. call (which is expected to return skip on success, and non-skip on failure);
  8682. three sorts of errors can be expected from such subroutines: parse error,
  8683. reparse needed, other type of failure (usually a semantic problem).  Thus,
  8684. these macros have three dispatch addresses, corresponding to these three
  8685. errors.  Note that the method used here assumes that if neither the parse
  8686. error or reparse flags are set in the command state block, then the error is
  8687. of type `other'.
  8688.  
  8689.  
  8690.  
  8691. 7.3.12.5. %jerrep errlab, replab, othrlb
  8692.  
  8693. Handle a skip-return error condition as described above.
  8694.  
  8695.  
  8696.  
  8697. 7.3.12.6. %jmerrep errlab, replab, othrlb
  8698.  
  8699. Handle a skip-return error condition as described above, printing an error
  8700. message on a parse error.
  8701.  
  8702.        Note! t1 is clobbered by %errep, %merrep, %jerrep, %jmerrep.
  8703.  
  8704.  
  8705.  
  8706. 7.3.13. Flag-Handling Macros
  8707.  
  8708. All of the following flag-handling macros use register F, the preserved flag
  8709. register.  F is assumed to be the flag register for any program that uses
  8710. these macros.  Note that %SetUp clears F, thus initializing flag management.
  8711.  
  8712.  
  8713.  
  8714. 7.3.13.1. %Flags(aFlg,bFlg,cFlg,...)
  8715.  
  8716. This macro takes a list of flag names, and assigns a flag value to each name
  8717. (within a 36-bit word).  It can be used more than once, but no more than 36
  8718. flags can be defined.
  8719.  
  8720.  
  8721.  
  8722. 7.3.13.2. %trnOn & %trnOff
  8723.  
  8724. These macros take a flag quantity (one or more flags ORed together), and turn
  8725. them on or off, respectively (with no skipping).
  8726. Columbia                                                             Page 158
  8727.  
  8728. 7.3.13.3. %TrOnS & %TrOfS
  8729.  
  8730. Like %TrnOn and %TrnOff, but skip always afterwards.
  8731.  
  8732.  
  8733.  
  8734. 7.3.13.4. %SkpOn & %SkpOff
  8735.  
  8736. These macros take a flag quantity, and will skip if ALL the flags are on or
  8737. off, respectively.
  8738.  
  8739.  
  8740.  
  8741. 7.3.13.5. %AnyOn & %AnyOff
  8742.  
  8743. These macros take a flag quantity, and will skip if ANY of the flags are on or
  8744. off, respectively.
  8745.  
  8746.  
  8747.  
  8748. 7.3.14. CUuos (CUCCA Utility UUOs) Interface
  8749.  
  8750.  
  8751.  
  8752. 7.3.14.1. %print, %prSkp
  8753.  
  8754. Formatted-print macros: output the arguments according to the format string.
  8755. %PrSkp returns skipping (+2 instead of +1, but handling a following
  8756. erjmp/ercal properly).  See 7.1 for details.
  8757.  
  8758. A note about arguments: the argument list is really nothing more than a
  8759. sequence of addresses, so if you choose to use addressing forms such as
  8760. address(index), be sure and use the <z address(index)> form so that macro will
  8761. be happy with the address.  The same applies to address forms such as
  8762. <z @(t1)>, etc.
  8763. Standards                                                            Page 159
  8764.  
  8765.               8. Macro-20 Programming Standards and Conventions
  8766.  
  8767.  
  8768.  
  8769. 8.1. Introduction
  8770.  
  8771. This document was adapted in April 1979 at the Columbia University Computer
  8772. Center from the document
  8773.  
  8774.        TOPS20 Coding Standards and Conventions, 17 January 1974, revised
  8775.     8 September 1976
  8776.  
  8777. written by the DEC Tops-20 monitor group for its own use.  This version
  8778. departs from the original in certain ways, by additions and deletions, and by
  8779. modifications of certain details, but the net effect is about the same.  These
  8780. standards and specifications apply in specific detail to Macro-20 programs,
  8781. and in spirit to other DEC-20/DEC-10 assemblers (Macro-10, Midas, Fail).  They
  8782. do not apply in their entirety to assembly language routines written to be
  8783. called from other languages, which usually have different subroutine calling
  8784. conventions, and may have registers dedicated to different uses, precluding
  8785. the use of certain MACSYM facilities.  Familiarity with Macro-20 and DEC-20
  8786. monitor calls is assumed.
  8787.  
  8788. A standard of programming style and conventions is especially important for
  8789. the assembly language programmer because assembly language lacks high-level
  8790. language facilities such as control and data structures, scoping of variables,
  8791. etc., without which the programmer must exercise tremendous discipline to
  8792. write a clear, easily modifiable program.  It is hoped that this standard will
  8793. make assembly language programming easier by relieving the programmer of the
  8794. burden of deciding at every turn how to format a statement, how to use
  8795. registers, how to pass parameters to a subroutine, and so forth.  Like any
  8796. standard, this one contains many elements that are arbitrary and capricious,
  8797. and few people will agree with every detail.  The bulk of the standard comes
  8798. to us as a fait accompli, having been in use at DEC for several years and
  8799. forming the basis for a very large amount of code.  Other facets have been
  8800. added after long experience both in writing programs and in reading and
  8801. modifying code from various installations.  It is felt the rules of style and
  8802. usage given here can result in programs that are as clear as Macro-20 programs
  8803. can be.
  8804.  
  8805.  
  8806.  
  8807. 8.2.  Statements
  8808.  
  8809. The general form of a statment should be:
  8810.  
  8811.  
  8812. label:  opcode ac, @addr(x)    ; Comment.
  8813.  
  8814.   where:
  8815.  
  8816.    1. Tabstops are assumed to be set every 8 spaces.
  8817.  
  8818.    2. The label begins at the left margin.
  8819.  
  8820.    3. The opcode begins at the first tab stop.  There should be one tab
  8821.       before the opcode.  If the label and colon(s) occupy 8 or more
  8822.       spaces, the opcode should start at the first tab stop on the next
  8823. Standards                                                            Page 160
  8824.  
  8825.       line.  Exceptions to this rule apply in multi-line literals and
  8826.       following skipping instructions, JSYS's, and subroutine calls (see
  8827.       below).
  8828.  
  8829.    4. One space (a blank, not a tab) should follow the opcode unless
  8830.       there are no other fields except the comment to be specified in the
  8831.       statement, in which case sufficient tabs should follow to put the
  8832.       comment field at the 4th tab stop.  Space is preferred to tab for a
  8833.       number of reasons: spaces take up less space and cause fewer
  8834.       overflows into the comment field; an instruction is typed the same
  8835.       way in the program text as it is in DDT (DDT will not accept a tab
  8836.       in an instruction); tabbing does not achieve vertical alignment of
  8837.       equivalent fields since various quantities can follow the opcode
  8838.       (register, address, and others); tabs would line up the operands
  8839.       with the opcodes of multiline literals; using tab prevents the
  8840.       operands of an indented opcode from reflecting the indentation and
  8841.       sometimes forces the operand forward an additional tab stop.  This
  8842.       standard attempts to help the whole instruction to be perceived
  8843.       visually as a single unit; the use of tab tends to visually
  8844.       separate opcode and operands for no useful reason.  Vertical
  8845.       alignment of operand fields such as produced by tab in this context
  8846.       appears to be mainly a carryover from punched-card oriented
  8847.       processors where parsing was done by field rather than on a
  8848.       character stream.
  8849.  
  8850.    5. When any field is not used by the instruction, it may be omitted
  8851.       along with its directly related punctuation.  A field which is
  8852.       affected by an instruction should NOT be defaulted to 0 by omitting
  8853.       it.
  8854.  
  8855.    6. The semicolon which begins the comment should be at the 4th tab
  8856.       stop.  There should be one or more tabs preceding the semicolon as
  8857.       necessary to place the semicolon at the 4th tab stop unless the
  8858.       preceding fields extend to or beyond the 4th tab stop.  In this
  8859.       case, one space (blank) should be used to separate the last
  8860.       preceding field and the semicolon.  The semicolon should be
  8861.       followed by a space.
  8862.  
  8863. The instruction which follows a skipping monitor or subroutine call should be
  8864. indented 1 additional space (1 space beyond the first tab stop) to indicate
  8865. the possibility of that instruction being skipped.  Indenting in this manner
  8866. should also be done following skipping machine instructions; when several
  8867. skipping instructions appear consecutively, each instruction that could be
  8868. skipped should be indented 1 space.
  8869.  
  8870.  
  8871.  
  8872. 8.3. Comments
  8873.  
  8874. A comment on the same line as a statement should begin at the 4th tab stop as
  8875. described above.  When a comment consists of a single sentence or phrase which
  8876. requires more than one line, the subsequent lines should have two spaces
  8877. between the semicolon (at the 4th tab stop) and the comment to indicate to the
  8878. reader that the several lines are part of one logical statement.
  8879.  
  8880. A comment on a line by itself should begin at the left margin.
  8881.  
  8882. A group of comment lines (1 or more lines) should be preceded and followed by
  8883. Standards                                                            Page 161
  8884.  
  8885. a blank line.
  8886.  
  8887. A long comment (10 or more lines) may be enclosed within a REPEAT 0 or COMMENT
  8888. pseudo-op and the semicolons omitted.
  8889.  
  8890. Extensive commenting of source listings is strongly encouraged:
  8891.  
  8892.    1. Routines, modules, sections, macro definitions, etc., should be
  8893.       described at their beginning.  See also requirements for subroutine
  8894.       comments below.
  8895.  
  8896.    2. Comments should appear on almost every statement line.  As the
  8897.       reader views the listing page, the comments (aligned at the 4th tab
  8898.       stop) should appear as a running commentary on what the code is
  8899.       doing.  These on-line comments should explain the logical procedure
  8900.       being carried out, not just describe the obvious action of the
  8901.       instruction.  Humorous or irrelevant comments (e.g.  "; Oops...",
  8902.       "; Oh well...") are discouraged since they provide no information
  8903.       to the reader.
  8904.  
  8905. Comments should be written in plain English, without jargon, following normal
  8906. rules of capitalization, punctuation, and grammar.  A reader should be able to
  8907. read the comments without seeing the code and obtain a coherent understanding
  8908. of what the program is doing.  When a variable or other mnemonic symbol is
  8909. referred to in the comments, an english phrase rather than the mnemonic itself
  8910. should frequently be used (e.g.  "last page address" rather than "LPGADR").
  8911. Comments, particularly routine headers, should describe why non-obvious
  8912. actions are being taken and/or what assumptions are being made (e.g.  "Get
  8913. here only when ...").
  8914.  
  8915. Comments should exist on three levels.  The highest level is a sentence or
  8916. paragraph that describes the operation of an entire program or routine, and
  8917. appears at the head of the program or routine (at the top of a page), usually
  8918. enclosed by the COMMENT pseudo-op so that each line need not begin with a
  8919. semicolon.  The first top-level comment in a file should include the author's
  8920. name, organization (and department), the date, and possibly a copyright
  8921. notice.  The lowest level is the per-statement comment at the 4th tab stop.
  8922. The intermediate level is a one- or two-line comment, beginning on the left
  8923. margin, which describes the purpose or operation of a group of statements.
  8924. There should never be more than 8 or 10 lines of code without such an
  8925. intermediate comment.
  8926.  
  8927. Think of any program you write as if it were a letter to a stranger who will
  8928. have to fix all the bugs you left in it, add new functionality, or translate
  8929. it to another language.  It should be possible to read through a program on
  8930. four levels:
  8931.  
  8932.    1. At the top level only.  Reading only the highest-level comments
  8933.       should give the reader a broad idea of the purpose and structure of
  8934.       the program.
  8935.  
  8936.    2. At the intermediate level.  Reading the top- and intermediate-level
  8937.       comments should show you not only what the program does, but what
  8938.       algorithm was used.
  8939.  
  8940.    3. At the lowest comment level.  Including these comments in a reading
  8941.       of the program adds detailed information about the actual
  8942.       implementation of the algorithm.
  8943. Standards                                                            Page 162
  8944.  
  8945.    4. At the code level.  Including the code itself brings you down to
  8946.       the bit-twiddling level.  It should never be necessary to read code
  8947.       unless you want to learn how things are done, or you are modifying
  8948.       the program.
  8949.  
  8950. Example showing intermediate- and low-level comments:
  8951.  
  8952.  
  8953. ; Get a JFN for the input file.
  8954.  
  8955.         movx t1, GJ%SHT!GJ%OLD  ; Using short form GTJFN, for an old file
  8956.         hrroi t2, [asciz /foo.txt/] ;  called foo.txt,
  8957.         GTJFN                   ;  get a Job File Number.
  8958.          erjmp filErr           ; On error go to the file-error handler.
  8959.         hrrzm t1, inJfn         ; No error, save the JFN (without flags).
  8960.  
  8961. ; Now open the file.
  8962.  
  8963.         movx t2, fld(7,OF%BSZ)!OF%RD ; In 7-bit byte read mode,
  8964.         OPENF                   ;  open the file.
  8965.          erjmp filErr           ; On error go to the file-error handler.
  8966.  
  8967. ; File is open.  Now begin processing.
  8968.  
  8969.         :
  8970.         :
  8971.  
  8972.  
  8973. The style of capitalization of the opcodes, JSYS bits, and variables is a
  8974. matter of taste, but consistent use of a mixture of upper and lower case to
  8975. enhance the readability of the program is strongly encouraged.  In this
  8976. example, MONSYM symbols (JSYS names and bits) are capitalized, instructions
  8977. and register names are in lower case, and variable names formed from multiple
  8978. words have capital letters at word breaks (e.g. filErr = file error).
  8979.  
  8980.  
  8981.  
  8982. 8.4. Pagination of Source Programs
  8983.  
  8984. Source listings should be divided into pages by formfeed (control-L)
  8985. characters.  A CRLF should precede and follow each formfeed.  Source files
  8986. should be arranged so that major modules, subroutines, etc., begin at the top
  8987. of a page.  Only when a subroutine is a quarter page or less in total size
  8988. should it begin other than at the top of a page.
  8989.  
  8990. Judicious use should be made of blank lines (they should be inserted to
  8991. emphasize logical boundaries, but without large gaps).  Garish graphic devices
  8992. like lines across the page, boxes around headings, etc., should be avoided
  8993. since they waste the programmer's time (both in typing them in and in waiting
  8994. for them to be typed out) without adding any useful information to the
  8995. program; the principle formatting devices for separating things and getting
  8996. attention should be blank lines and formfeed characters.
  8997.  
  8998. It should rarely be necessary for flow of control to cross a listing page.
  8999. That is, the last instruction on each page would normally be an unconditional
  9000. transfer of control not preceded by a skipping instruction.  An unbroken
  9001. sequence of instructions longer than one listing page is strong evidence of
  9002. insufficient subroutinization.  However, when a sequence of instructions does
  9003. Standards                                                            Page 163
  9004.  
  9005. cross a page, the last line on the preceding page and the first line on the
  9006. following page should be a comment line of the form
  9007.  
  9008.  
  9009.         ; ..
  9010.  
  9011.  
  9012. where the semicolon appears at the first tab stop directly under the preceding
  9013. opcode.  E.g.,
  9014.  
  9015.  
  9016.         move t1, foo            ; Comment
  9017.         ; ..
  9018. ^L
  9019.         ; Comment about continuation.
  9020.  
  9021.         ; ..
  9022. label:  movem t1, baz           ; Comment
  9023.  
  9024.  
  9025. The page break should occur at a natural juncture in the program logic.
  9026.  
  9027.  
  9028.  
  9029. 8.5. Other Assembler Functions
  9030.  
  9031. For top-level macro definitions, the DEFINE should appear at the left margin
  9032. and be followed by one space.  The name of the macro being defined should
  9033. appear next, followed by one space.  The dummy argument list, if any, should
  9034. appear next, followed by the open angle-bracket.  E.g.,
  9035.  
  9036.  
  9037. define macnam (a,b,c)<
  9038.  
  9039.       or
  9040.  
  9041. define macnam <
  9042.  
  9043.  
  9044. A comment or CRLF should follow the open angle-bracket, and the body of the
  9045. macro definition should begin on the next line, except when the entire macro
  9046. definition is on one line in order to be used as part of an expression.  The
  9047. terminating right angle bracket should be on a line by itelf, on the left
  9048. margin.
  9049.  
  9050. Example:
  9051.  
  9052.  
  9053. define  getSum (a,b,c)<         ;; Macro to get a sum into an AC.
  9054.         move a, b               ;; Load contents of b into AC a,
  9055.         add a, c                ;;  and add contents of c.
  9056. >
  9057.  
  9058. Macro calls generally do not require parentheses surrounding the arguments.
  9059. The exception is a macro call appearing within an expression, e.g.
  9060.  
  9061.  
  9062.         aa+foo(xx,yy)+bb
  9063. Standards                                                            Page 164
  9064.  
  9065.  
  9066.  
  9067. In some cases, however, the parentheses improve clarity, e.g. "foo (,x)" shows
  9068. more clearly that the first argument to foo is omitted than does "foo ,x".
  9069.  
  9070. Angle-brackets should be used to quote any argument containing
  9071. non-alphanumeric characters; this is especially true of character strings with
  9072. imbedded blanks.
  9073.  
  9074. Examples (where %jsErr is a macro name):
  9075.  
  9076.  
  9077.         GTJFN
  9078.          %jsErr <Can't get a JFN>, r
  9079.  
  9080.         OPENF
  9081.          %jsErr (,r)
  9082.  
  9083. Top level assembler conditionals should be indented 3 spaces from the left
  9084. margin (so that tag and comment lines may always be leftmost).  Lower level
  9085. conditionals should be indented 3 or more spaces.  The terminating
  9086. angle-bracket of a conditional should appear:
  9087.  
  9088.    1. immediately following the last instruction if the conditional is
  9089.       only one line long;
  9090.  
  9091.    2. on a separate line indented the same amount as the pseudo-op which
  9092.       began the conditional.
  9093.  
  9094. Example:
  9095.  
  9096.  
  9097. tag:
  9098.    ife ftFoo,<move t1, mumble>  ; If feature Foo is selected just do this.
  9099.  
  9100.    ifn ftFoo,<                  ; If feature Foo is not selected...
  9101.         move t1, mumble         ;  then do this,
  9102.       ifn ftBaz,<               ;  and if feature Baz is selected...
  9103.         add t1, baz             ;   do this
  9104.         move t2, frotz          ;   and this too.
  9105.       >                         ;   End of ifn ftBaz.
  9106.         jrst frotzH             ;  Go to the frotz handler.
  9107.    >                            ;  End of ifn ftFoo.
  9108.  
  9109. A closing angle bracket should NEVER appear in a comment (i.e.  following a
  9110. semicolon on the same line).  The coding should be correct even if the
  9111. assembler were made to ignore angle-brackets in comments.
  9112.  
  9113. Assembly listing options are provided for those who want listings, but
  9114. experience has shown that assembly listings are rarely useful; it is usually
  9115. sufficient to work from a source listing.  However, all assemblies should
  9116. begin with SALL which has been shown to produce the most readable assembly
  9117. listings.  In addition, all source files should have a TITLE, and SUBTTL's for
  9118. each logical section of the program (e.g. symbol definitions, initialization,
  9119. main program, support routines, data area).
  9120.  
  9121. In general, macros worth defining at all are worth defining on a system-wide
  9122. basis.  Therefore, localized, special-purpose macros are discouraged.
  9123. Standards                                                            Page 165
  9124.  
  9125. 8.6. Instruction Mnemonics
  9126.  
  9127. The standard KL-10 instruction mnemonics as defined by the DECsystem-10/20
  9128. Hardware Reference Manual should be used throughout.  No abbreviated opcodes
  9129. should be used.
  9130.  
  9131. Macro or opdef definitions should be made to define a useful mnemonic which is
  9132. related to a function being performed in the code.  See the subroutine
  9133. conventions below for examples.
  9134.  
  9135.  
  9136.  
  9137. 8.7. Variables and Structures
  9138.  
  9139. Use of the stack variable and data structure facilities in MACSYM is
  9140. recommended.  See MACSYM documentation.  Because of these facilities, the
  9141. following should be observed:
  9142.  
  9143.    1. Explicit pushing and popping of quantities is rarely done.
  9144.  
  9145.    2. Explicit referencing of the stack, e.g. as -n(p) is never done.
  9146.  
  9147.    3. Fields within data blocks or tables are not referenced by halfword
  9148.       instructions or explicit byte pointers but rather by the MACSYM
  9149.       facilities LOAD, STOR, etc.
  9150.  
  9151.    4. Flags can be defined with DEFSTR, MSKSTR, or as full-word
  9152.       parameters, and can be referenced with the TXmn MACSYM macro. Flags
  9153.       should never be defined as half-word quantities which require the
  9154.       programmer to remember whether to use TL or TR.  Other macros may
  9155.       be defined to operate on single-bit flags, which should be held in
  9156.       register 0; in this case too, no instruction should depend on the
  9157.       actual value or location of a flag.
  9158.  
  9159.  
  9160.  
  9161. 8.8. Subroutines
  9162.  
  9163. All AC's should be preserved over a subroutine call unless an explicit
  9164. statement to the contrary appears in the subroutine description.  ACs are
  9165. changed over a subroutine call only when values are to be returned to the
  9166. caller.
  9167.  
  9168. The allocation of ACs for all inter- and intra-module subroutine calls should
  9169. be:
  9170.  
  9171. ACs 1,2,3,4     Passing arguments and returning results.
  9172.  
  9173. ACs 0, 5-15     Preserved, not changed by subroutine (or saved and restored if
  9174.                 necessary).
  9175.  
  9176. AC 16           Temporary, used by MACSYM call/return procedure and reserved
  9177.                 for use by other call/return procedures.
  9178.  
  9179. AC 17           Global stack pointer
  9180.  
  9181. Call and return should be effected by 'pushj p,' and 'popj p,' respectively.
  9182. A set of assembler mnemonics has been defined for subroutine mechanics as
  9183. Standards                                                            Page 166
  9184.  
  9185. follows:
  9186.  
  9187. call            (= pushj p,) should be used to call subroutines, e.g.
  9188.                 'call subr'.
  9189.  
  9190. ret             (= popj p,) should be used to return +1 from subroutines.
  9191.  
  9192. retskp          should be used to return +2 from subroutines.  Retskp is
  9193.                 equivalent to:
  9194.  
  9195.  
  9196.         jrst [  aos (p)
  9197.                 popj p,]
  9198.  
  9199.  
  9200. callret         may be used to call a subroutine and return immediately
  9201.                 thereafter.  It is equivalent to
  9202.  
  9203.  
  9204.         call subr
  9205.         ret
  9206.  
  9207.    or
  9208.  
  9209.         call subr
  9210.          ret
  9211.         retskp
  9212.  
  9213.  
  9214. Note that 'callret' is not guaranteed to be a single instruction; therefore it
  9215. may not be skipped over.  The other returns above are guaranteed to be single
  9216. instructions.
  9217.  
  9218. These mnemonics are used to emphasize the FUNCTION being performed (calling,
  9219. returning) rather than the mechanics of the function (pushing, jumping, etc.).
  9220. Also, these mnemonics could continue to be used even if a more general calling
  9221. standard were adopted at some time in the future.
  9222.  
  9223. Return may also be effected by transferring control to one of the global
  9224. labels R or RSKP, e.g.
  9225.  
  9226.  
  9227.         jumpe t1, r             ; Equivalent to "jumpe t1, [ret]".
  9228.         jumpn t1, rskp          ; Equivalent to "jumpn t1, [retskp]".
  9229.  
  9230.  
  9231. The general temporaries should be used for passing arguments to subroutines
  9232. and returning values.  AC1 (t1) should be used for a single argument routine,
  9233. ACs 1 and 2 for a two-argument routine, etc.  When subroutines modify of
  9234. depend on global data, including flags, such effects should be clearly and
  9235. completely documented.
  9236.  
  9237. A routine defined to return caller +2 (skip) on success and caller +1 (noskip)
  9238. on failure is acceptable.  Returns greater than caller +2 are considered very
  9239. bad form.
  9240. Standards                                                            Page 167
  9241.  
  9242. 8.9. AC Definitions
  9243.  
  9244. The following mnemonics have been chosen to be consistent with the AC-use
  9245. conventions above.  The preserved ACs are divided into three groups, f
  9246. intended for Flags, and q1-q3 and p1-p6 intended for general use.  The ACs
  9247. within each group are consecutive.
  9248.  
  9249.  
  9250.         0 - f           10 - p1
  9251.         1 - t1          11 - p2
  9252.         2 - t2          12 - p3
  9253.         3 - t3          13 - p4
  9254.         4 - t4          14 - p5
  9255.         5 - q1          15 - p6
  9256.         6 - q2          16 - cx
  9257.         7 - q3          17 - p
  9258.  
  9259.  
  9260. The programmer should assume that each group (Tn, Qn, Pn,) is in ascending
  9261. order, e.g. that t2 = t1+1, but that the specific assignment of numbers may
  9262. change.  Explicit numeric offsets from AC symbols (e.g.  T1+1) should NEVER be
  9263. used.  Instructions which use more than one AC (e.g. div, jffo) must be given
  9264. an AC operand such that the other AC(s) implicitly affected are in the same
  9265. group.  E.g. t3 (and t4) is OK for idiv because t3+1=t4, but q3 is not because
  9266. q3+1=??.  AC0 is almost universally used as a flag register, and should not be
  9267. used for any other purpose.
  9268.  
  9269. There is a facility in MACSYM to save and automatically restore ACs.  The
  9270. indicated ACs are saved on the stack at the point of execution and a dummy
  9271. return is placed on the stack which causes these ACs to be restored
  9272. automatically when the current routine returns.  Use of this facility
  9273. eliminates the need for matching push/pop pairs at the entry and exits of
  9274. routines and eliminates the bugs which often arise from an unmatched push or
  9275. pop.  The facility is:
  9276.  
  9277.     saveAC <a,b,c>
  9278.  
  9279. in which a, b, and c are AC names; one or more may be specified.
  9280.  
  9281. Defining a different mnemonic for a preserved AC may be of value when the AC
  9282. is used for a specific function by a large body of code.  However, it offers
  9283. the possibility of confusion because two different symbols may refer to the
  9284. same AC unbeknownst to the programmer.  In smaller programs, use of certain
  9285. ACs can be restricted to specific functions, and a global definition is
  9286. appropriate.  A very large program, however, usually cannot accomodate a
  9287. sufficient number of dedicated ACs.
  9288.  
  9289. Therefore, when a specific function-oriented AC definition is made, it should
  9290. be explicitly decided which modules should use the definition (by "module" is
  9291. meant a separately-compiled section of code).  Within these modules, the usual
  9292. name for the AC must be purged so that there is no possibility of using two
  9293. different symbols for the same AC.
  9294.  
  9295. Only preserved ACs may be used for special definitions.  Parameters to
  9296. subroutines may be passed in functionally defined ACs in the following cases:
  9297.  
  9298.    1. On an intra-module call where the contents of the AC is appropriate
  9299.       to its function definition.
  9300. Standards                                                            Page 168
  9301.  
  9302.    2. On an inter-module call where the same definition exists in both
  9303.       modules and the AC is being used for its intended function.
  9304.  
  9305. A parameter may NOT be passed in a preserved AC unless both caller and callee
  9306. know it by the same name, and that name must be a specific one related to the
  9307. function which the AC is performing.
  9308.  
  9309. The procedure for declaring a functionally defined AC is:
  9310.  
  9311.     defAC newAC,oldAC
  9312.  
  9313. This must be done at the beginning of an assembly, and it causes newAC to take
  9314. on the value of oldAC.  OldAC must be the mnemonic for one of the regular
  9315. preserved ACs, and this mnemonic will be purged and therefore unavailable for
  9316. use in the current assembly.
  9317.  
  9318. An AC with a special definition should not be used for other purposes; e.g.
  9319. "JFN" should not be used to hold some quantity other than a JFN merely because
  9320. it happens to be available.
  9321.  
  9322.  
  9323.  
  9324. 8.10. Subroutine Documentation
  9325.  
  9326. The following is a suggested format for documenting the calling sequence of a
  9327. subroutine.  A description of this sort should appear at the beginning of
  9328. every subroutine, no matter how short.
  9329.  
  9330.  
  9331. srName: comment |
  9332.  
  9333. One or more lines describing what the subroutine does.
  9334.  
  9335.         Enter with:
  9336.          t1/ Description of first argument.
  9337.          t2/ Description of second argument.
  9338.           :
  9339.           :
  9340.          global foo/ Description of required global variable.
  9341.  
  9342.          Returns:
  9343.           +1: Conditions giving this return, with:
  9344.                t1/ Value(s) returned.
  9345.                t2/ More value(s) returned.
  9346.                 :
  9347.                 :
  9348.                global foo/ Description of how it was effected.
  9349.           +2: Conditions and values as above.
  9350. |
  9351.  
  9352. Notes:
  9353.  
  9354.    1. The arguments, if any, should be documented as the contents of
  9355.       registers and/or variables as shown.  If there are more than 4
  9356.       arguments, then the address of an argument list should be passed.
  9357.  
  9358.    2. It is absolutely essential that all global inputs and outputs
  9359.       (variables, tables, flags, etc., that are not declared within the
  9360. Standards                                                            Page 169
  9361.  
  9362.       subroutine) be noted; failure to do so hides crucial assumptions
  9363.       and effects from readers, and makes modification a very tricky
  9364.       business.
  9365.  
  9366.    3. An example of argument setup, call, and +1/+2 handling should be
  9367.       given if necessary for clarification.
  9368.  
  9369.    4. The return(s) should be noted as shown; "Always" or "Never" may be
  9370.       used as the condition where appropriate; the +2 return need not be
  9371.       shown if it does not exist; values returned should be described in
  9372.       the same form as arguments.
  9373.  
  9374.  
  9375.  
  9376. 8.11. Multi-line Literals
  9377.  
  9378. The use of multi-line literals is encouraged as a technique for making code
  9379. more readable and easier to follow.  The following additional rules apply:
  9380.  
  9381.    1. The opening bracket for a multi-line literal should occur in the
  9382.       position that the first character of the address field would have
  9383.       appeared if the instruction had an ordinary address, e.g.
  9384.  
  9385.  
  9386.               skipge foo
  9387.                jrst [
  9388.  
  9389.  
  9390.    2. The first and all following instructions within the literal should
  9391.       begin at the second tab stop, e.g.
  9392.  
  9393.  
  9394.               jrst [  move t1, mumble ; Comment
  9395.                       jrst fie ]      ; Comment
  9396.  
  9397.  
  9398.       The tab between the open bracket and the first opcode may be
  9399.       omitted if the line position is already at or beyond the second tab
  9400.       stop, e.g.
  9401.  
  9402.  
  9403.               GTJFN
  9404.                ercal [move t1, mumble
  9405.  
  9406.  
  9407.       If the first opcode is beyond the second tab stop, it is better to
  9408.       start the enclosed code on a new line, e.g.
  9409.  
  9410.  
  9411.               jumpge t1, [
  9412.                       move t1, mumble
  9413.  
  9414.  
  9415.    3. The closing bracket should follow the last field of the last
  9416.       instruction (as above), and should be before the comment on the
  9417.       same line.  It should have a blank before it to set it off from the
  9418.       preceding token.
  9419. Standards                                                            Page 170
  9420.  
  9421.    4. Nesting of multi-line literals to a depth greater than two is
  9422.       discouraged because of awkward formatting problems.
  9423.  
  9424.    5. Labels should not appear in multi-line literals.
  9425.  
  9426.    6. No hard and fast fules can be given as to when to use or not use
  9427.       multi-line literals.  However, a literal longer than about 10 lines
  9428.       becomes suspect.
  9429.  
  9430.    7. Use of ".+1" is legal in a literal to return to the main sequence.
  9431.  
  9432.  
  9433.  
  9434. 8.12. Flow of Control - Branch Conventions
  9435.  
  9436. In general, jumps should be to labels forward (down the page) from the point
  9437. of branch except for loops.  Tops of loops should be identified by comment.
  9438.  
  9439. The expressions ".+1" and ".-1" are the only legal uses of "."  (this
  9440. location).  All other potential uses should be avoided in favor of an
  9441. explicitly defined label.
  9442.  
  9443. "Global" jumps should be avoided altogether.  Higher-level languages do not
  9444. permit them, and with good reason.  The only exceptions are jumps to well
  9445. defined and published exit sequences, e.g. R, RSKP (see subroutine
  9446. conventions, above).
  9447.  
  9448.  
  9449.  
  9450. 8.13. Numbers
  9451.  
  9452. In general, there should be no occasion to use a literal number in in-line
  9453. code.  All parameters, bit definitions, etc., should be defined mnemonically
  9454. at appropriate places.  It is much easier to err in the direction of too
  9455. little use of mnemonics rather than too much; therefore, when in the slightest
  9456. doubt, define a mnemonic.
  9457.  
  9458.  
  9459.  
  9460. 8.14. Sharability
  9461.  
  9462. When two or more people are running the same (copy of a) program, they can
  9463. share the memory pages it occupies.  This cuts down on page faults and makes
  9464. the program, and the system, run more efficiently.  Most higher level
  9465. languages produce sharable code automatically, but the assembly language
  9466. programmer must take special pains to do so.  To write sharable programs, you
  9467. must collect all your impure data together in one place, segregating it from
  9468. actual program code and pure data (a word is impure if it can be modified at
  9469. runtime).  Each user gets a private copy of any page that has been written
  9470. into, so sharability is greatest when all the impure data has been collected
  9471. into the fewest possible pages.  Pure data (e.g.  command or dispatch tables)
  9472. can be freely mingled with code provided there is no way for control to pass
  9473. into it.
  9474. Standards                                                            Page 171
  9475.  
  9476. 8.15. Living in an Imperfect World
  9477.  
  9478. Much of the current DECSYSTEM-20 software was written before the existence of
  9479. this standard and therefore does not conform to it.  A great deal of
  9480. systematic editing has already been done to improve conformance, but obvious
  9481. irregularities exist.  In general, new code being added should conform exactly
  9482. to this standard even if being integrated with old code.  The following are
  9483. some specific problems which may arise and the recommended solutions:
  9484.  
  9485.  
  9486.  
  9487. 8.15.1. AC Mnemonics
  9488.  
  9489. Some code uses absolute numeric ACs.  If new code is being integrated into a
  9490. sequence which uses numeric ACs, it is desirable that the existing code be
  9491. edited to use the standard mnemonics, particularly for the preserved ACs.  If
  9492. the programmer cannot take the time to do that, then the mnemonics T1-T4
  9493. should be used for ACs 1-4, and other ACs should be referenced in the same way
  9494. as is done by the existing code.  Some code uses mnemonics A,B,C,D for the
  9495. temporary ACs.  These same mnemonics should be used for new code integrated
  9496. into this existing code, or all references can be edited to use the standard
  9497. mnemonics.  You may write some code using the standard mnemonics for preserved
  9498. ACs and then discover that the module into which you wish to put this code has
  9499. redefined some of these ACs.  The solution is one or a combination of the
  9500. following:
  9501.  
  9502.    1. Move the new code to a module which does not redefine the preserved
  9503.       ACs.
  9504.  
  9505.    2. Use different preserved ACs -- ones which have not been redefined.
  9506.       (Note it is not acceptable to use an AC with a special definition
  9507.       for other than its special purpose.)
  9508.  
  9509. Clearly, code which needs some of the special definitions must be placed in a
  9510. module which has these ACs defined and must therefore use only the other
  9511. preserved ACs.
  9512.  
  9513. Note that a value which usually resides in a special AC need not ALWAYS reside
  9514. there; for example, it can be placed in one of t1-t4 as a subroutine argument.
  9515.  
  9516.  
  9517.  
  9518. 8.15.2. Stack Handling
  9519.  
  9520. Use of the several stack variable facilities defined in MACSYM is recommended.
  9521. Some old code uses explicit PUSH and POP and references of the form -n(p)
  9522. however, and when anything more than trivial modifications must be made to
  9523. such code, it is most strongly recommended that the code be edited to use
  9524. STKVAR or TRVAR.  Failing that, references must be consistent with the
  9525. existing code.
  9526. How To                                                               Page 172
  9527.  
  9528.                  9. How to Write, Assemble, and Run Programs
  9529.  
  9530.  
  9531. Macro programs must be entered into the computer by means of a text editor.
  9532. The best such editor is EMACS, which not only surpasses other editors in power
  9533. and flexibility, but understands the syntax of Macro programs; to take
  9534. advantage of this understanding you should put EMACS in Macro mode (MM Macro
  9535. Mode).
  9536.  
  9537. Macro programs are fully compatible with the Exec Load-Class commands.  These
  9538. are:
  9539.  
  9540. COMPILE         The COMPILE command produces a relocatable object program from
  9541.                 one or more source programs.  The resulting object file has
  9542.                 the extension .REL.  If there is already a .REL file of the
  9543.                 given name that is newer than any of the source files, no
  9544.                 compilation will be done unless the /COMPILE switch is
  9545.                 included.
  9546.  
  9547. LOAD            The LOAD command invokes LINK, the system linkage-editor and
  9548.                 loader, to bring compiled modules into memory, resolving any
  9549.                 unresolved references, and produce an executable core image.
  9550.                 The LOAD command will recompile any module whose most recent
  9551.                 .REL file is older than the most recent source (.MAC), i.e.,
  9552.                 any source file you've edited since the last LOAD.  If you
  9553.                 want to have a directly-executable (.EXE) version of your
  9554.                 program on the disk, you should issue the SAVE or CSAVE
  9555.                 command after the LOAD command completes.  LOAD does not start
  9556.                 the program; you must use the START command to do this.
  9557.  
  9558. EXECUTE         The EXECUTE does what the LOAD command does and then STARTs
  9559.                 execution of your program.
  9560.  
  9561. DEBUG           The DEBUG command acts like the EXECUTE command, but it also
  9562.                 loads DDT (the source-level assembly language debugger) into
  9563.                 memory and starts DDT instead of the program.  It is
  9564.                 equivalent to LOAD followed by DDT.
  9565.  
  9566. If you repeatedly edit your program with EMACS, EDIT, or Otto, you can issue a
  9567. special command which saves the .MAC file, exits from the editor, and then
  9568. tells the Exec to reissue its last load class command, with the 'saved
  9569. arguments'.  In EDIT the command is 'g'; in Otto it is 'go'; in EMACS it must
  9570. be assigned to a key in your EMACS.INIT file.
  9571.  
  9572. All the LOAD-class commands have the following features:
  9573.  
  9574.    1. Recognizing that your program is in Macro, provided the extension
  9575.       (filetype) of the source file is .MAC.
  9576.  
  9577.    2. Saving their arguments, or if no arguments were specified,
  9578.       recalling the arguments of the last LOAD-class command in which
  9579.       arguments were specified.  For instance, if you have already issued
  9580.       the command
  9581.  
  9582.           LOAD foo,mylib:bar
  9583.  
  9584.       you can achieve the same effect in subsequent compilations by
  9585.       merely typing
  9586. How To                                                               Page 173
  9587.  
  9588.           LOAD
  9589.  
  9590.       The same effect is achieved by exiting the editor with a 'go'-type
  9591.       command, as described above.
  9592.  
  9593.    3. Taking arguments from an indirect file. You can put repeatedly used
  9594.       arguments in a file as they would appear in the command and then
  9595.       give a command like 'load @mac'.  The '@' indicates that the
  9596.       command should look to the file for its arguments.
  9597.  
  9598.    4. Gathering files together to produce one program. This is done by
  9599.       separating the files to be worked on by either commas or plus signs
  9600.       on the command line; commas mean to consider the files as separate
  9601.       modules (with surrounded by Title and End pseudo-ops), a plus signs
  9602.       means to concatenate the enclosing files.
  9603.  
  9604.    5. Passing switches to the compilers and LINK.
  9605.  
  9606. The load-class commands themselves have many switches.  Type any load-class
  9607. command followed by a slash and then a question mark to see what they are.
  9608. DDT                                                                  Page 174
  9609.  
  9610.            10. Interactive Debugging of Assembly Language Programs
  9611.  
  9612.  
  9613.        This chapter was adapted from the DECsystem-10 Utilities Manual and
  9614.     the Rutgers University IDDT manual.
  9615.  
  9616. DDT (Dynamic Debugging Tool) is a program that allows you to test and debug
  9617. assembly language programs interactively using the same symbols (labels and
  9618. register names) that are used in the program.  You can invoke DDT in either of
  9619. two ways:  type 'DDT' after the completion of a LOAD command (or after GETting
  9620. an .EXE file) or by using the DEBUG command (see 9).  In either case, the
  9621. effect is the same: DDT is loaded into pages 770-777 of your address space
  9622. (your program should not use these pages) and started.  You may then type DDT
  9623. commands to examine storage locations, set breakpoints, execute selected
  9624. sections of the program, single-step through the program, search for certain
  9625. instructions or data, modify code or data, and so forth.
  9626.  
  9627. DDT commands are purposely terse, and therefore somewhat cryptic.  You can use
  9628. DEL (RUBOUT) and ^U to edit commands; these have the expected effect, but echo
  9629. as "XXX".
  9630.  
  9631. In the following descriptions, a dollar sign ($) indicates that the ESC
  9632. (ESCAPE or ALTMODE) character should be typed.  All numbers are in octal
  9633. unless otherwise noted.
  9634.  
  9635.  
  9636.  
  9637. 10.1. Typeout Modes
  9638.  
  9639. You can select how DDT will display the contents of memory.  Normally (i.e. by
  9640. default) it tries to interpret each word as an instruction, decoding the
  9641. opcode, accumulator, index, indirect, index, and address fields and
  9642. substituting appropriate values from the program's (or DDT's own) symbol
  9643. table, e.g. 202067,,1000 (octal) would be typed by DDT as
  9644.  
  9645.     MOVEM T1, @FOO(Q3)
  9646.  
  9647. assuming that T1 is defined to be 1, Q3 to be 7, and FOO to be 100 in the
  9648. program's symbol table.
  9649.  
  9650. You can tell DDT to interpret words in other ways, either on a temporary or
  9651. prevailing basis.
  9652.  
  9653. The following commands are used to set the type-out modes:
  9654.  
  9655. $S              Symbolic instruction.
  9656.  
  9657. $C              Numeric, in current radix.
  9658.  
  9659. $F              Floating point.
  9660.  
  9661. $T              7-bit ASCII text.
  9662.  
  9663. $6T             SIXBIT text.
  9664.  
  9665. $5T             RADIX50.
  9666.  
  9667. $H              Halfwords, two addresses.
  9668. DDT                                                                  Page 175
  9669.  
  9670. $nO             Bytes (of n bits each), separated by commas.
  9671.  
  9672.  
  9673.  
  9674. 10.1.1. Address Mode Typeout
  9675.  
  9676. The following commands are used to set the address modes in typeout of
  9677. symbolic instructions and halfwords:
  9678.  
  9679. $R              Relative to symbolic address, e.g. FOO+17
  9680.  
  9681. $A              Absolute numeric address, e.g. 4023.
  9682.  
  9683.  
  9684.  
  9685. 10.1.2. Radix Typeout
  9686.  
  9687. You can also determine the radix (base, e.g. decimal, octal) in which the
  9688. numeric parts of a displayed word are typed, using the following command:
  9689.  
  9690. $nR             Change radix to n (n>1).
  9691.  
  9692.  
  9693.  
  9694. 10.1.3. Prevailing vs Temporary Modes
  9695.  
  9696. The typout-mode commands shown above may be started with a single ESC ($), or
  9697. two ESC's ($$):
  9698.  
  9699. $$              Set the prevailing type-out or address mode or a prevailing
  9700.                 radix (e.g. $$10R - set prevailing numeric radix to 10)
  9701.  
  9702. $               Set the temporary typeout mode; display words or fields in
  9703.                 this mode until carriage return is typed (e.g. $2R - set the
  9704.                 temporary numeric radix to 2).
  9705.  
  9706. CR (carriage return) Terminate temporary modes, and revert to prevailing
  9707.                 modes.
  9708.  
  9709. Initial modes are: $$S (symbolic instructions), $$R (relative addresses), and
  9710. $$8R (radix 8 [octal]).
  9711.  
  9712.  
  9713.  
  9714. 10.2. Storage Words
  9715.  
  9716. The following commands are used to examine storage words.  If you type ESC
  9717. between the address and the delimiter, the effective address of the typed
  9718. quantity will be calculated first, e.g. 1(p)$/ will print the contents of the
  9719. word after the one pointed to by p.
  9720.  
  9721. adr/            Open and examine the contents of adr in current type-out mode.
  9722.  
  9723. adr!            Open, but inhibit the type-out.
  9724.  
  9725. adr[            Open and examine word as a number in current radix.
  9726.  
  9727. adr]            Open and examine word as symbolic instruction.
  9728. DDT                                                                  Page 176
  9729.  
  9730. ;               retype last quantity typed (useful after setting a temporary
  9731.                 type-out mode, e.g. $6T;).
  9732.  
  9733. adr\            Open in current mode, but don't change location counter.
  9734.  
  9735.  
  9736.  
  9737. 10.2.1. Related Storage Words
  9738.  
  9739. The following are used to examine related storage words:
  9740.  
  9741. <lf> (linefeed or ^J) Close the current word (making any modifications typed
  9742.                 in) and to open the following word.
  9743.  
  9744. ^ (circumflex) or ^H (backspace) to close current word (with modifications)
  9745.                 and open adr-1.
  9746.  
  9747. ^I (tab)        Close current word (with modifications) and open word
  9748.                 specified by address of current word and to set the location
  9749.                 counter to that place.
  9750.  
  9751. \               Same as ^I, but location counter is not changed.
  9752.  
  9753. <cr>            Close word (with modifications) and revert type-out to
  9754.                 prevailing mode.
  9755.  
  9756.  
  9757.  
  9758. 10.2.2. Retyping In Modes Other than the Prevailing Mode
  9759.  
  9760. Each of the following commands specifies the mode in which DDT should
  9761. immediately retype the last expression typed by DDT or the user.  Neither the
  9762. temporary nor the prevailing mode is altered.
  9763.  
  9764. =               Retype as halfwords in current radix.
  9765.  
  9766. _ (undescore)   Retype as a symbolic instruction (address part determined by
  9767.                 $A or $R).
  9768.  
  9769. /               Type out, in current type-out mode, the contents of the
  9770.                 location specified by the address in the open instruction
  9771.                 word, and to open that location, but not to change the
  9772.                 location counter.
  9773.  
  9774. [               Retype as a number and open contents of the location specified
  9775.                 by the open instruction and not to change the location
  9776.                 counter.
  9777.  
  9778. ]               Same as above, but type out as a symbolic instruction.
  9779.  
  9780.  
  9781.  
  9782. 10.3. Typing In
  9783.  
  9784. These are shown by example:
  9785.  
  9786. ADD AC1,@DATE(17) to type in instruction simply type it in symbolically.
  9787. DDT                                                                  Page 177
  9788.  
  9789. 402,,202        to type in halfwords.
  9790.  
  9791. 1234            to type in octal values.
  9792.  
  9793. 99.             to type in fixed point decimal integer.
  9794.  
  9795. 101.11          to type in ..
  9796.  
  9797. 77.0E+2         ... a floating-point number.
  9798.  
  9799. "/ABCDE/        ASCII input (/ is delimiter; up to 5 characters).
  9800.  
  9801. "A$             ASCII input (one character, right justified).
  9802.  
  9803. $"/ABCDEF/      SIXBIT input (/ is delimiter; up to 6 characters).
  9804.  
  9805. $"Q$            one SIXBIT character.
  9806.  
  9807.  
  9808.  
  9809. 10.4. Symbols
  9810.  
  9811. A symbol is is defined in DDT as a string of up to six letters and numbers
  9812. including the special characters ., %, and $.  Characters after the sixth are
  9813. ignored.  They are defined in a table kept with the program you are DDTing,
  9814. called the "symbol table".  Programs have only one symbol table unless their
  9815. authors have taken explicit action to create more than one.  Such actions
  9816. include compiling and/or linking the program from more than one source and/or
  9817. .REL file.
  9818.  
  9819. foo$:           Permit reference to local symbols within a module with title
  9820.                 "foo" (open the symbol table of foo).  You can refer to
  9821.                 symbols in a program without issuing this command, but DDT
  9822.                 always appends "#" to the symbol on typeout in this case to
  9823.                 show that it's only guessing.  If a program has more than one
  9824.                 symbol table, you should use this command to let it know which
  9825.                 table to use.
  9826.  
  9827. n<sym           Insert or redefine a symbol in the symbol table and give it a
  9828.                 value n.
  9829.  
  9830. sym:            Insert or redefine a symbol and give a value equal to the
  9831.                 current location counter (.).
  9832.  
  9833. sym$$K          Delete a symbol from the symbol table.
  9834.  
  9835. sym$K           Kill a symbol for type-outs (but sill permit it for type-ins).
  9836.  
  9837. $D              Perform a $K on last symbol typed out and then retype the last
  9838.                 quantity.
  9839.  
  9840. sym#            Declare a symbol whose value is to be defined later.
  9841.  
  9842. ?               Type a list of all undefined symbols (created by #).
  9843. DDT                                                                  Page 178
  9844.  
  9845. 10.4.1. Special DDT Symbols
  9846.  
  9847. .               The present location counter.
  9848.  
  9849. $Q              The last quantity typed.
  9850.  
  9851. $$Q             The last quantity typed, halves reversed.
  9852.  
  9853. @               Indirect bit.
  9854.  
  9855. $M              The address of the mask register.
  9856.  
  9857. $I              The address of save flags.
  9858.  
  9859. $nB             Pointer to nth breakpoint.
  9860.  
  9861.  
  9862.  
  9863. 10.4.2. Arithmetic Operators
  9864.  
  9865. DDT can evaluate expressions involving the following arithmetic operators:
  9866.  
  9867. +               two's complement addition.
  9868.  
  9869. -               two's complement subtraction.
  9870.  
  9871. *               integer multiplication.
  9872.  
  9873. '               integer division (apostrophe).
  9874.  
  9875. Parentheses are used to denote an index field or to interchange the left and
  9876. right halves of the enclosed expression.
  9877.  
  9878. Expressions are evaluated as follows:  A left parenthesis stores the states of
  9879. the storage-word assembler on a stack and reinitializes the assembler to form
  9880. a new storage word.  A right parenthesis terminates the storage word and swaps
  9881. its two halves to form the result inside the parentheses.  The result is
  9882. treated in one of two ways:
  9883.  
  9884.    1. If +, -, ', or * immediately preceded the left parenthesis, the
  9885.       expression is treated as a term in the larger expression being
  9886.       assembled and therefore may be truncated to 18 bits if part of an
  9887.       address field.
  9888.  
  9889.    2. Otherwise, the swapped quantity is added into the storage word.
  9890.  
  9891. Parentheses may be nested to form subexpressions, to specify the left half of
  9892. an expression, or to swap the left half of an expression into the right half.
  9893.  
  9894.  
  9895.  
  9896. 10.4.3. Field Delimiters In Symbolic Type-ins
  9897.  
  9898. SPACE           Delimit opcode name (spaces or blanks).  Add the value of the
  9899.                 immediately preceding expression (normally an opcode) into the
  9900.                 sotrage word, and set a flag so that the expression going into
  9901.                 the address field is truncated to 18 bits.
  9902. DDT                                                                  Page 179
  9903.  
  9904. , (comma)       Delimit accumulator field.  The comma does three things:
  9905.  
  9906.                    1. The left half of the expression is added into the
  9907.                       storage word.
  9908.  
  9909.                    2. The right half is shifted left 23 bits (into the
  9910.                       accumulator field) and added into the storage word.
  9911.  
  9912.                    3. A flag is set to truncate addresses to 18 bits.
  9913.  
  9914. ,, (double comma) Delimit two halfwords.
  9915.  
  9916. ( )             Delimit index register (the halfwords are swapped).
  9917.  
  9918. @               Indicate indirect addressing (set bit 13).
  9919.  
  9920. The address field expression is terminated by any word termination command or
  9921. character.
  9922.  
  9923.  
  9924.  
  9925. 10.5. Breakpoints
  9926.  
  9927. You can automatically stop your program at a strategic point by specifying an
  9928. address at which the program should stop if the instruction at that address is
  9929. about to be executed (i.e. if the PC (Program Counter) attains that value).
  9930. These addresses are called breakpoints; there may be up to eight of them
  9931. active at one time.  Breakpoints may be set before the debugging run is
  9932. started or during another breakpoint stop.
  9933.  
  9934. The commands to set and remove breakpoints are:
  9935.  
  9936. adr$nB          Set breakpoint n.
  9937.  
  9938. adr$B           Set next unused breakpoint.
  9939.  
  9940. adr$$nB         Set breakpoint...
  9941.  
  9942. adr$$B          ... with automatic proceed.
  9943.  
  9944. x,,adr$nB       Set breakpoint which will...
  9945.  
  9946. x,,adr$B        ...automaticaly open and...
  9947.  
  9948. x,,adr$$nB      ...display the contents of...
  9949.  
  9950. x,,adr$$B       ...address X.
  9951.  
  9952. 0$nB            Remove breakpoint n.
  9953.  
  9954. $B              Remove all breakpoints.
  9955.  
  9956. $nB/            Check status of a breakpoint.
  9957.  
  9958. If the address field (adr) is omitted, the breakpoint will be set at the
  9959. current location.
  9960.  
  9961. When your program reaches a breakpoint, DDT types (for example)
  9962. DDT                                                                  Page 180
  9963.  
  9964.     $7B>>FOO+23
  9965.  
  9966. where breakpoint number 7 was set at location FOO+23 (for instance, by the
  9967. command FOO+23$7B).
  9968.  
  9969.  
  9970.  
  9971. 10.5.1. Proceeding from a Breakpoint
  9972.  
  9973. After you have poked around to your satisfaction, you may continue the program
  9974. using the following commands:
  9975.  
  9976. $P              Proceed from a breakpoint.  Keep executing until another (or
  9977.                 the same) breakpoint is encountered, or the program halts.
  9978.  
  9979. n$P             Proceed as above, but pass this breakpoint n-1 times (i.e.
  9980.                 ignore it until the nth encounter).
  9981.  
  9982. $$P             Proceed from a breakpoint...
  9983.  
  9984. n$$P            ...and thereafter proceed automatically.
  9985.  
  9986.  
  9987.  
  9988. 10.5.2. Single Stepping
  9989.  
  9990. After a breakpoint has been encountered, you may wish to single-step through
  9991. your program, rather than continuing with $P.  DDT provides the following
  9992. commands for single-stepping:
  9993.  
  9994. $x              Execute the current instruction, type out the new contents of
  9995.                 any locations affected by the instruction, type out the next
  9996.                 instruction, and wait.  No breakpoints are moved or removed.
  9997.  
  9998. n$x             Like $x, but do it for n instructions.
  9999.  
  10000. n$$x            Same as $x, but execute instructions unconditionally, without
  10001.                 typing anything out, until PC reaches either .+1 or .+2.  This
  10002.                 is useful for executing debugged subroutines or UUO's.
  10003.  
  10004.  
  10005.  
  10006. 10.5.3. Conditional Breakpoints
  10007.  
  10008. You can insert a conditional instruction, or a call to a closed subroutine,
  10009. using the following command:
  10010.  
  10011. $nB+1/instruction Insert a conditional instruction or call a conditional
  10012.                 routine, when breakpoint n is reached.
  10013.  
  10014. When the breakpoint is reached, this instruction or subroutine is executed.
  10015. If the instruction (or subroutine) does not skip, the program either stops or
  10016. continues based on the contents of the proceed counter (located at $nB+2).  If
  10017. the instruction or subroutine skips, the program stops.  If the subroutine
  10018. causes a double skip return, the program proceeds.  This works as follows:
  10019. DDT                                                                  Page 181
  10020.  
  10021.  
  10022.         skipe $nB+1             ; Conditional break instruction?
  10023.          xct $nB+1              ;  Yes, execute it (it may skip).
  10024.          sosg $nB+2             ;  Decrement proceed counter.
  10025.          jrst <break routine>   ;  If greater than 0 then break
  10026.         jrst <proceed routine>  ;   else proceed.
  10027.  
  10028.  
  10029.  
  10030. 10.5.4. Starting the Program
  10031.  
  10032. $G              Start at .JBSA (the normal starting address).
  10033.  
  10034. adr$G           Start or continue at a specific address.
  10035.  
  10036.  
  10037.  
  10038. 10.6. Searching
  10039.  
  10040. There are three kinds of searches:  word search, not-word search, and
  10041. effective address search.  In the following commands, a<b>c are respectively:
  10042. lower limit, upper limit, searchword; a defaults to 0, b defaults to "end".
  10043.  
  10044. The word search and not-word search compare each storage word with the word
  10045. being searched for in those bit positions where the mask, located at $M, has
  10046. ones.  The mask word contains all ones unless otherwise set by you.  All words
  10047. in the given range that show equality to the search object under the mask are
  10048. typed out.
  10049.  
  10050. a<b>c$w         Search for word containing c.
  10051.  
  10052. a<b>c$N         Search for word not containg c.
  10053.  
  10054. a<b>c$E         Search for a word containing effective address c.
  10055.  
  10056. n$M             Set the mask to n.
  10057.  
  10058. $M/             Examine the mask.
  10059.  
  10060. You may use the word search command to list the range of locations from
  10061. 'first' to 'last', as follows:
  10062.  
  10063.     0$M first<last>0$W
  10064.  
  10065. This sets the mask to 0 and then performs a word search for 0.  Remember to
  10066. put the mask back to -1 (or whatever its previous value was) before
  10067. continuing.
  10068.  
  10069.  
  10070.  
  10071. 10.6.1. Zeroing Memory
  10072.  
  10073. $$Z             Zero memory except DDT, locations 20-137, and the symbol
  10074.                 table.
  10075.  
  10076. first<last$$Z   Zero locations 'first' thru 'last'.
  10077. DDT                                                                  Page 182
  10078.  
  10079. 10.7. Special Characters
  10080.  
  10081. The following are used in DDT type-outs:
  10082.  
  10083. >               Break caused by conditional break instruction.
  10084.  
  10085. >>              Break because proceed counter exhausted.
  10086.  
  10087. U               Undefined symbol can not be assembled.
  10088.  
  10089. #               (as in FOO#) The symbol has been interpreted from a symbol
  10090.                 table you have not formally opened.
  10091.  
  10092. number,,number  Half-word number type-out.
  10093.  
  10094. #1.234E+27      Unnormalized floating-point number.
  10095.  
  10096. 123.            Decimal point indicates decimal number.
  10097.  
  10098. ?               Illegal command or all 8 breakpoints used.
  10099.  
  10100. XXX             Rubout, ^U echo.
  10101.  
  10102.  
  10103.  
  10104. 10.8. Miscellaneous DDT Commands
  10105.  
  10106.  
  10107.  
  10108. 10.8.1. Immediate Mode Instruction Execution
  10109.  
  10110. instr$X         Execute the instruction in immediate mode.
  10111.  
  10112.  
  10113.  
  10114. 10.8.2. Execute Indirect Command File
  10115.  
  10116. $Y Read and execute a command file called BATCH.DDT.
  10117.  
  10118. $"/name/$Y Read and execute a command file called name.DDT.
  10119.  
  10120.  
  10121.  
  10122. 10.8.3. Patch
  10123.  
  10124. A patch is a section of code or data inserted into an .EXE file, usually to
  10125. correct a bug.  At the appropriate location, an instruction is replaced by an
  10126. unconditional jump to the new code; the instruction that was displaced is
  10127. included in the new code, and the new code usually terminates with a jump back
  10128. the original sequence.  You can use DDT to insert a patch with the following
  10129. commands:
  10130.  
  10131. $<              Patch before the currently open location.
  10132.  
  10133. $$<             Patch after the currently open location.
  10134.  
  10135. $>              End the patch.
  10136. DDT                                                                  Page 183
  10137.  
  10138. When you begin a patch, DDT will open the first location in the patch area (an
  10139. area set aside automatically by Macro, or by other means, for the installation
  10140. of patches).  The patch area is defined by the symbol PAT.. or PATCH or
  10141. C(.JBFF), whichever is found first.  Alternately, you can type a single symbol
  10142. preceding the patch begin command (as in "FF$<"), and it will be taken as the
  10143. beginning of the patch area.  If you are doing a patch after the current
  10144. location, DDT will insert your original instruction and then open open the
  10145. next location.  You may now proceed to enter your patch using linefeeds to
  10146. enter the new instructions or data.
  10147.  
  10148. When you have finished the patch, type $> and DDT will:
  10149.  
  10150.    1. Close the current location, if any.
  10151.  
  10152.    2. If a patch "before" was was being done, DDT will insert the
  10153.       instruction from the original location.
  10154.  
  10155.    3. DDT will insert JUMPA 1,LOC+1 and JUMPA 2,LOC+2, where LOC is the
  10156.       original patch location.  Thus skipping instructions may be
  10157.       patched.
  10158.  
  10159. Note:  the original location is not changed until the patch completion command
  10160. is given.  Thus, you can give up or restart the patch at any time.  DDT
  10161. remembers the parameters of the most recent patch begin command and uses them
  10162. at patch completion, whereupon they are forgotten.  A second patch completion
  10163. will produce an error indication.
  10164.  
  10165.  
  10166.  
  10167. 10.9. Sample DDT Session
  10168.  
  10169. Here's a very short DDT session, just to get you started.  A Macro program is
  10170. compiled and loaded, DDT is called in, a breakpoint is set, the program is
  10171. started and runs until the breakpoint is encountered.  A location is examined
  10172. and its contents replaced, and the program is then continued.  This short
  10173. example illustrates the most useful DDT commands.  In the example, after DDT
  10174. is started, DDT typeout is shown in upper case; your commands are shown in
  10175. lower case.
  10176.  
  10177.  
  10178. @load foo                      ; Compile and load the program.
  10179. MACRO: Foo
  10180. LINK:  Loading
  10181. EXIT
  10182. @ddt                            ; Start DDT.
  10183. DDT                             ; DDT's greeting.
  10184. foo$:                           ; Open Foo's symbol table.
  10185. subr$b  $g                      ; Set a breakpoint and start.
  10186. $1B>>SUBR                       ; The breakpoint is encountered.
  10187. ./ MOVEM T1, FROB               ; Display the instruction at the breakpoint.
  10188. t1/ 5   -1                      ; Display contents of t1, then replace
  10189.                                 ;   it with -1.
  10190. $x                              ; Now execute the instruction.
  10191. T1/ -1    FROB/ -1              ; The effected locations are displayed.
  10192. SUBR+1/ MOVE T1,Q1   $p         ; The next instruction is shown, and
  10193. .                               ;  the program is continued using $P.
  10194. .                               ; (the session continues...
  10195. .                               ;  ...)
  10196. DDT                                                                  Page 184
  10197.  
  10198. ^Z                              ; Exit from DDT
  10199. @                               ;  back to the Exec.
  10200.  
  10201.  
  10202.  
  10203. 10.10. IDDT (Invisible DDT)
  10204.  
  10205.        This section is extracted from a document from Rutgers University,
  10206.     describing IDDT, a program that has a long lineage, starting at BBN
  10207.     and including at least SRI, MIT, and Rutgers.  All of the elementary
  10208.     commands and features have been included.  For further details, see
  10209.     the complete IDDT manual.
  10210.  
  10211. IDDT is a debugger which will handle programs with multiple forks and ones
  10212. which use high core (which is used by regular DDT) as well as other programs
  10213. which DDT can't handle.  It has many of the same commands as the standard DDT
  10214. and ordinarily may be used without regard to the fact that it is a different
  10215. debugger.
  10216.  
  10217. The primary feature of IDDT is that it operates on user programs which run in
  10218. any inferior fork of IDDT.  Thus, an errant user program cannot destroy the
  10219. debugger or its symbol table because the debugger is in a totally different
  10220. address space.  This relation between the program being debugged and IDDT is
  10221. much the same as the relation between current user programs (including IDDT)
  10222. and the Exec.  Because of this, IDDT must simulate many of the services
  10223. ordinarily provided by the EXEC, such as GET, LINK, RUN, etc.
  10224.  
  10225.  
  10226.  
  10227. 10.10.1. Using IDDT
  10228.  
  10229. IDDT may be called into service either before or after programs have been
  10230. loaded into memory.  This is done by typing the Exec command IDDT.
  10231.  
  10232. This command causes the EXEC to splice a fork containing IDDT in between
  10233. itself and the program to be debugged.  This operation is done in a way that
  10234. preserves the state of the user's program including its fork structure.  It is
  10235. possible to ^C out of a running program and get IDDT.  If this is done, a $P
  10236. (Proceed) command will resume running the user program.
  10237.  
  10238. The EXEC command "NO IDDT" will unsplice the fork containing IDDT in the event
  10239. the user wishes to continue his program without having an IDDT above it.
  10240.  
  10241. A fairly common practice is to get IDDT first and use it to load the program
  10242. to be debugged.  One of three IDDT commands may be used to load the object
  10243. program: $L (run LINK in the user fork), ;L (Loadgo (RUN) named file), or ;Y
  10244. (Yank (GET) the named file).  The first of these is essentially the same as
  10245. the EXEC command, LINK.  The second is comparable to RUN, while the last is
  10246. similar to GET. In addition the ;M (Merge the named file) will simulate the
  10247. MERGE EXEC command.
  10248.  
  10249. The $L command causes IDDT to run LINK in the user's address space.  Upon
  10250. completion, LINK may return control to IDDT.  At this point IDDT will have the
  10251. LOADER's symbol table.  In order to switch to the symbols of the program which
  10252. was loaded, the ;S (Symbol) command should be typed.  ;S tells IDDT to look
  10253. for a standard symbol table pointer in location 116 (.JBSYM).
  10254. DDT                                                                  Page 185
  10255.  
  10256. 10.10.2. EXEC-like Features
  10257.  
  10258. For convenience, IDDT has several commands which provide the same services as
  10259. some EXEC commands.  These are:
  10260.  
  10261. <n>;A           Give informaton about page n or if n is missing about all
  10262.                 pages.  (like a INFO MEMORY command)
  10263.  
  10264. <n>;F           Fork information about fork n or if n is missing about all
  10265.                 forks.  (like INFO FORK command)
  10266.  
  10267. <n>;J           JFN information on JFN n or if n is missing about all JFNs.
  10268.                 (like INFO FILES)
  10269.  
  10270. ;;J             Job information (like INFO JOB and INFO FORK)
  10271.  
  10272. ;I              Interupt status of PSI system (like INFO PSI-STATUS)
  10273.  
  10274. <n>;V           "View cell" - sets address, contents of which is displayed
  10275.                 when ^T (control T) is typed. If n is missing clear "view
  10276.                 cell"
  10277.  
  10278. ;Y              Yank - analogous to EXEC command GET
  10279.  
  10280. ;M              Merge - analogous to EXEC command MERGE
  10281.  
  10282. ;L              Loadgo - Analogous to EXEC command RUN
  10283.  
  10284. $$G             Go - analogous to EXEC command START
  10285.  
  10286. $$1G            Analogous to EXEC command REENTER
  10287.  
  10288. $$nG            Analogous to EXEC command START at offset n of entry vector
  10289.  
  10290. $P              Proceed - analogous to EXEC command CONTINUE
  10291.  
  10292. ;U              Unget (SAVE 0 777)
  10293.  
  10294. a<b$nU          Unprotect page (like SET PAGE-ACCESS command)
  10295.  
  10296. loc$$nU         Set address break trap for loc in current fork; n is the type
  10297.                 of access to trap on (defaults to 2):  1 - read, 2 - write, 4
  10298.                 - execute (these can be or'ed together); like the EXEC command
  10299.                 SET ADDRESS-BREAK
  10300.  
  10301. ;O              Obtain symbol file (no EXEC equivalent)
  10302.  
  10303. ;W              Write symbol file (no EXEC equivalent)
  10304.  
  10305. ;H              Halt IDDT (return to EXEC)
  10306.  
  10307. ;W, ;M, ;Y, ;O, ;L, and ;U ask for a file name from the user.  The default
  10308. extension will be .EXE or .SYMBOLS as appropriate.
  10309. DDT                                                                  Page 186
  10310.  
  10311. 10.10.3. View Cell
  10312.  
  10313. A command such as FOO+5;V or 12345;V will define the "view cell".  When IDDT
  10314. handles a ^T (control T) the address and contents of the view cell will be
  10315. typed.  The view cell may be undefined and consequently removed from the ^T
  10316. (control T) typeout by ;V (no argument).
  10317.  
  10318. Note: The contents of the view cell in the fork to which IDDT's attention has
  10319. been directed to is what will be typed out on the ^T.
  10320.  
  10321.  
  10322.  
  10323. 10.10.4. Breakpoints
  10324.  
  10325. When a fork hits a breakpoint, IDDT's handle on the breaking fork is printed
  10326. in parens before the breakpoint name unless it is the the top fork, e.g.
  10327.  
  10328.     (2)$1B>>105.
  10329.  
  10330.  
  10331.  
  10332. 10.10.5. Fork Handles
  10333.  
  10334. IDDT's attention can be shifted to any fork in the program being debugged
  10335. using the ;;F command.  In the form: n;;F, fork n becomes current and all
  10336. examines, deposits, breakpoints etc pertain to it.  n is a small number
  10337. (actually the low bits of IDDT's fork handle on the fork in question).  0
  10338. always means the top fork of the debugee.  In the form m<n;;F, attention is
  10339. switched to the m-th inferior of fork n. Again, n is IDDT's handle on some
  10340. fork in the debugee.  m is the low bits of fork n's relative handle on some
  10341. fork (IDDT executes GFRKH(400000+n, 400000+m) to get the new handle).  The
  10342. relative handle so obtained is printed.
  10343.  
  10344.  
  10345.  
  10346. 10.10.6. Escape character
  10347.  
  10348. IDDT initially arms ^D (control D) as an interrupt character.  This may be
  10349. changes with the ;E (set Escape character) command.  If a user program has
  10350. been started under IDDT, typing ^D (the escape character) will gracefully
  10351. suspend that process and give control to IDDT which then types a message of
  10352. the form
  10353.  
  10354.     XXX:FOO+5/   MOVE A,DAT+21
  10355.  
  10356. The interrupt is understood to have occurred immediately before this
  10357. instruction, and that if a $P (proceed) command is typed, this instruction
  10358. will be the next one executed by the user.
  10359.  
  10360.  
  10361.  
  10362. 10.10.7. RUBOUT and Type-in Editing
  10363.  
  10364. RUBOUTs typed while IDDT is running behave much the same as they do in normal
  10365. DDTs, that is, the current command is aborted.  This is particularly
  10366. convenient for stopping long searches ($W, $N and $E commands), with IDDT
  10367. because it is an interrupt and does not have to be read by a PBIN to initiate
  10368. action as it does with old-style DDT's.
  10369. DDT                                                                  Page 187
  10370.  
  10371. On command typein RUBOUT acts as it does under the EXEC, that is to delete the
  10372. previous character in the input buffer.  In addition ^W and ^U (control W and
  10373. control U) also work as in the EXEC by deleting the word and line
  10374. respectively.
  10375.  
  10376.  
  10377.  
  10378. 10.10.8. Interface with the Exec
  10379.  
  10380. The EXEC command "FORK n" may be used to switch the EXEC's attention between
  10381. the fork containing IDDT and the one containing the user's program.  This may
  10382. be done for the purpose of doing a "MEMSTAT" or ^T.  The EXEC examine and
  10383. deposit commands also pertain to the currently selected fork.
  10384.  
  10385. If the user has returned to the EXEC by typing ;H to IDDT, IDDT may be resumed
  10386. by a "CONTINUE".  A HALTF in the user's program will return to IDDT.  It may
  10387. be continued by a $P to IDDT.
  10388.  
  10389.  
  10390.  
  10391. 10.10.9. Saving a Core Image
  10392.  
  10393. The ;U command asks for a file name and then does the equivalent of a SAVE
  10394. from page 0 through page 777 on this file.  The entry vector will be copied if
  10395. it exists.  If no entry vector has been declared for the fork, IDDT will set a
  10396. length one entry vector at "." .  A message is typed to this effect.
  10397.  
  10398.  
  10399.  
  10400. 10.10.10. Single Instruction Executes
  10401.  
  10402. When the user types an instruction followed by $X, IDDT pushes down several
  10403. words of state information, plants the instruction in the user's address space
  10404. followed by three breakpoints, and restarts the user at this special location.
  10405. When the instruction completes, IDDT types the proper number of $-signs to
  10406. indicate how many times the instruction skipped, and pops back the saved state
  10407. information.  The state information currently includes the program counter
  10408. ($G), and which breakpoint (if any) the user was stopped at.  This makes it
  10409. possible to hit a breakpoint, execute an instruction (which might be a PUSHJ
  10410. to a subroutine), and then, upon completion of the $X, do a $P to proceed the
  10411. breakpoint.
  10412.  
  10413. IDDT's $X register points in the user's address space to the four words which
  10414. will be used for $X commands.  $X initially contains 777774 so that the top
  10415. four words are used.  The user is free to change the contents of $X.
  10416.  
  10417.  
  10418.  
  10419. 10.10.11. Search Commands
  10420.  
  10421. The search commands ($W, $N, and $N) have been generalized to take an argument
  10422. which specifies the maximum number of "finds" that shall occur before the
  10423. search will terminate.  An example is:
  10424.  
  10425.     FOO<BAR>QQZZ$5E
  10426.  
  10427. This command will stop after typing five instructions lying between locations
  10428. "FOO" and "BAR" which have an effective address of "QQZZ".
  10429. DDT                                                                  Page 188
  10430.  
  10431. 10.10.12. Single Stepping
  10432.  
  10433. There are two flavors of single stepping, $Y and $J:
  10434.  
  10435. $J just fetches the next instruction and executes it, so if that next
  10436. instruction is a subroutine call, the entire subroutine will be executed, and
  10437. if that instruction is a jrst, the program will be continued.
  10438.  
  10439. $Y fetches the next instruction and if it is a jump of any sort, it is
  10440. interpreted so that in fact only one instruction is executed at a time, so
  10441. that if the instruction is a subroutine call, the program counter will be set
  10442. to the beginning of the subroutine. (this is most like $X in other DDTs)
  10443.  
  10444. Both commands have the same syntax:
  10445.  
  10446. $J single steps
  10447.  
  10448. <num>$J will step num times
  10449.  
  10450. <num>(<loc>)$J will step num instruction or until the contents of location loc
  10451. are changed, in which case it will stop and say
  10452.  
  10453.     (WP)PC     LOC/        new contents of loc
  10454.  
  10455. where pc is the instruction after the one that attempted to change the value
  10456. of loc.  Note, however the contents of loc will not be changed.
  10457.  
  10458. <loc>$$J is equivalent to infinity(<loc>)$J, ie it will single step until an
  10459. attempt is made to change the contents of loc.
  10460.  
  10461. If the verbose switch is on, the instruction being executed and any AC's or
  10462. the view cell (see above) that change will be typed out.
  10463.  
  10464. Both instruction are extremely slow.
  10465.  
  10466.  
  10467.  
  10468. 10.10.13. Other Commands
  10469.  
  10470. ^L              blanks the screen
  10471.  
  10472. $.              returns current PC
  10473.  
  10474. ;.<internal symbol name> inserts the value of the internal symbol into the
  10475.                 expression.  Current internal symbols are:
  10476.  
  10477.                 SYMOFS          Offset from symbol printed as in
  10478.                                 <symbol>+<nnn> (default value is 777 octal).
  10479.  
  10480.                 PC              Current PC (see also $.) (can be set with
  10481.                                 <adr>$0G).
  10482.  
  10483.                 example: ;.PC/ 10010 displays the contants of the PC register
  10484. Examples                                                             Page 189
  10485.  
  10486.                            11. Programming Examples
  10487.  
  10488.  
  10489. The programs in this chapter are purely pedagogical in nature and don't do
  10490. anything useful.
  10491.  
  10492.  
  10493.  
  10494. 11.1. Binary Search Program
  10495.  
  10496.  
  10497.         title binSrc - Demonstration of binary search.
  10498.  
  10499.         $VERNO=1                ; Program version number
  10500.         $EDNO=2                 ; Program edit number
  10501.  
  10502. comment \  Most recent update:  10:23am  Thursday, 19 April 1979
  10503.  
  10504. Prompts user for a number, looks it up in a list containing the
  10505. even numbers from 2 to 12 (with some duplicates).
  10506.  
  10507. H. Eskin, F. da Cruz, CUCCA, April 1979
  10508. \
  10509.         search CUsym            ; Obtain Columbia macros, symbols, etc.
  10510.         %setEnv                 ; Search Monsym, Macsym, initialize things.
  10511.  
  10512. numLen=^d20                     ; Buffer for number typein.
  10513.  
  10514.         ; Standard 3-word entry vector
  10515.  
  10516. entVec: jrst start              ; Start address
  10517.         jrst reEntr             ; Reentry address
  10518.         %version ($VERNO,$EDNO) ; Standard version number
  10519. evlen=.-entvec                  ; Entry vector length
  10520.  
  10521. reentr: jrst start              ; reentry handling (nothing special)
  10522.  
  10523. start:  %setUp                  ; RESET, set up stack, etc.
  10524.         hrroi t1, [asciz /Number to search for: /]
  10525.         call getNum
  10526.         call search
  10527.          %print < No exact match%/>
  10528.         %print < %d found at %o%/>,<exp t1,t2>
  10529.         jrst start
  10530. Examples: Binary Search                                              Page 190
  10531.  
  10532.  
  10533. search: comment | Binary search routine
  10534.  
  10535.         Looks the given number up in a list, which is presumed to be
  10536.         in ascending numeric order (with duplications allowed).
  10537.         Returns values appropriately for insertion of a new element.
  10538.  
  10539.         Enter with:
  10540.          t1/ Number to search for.
  10541.          global list/ list of numbers to be searched, in ascending order.
  10542.          global top/ address of the word after the last element in the list.
  10543.  
  10544.         Returns:
  10545.          +1: if number not found,
  10546.          +2: if number found, with (in either case):
  10547.             t1/ Number that was found;
  10548.             t2/ The address of the greatest number less than or equal
  10549.                 to the desired number.  If no such number, then the address
  10550.                 of the word before the beginning of the list.
  10551. |
  10552. Lo=p1                           ; Mnemonic aliases for registers
  10553. hi=p2                           ;  (not normally recommended).
  10554.         PURGE p1,p2             ;  (to avoid duplicate names for same ACs).
  10555.  
  10556.         saveAC <hi,Lo,q1>       ; Save these registers.
  10557.  
  10558. ; Set up initial conditions.
  10559.  
  10560.         movei Lo, list-1        ; Point before search list
  10561.         move hi, top            ;  and after it.
  10562.  
  10563. ; This loop does the binary search.
  10564.  
  10565. loop:   cail lo, -1(hi)         ; Is the list null?
  10566.          jrst nFound            ;  Yes, then the element has not been found.
  10567.         move q1, Lo             ; No, calculate midpoint: set probe to Lo
  10568.         add q1, hi              ;  ... + hi
  10569.         idivi q1, 2             ;  ... / 2.
  10570.         camn t1, (q1)           ; Exact match?
  10571.          jrst found             ;  Yes, done.
  10572.  
  10573. ; No match, adjust boundaries of list appropriately.
  10574.  
  10575.         caml t1, (q1)           ; If search key is not less than this one
  10576.          skipa Lo, q1           ;  then move low bound and skip
  10577.          move hi, q1            ;  else move high bound,
  10578.         jrst loop               ; and go back and try again.
  10579.         ;..                     ;  (continued next page...
  10580.  
  10581. Examples: Binary Search                                              Page 191
  10582.  
  10583.  
  10584.  
  10585. ;...continued from preceding page)
  10586.  
  10587.  
  10588. ; Get here when the list is used up (and the search object not found).
  10589.  
  10590. nFound: move t1, (Lo)           ; Greatest element that was less than search
  10591.         move t2, Lo             ;   key was found at this address.
  10592.         ret                     ; Return indicating failure to find key.
  10593.  
  10594. ; Get here only on exact match.  Must check for duplicates.
  10595. ;  Put aobjn counter in left half of probe, then search.
  10596.  
  10597. found:  movn t2, top            ; Negative Address of 1st element not in list.
  10598.         add t2, q1              ; Calculate -number of elements to be checked.
  10599.         hrl q1, t2              ; Make aobjn pointer.
  10600.  
  10601. next:   camn t1, 1(q1)          ; Toodle down the list until no match
  10602.          aobjn q1, next         ;  or no more elements.
  10603.  
  10604. fin:    move t1, (q1)           ; Return the value that was found
  10605.         hrrz t2, q1             ;  and its address.
  10606.         retskp                  ; Skip return to indicate that it was found.
  10607.  
  10608. p1=Lo                           ; Restore normal AC mnemonics
  10609. p2=hi                           ;  ...
  10610.         PURGE hi, Lo            ;  ...
  10611. Examples: Binary Search                                              Page 192
  10612.  
  10613.  
  10614. getNum: comment | Get a number from the terminal, allowing editing.
  10615.  
  10616.         Enter with:
  10617.          t1/ pointer to asciz prompt.
  10618.          global numBuf defined to be of length numLen.
  10619.  
  10620.         Returns +1 always, with
  10621.          t1/ number that was typed.
  10622.  
  10623.         This routine catches all format errors and reprompts the user
  10624.         until a valid integer is typed.
  10625. |
  10626.         saveAC <t2,t3,q1>       ; Since not used for passing args.
  10627.  
  10628.         move q1, t1             ; Save pointer to prompt.
  10629.  
  10630. reTry:  move t1, q1             ; And restore it in case of error.
  10631.         PSOUT                   ; Issue the first prompt.
  10632.  
  10633.         hrroi t1, numBuf        ; Point to buffer for string that user types.
  10634.         movx t2, RD%BEL!numLen  ; Break on CRLF, max length for typein.
  10635.         move t3, q1             ; Reprompting text.
  10636.         RDTTY                   ; Get string, allowing editing.
  10637.          %jsErr                 ; Errors are fatal, but very unlikely.
  10638.  
  10639. ; Now convert the string to a number.  We don't do the NIN directly from
  10640. ;  the terminal because NIN does not allow editing.
  10641.  
  10642.         hrroi t1, numBuf        ; Point to string representation of number.
  10643.         movei t3, ^d10          ; Radix for interpretation.
  10644.         NIN                     ; Number In - do the conversion.
  10645.          %jsErr (,reTry)        ; On error, print msg and ask again.
  10646.  
  10647.         move t1, t2
  10648.         ret                     ; All OK, return.
  10649. Examples: Binary Search                                              Page 193
  10650.  
  10651.  
  10652.         %impure                 ; impure data
  10653.  
  10654. numBuf: block numLen            ; For number typein.
  10655.  
  10656.         radix ^d10
  10657. list:   0
  10658.         2
  10659.         2
  10660.         2
  10661.         4
  10662.         6
  10663.         8
  10664.         10
  10665.         10
  10666.         12
  10667. top:    .
  10668. ^L
  10669.         end <evlen,,entvec>
  10670.  
  10671. ; - EMACS editing modes -
  10672.  
  10673. ; local modes:
  10674. ; mode:Macro
  10675. ; comment start:;
  10676. ; comment rounding:+1
  10677. ; end:
  10678. Examples: COMND JSYS                                                 Page 194
  10679.  
  10680. 11.2. COMND Example
  10681.  
  10682.  
  10683.         title Foo - A small Exec
  10684.  
  10685. $VERNO=1                        ; Program version number
  10686. $EDNO=1                         ; Program edit number
  10687.  
  10688. comment \ most recent update:   11:04am  Wednesday, 30 May 1979
  10689.  
  10690. This program is written to demonstrate various things:
  10691.  
  10692. 1. Use of the COMND JSYS via the Columbia UUOs, with secondary
  10693.    parsing done by subroutines, which return success or failure indications
  10694.    to the main parsing sequence.  This is the recommended method for
  10695.    writing most interactive programs.
  10696.  
  10697. 2. The normal convention for "rescan" entry into a program.  If the program
  10698.    is invoked by typing "foo xxx" to the Exec, where "xxx" is a Foo command,
  10699.    the program executes that command and then halts; in other words, it
  10700.    behaves as though "foo xxx" was an Exec command.  On the other hand, if
  10701.    the program is invoked by typing "foo", the user is prompted for commands
  10702.    until the "exit" command is given.
  10703.  
  10704. 3. The $dir routine shows how to do filename stepping with the GNJFN JSYS.
  10705.  
  10706. 4. The %print UUO is demonstrated in various places.  The fact that it
  10707.    assembles into one word in line is shown to be handy; it can be used
  10708.    in "case" statements, it can be skipped over, etc.
  10709.  
  10710.  
  10711. F. da Cruz, CUCCA, May 1979
  10712. \
  10713.         search CUsym            ; Obtain macros, symbols, etc.
  10714.         %setEnv                 ; Search Monsym, Macsym, initialize things.
  10715.         extern rescan           ; Routines from CUrel.
  10716.  
  10717.         ; Symbol and flag definitions
  10718.  
  10719. %flags <xitFlg>
  10720. Examples: COMND JSYS                                                 Page 195
  10721.  
  10722.  
  10723.         ; Standard 3-word entry vector
  10724.  
  10725. entVec: jrst start              ; Start address
  10726.         jrst reEntr             ; Reentry address
  10727.         %version ($VERNO,$EDNO) ; Standard version number
  10728. evLen=.-entVec                  ; Entry vector length
  10729.  
  10730. reEntr: jrst start              ; Nothing special on reentry.
  10731.  
  10732. start:  %setUp                  ; RESET, set up stack, etc.
  10733.         call init               ; Initialize.
  10734.          jrst [ HALTF           ;  On failure, halt
  10735.                 jrst . ]        ;  and don't allow continuation.
  10736.  
  10737. ; Get here after successful initialization, or upon continuation.
  10738.  
  10739. cont:   call main               ; Do the work.
  10740.         HALTF                   ;  and stop the program.
  10741.  
  10742.         %trnOff xitFlg          ; (In case they continue
  10743.         jrst cont               ;  ...)
  10744. Examples: COMND JSYS                                                 Page 196
  10745.  
  10746.  
  10747.         subttl Initialization
  10748.  
  10749. init:   comment | Initialize the program. |
  10750.  
  10751. ; Pass rescan argument (if any) to command parser
  10752.  
  10753.         %trnOff xitFlg          ; Turn off the exit flag
  10754.         move t1, [point 7, [asciz/Foo/]] ; Name of this program.
  10755.         call rescan             ; Do rescan processing.
  10756.          %trnOn xitFlg          ; Rescan arg was found, turn on flag.
  10757.  
  10758.         retskp
  10759. Examples: COMND JSYS                                                 Page 197
  10760.  
  10761.  
  10762.         subttl  Main program - highest level command parser.
  10763.  
  10764. main:   stkVar temp             ; Allocate local temporary variable on stack.
  10765.         %skpOff xitFlg          ; Rescan entry?
  10766.          jrst repars            ;  Yes, don't set up prompt.
  10767.  
  10768. restar: %skpOff xitFlg          ; If we get here with the exit-flag on, there
  10769.          ret                    ;  was an error in the rescan line, so exit.
  10770.  
  10771. ; Come here when there were no arguments on the Exec command line.
  10772.  
  10773.         %cmIni <<Foo>>,,,gjfBlk ; Issue prompt, specify GTJFN block address.
  10774.          %jsErr <Foo internal error: .CMINI failure> ; Handle errors.
  10775.  
  10776. ; This is the reparse address.  Come here after any parse error, including
  10777. ;  deletion into a field previously parsed (this is done automatically by
  10778. ;  the %merrep and %jmerrep macros).
  10779.  
  10780. repars: %cmKey cmdTab,<command,> ; Get major command.
  10781.          %merrep restar, repars ;  Handle any parse errors.
  10782.         hrrz t2, (t2)           ; Get address of associated dispatch word
  10783.         hrrzm t2, temp          ;  (we'll need it again soon)
  10784.         load t1, %prsAd, (t2)   ;  and secondary parse routine address
  10785.         call (t1)               ;  which we call to parse the next field(s).
  10786.          %jmerrep restar, repars, restar ; Handle error return.
  10787.  
  10788. ; Get here after all fields have been successfully parsed.
  10789.  
  10790.         move t2, temp           ; Get command table word back again,
  10791.         load t1, %evlAd, (t2)   ;  and from it, the action routine address.
  10792.         call (t1)               ; Call the action routine.
  10793.          nop                    ;  (ignore failure)
  10794.         %skpOff xitFlg          ; Was it an exit command?
  10795.          ret                    ;  Yes, exit.
  10796.         jrst restar             ; No, keep going.
  10797.  
  10798. ; This is the major command table.  Note that it although it is data and
  10799. ;  not code, it is still pure storage, and can be kept with the routine
  10800. ;  that uses it.
  10801.  
  10802. cmdTab: %table
  10803.         %key <directory>, [.dir,,$dir]
  10804.         %key <echo>, [.echo,,$echo]
  10805.         %key <exit>, [.exit,,$exit]
  10806.         %key <help>, [.help,,$help]
  10807.         %key <information>, [.info,,$info]
  10808.         %tbEnd
  10809. Examples: COMND JSYS                                                 Page 198
  10810.  
  10811.  
  10812.         subttl  Secondary Parsing Routines and Action Routines.
  10813.  
  10814.  
  10815. .dir:   comment | Parse rest of "directory" command. |
  10816.  
  10817.         movx t1, CZ%NCL!.FHSLF  ; Release all non-open JFNs
  10818.         CLZFF                   ;  ...
  10819.  
  10820.         %cmNoi <of files>       ; Issue guide words.
  10821.          %pret                  ;  Fail-return on error.
  10822.  
  10823. ; Get file specification for directory listing.
  10824.  
  10825.         %cmFil <file specification, possibly wild>,,CM%SDH
  10826.          %pret                  ;  Fail-return on error.
  10827.         move q1, t2             ; Save directory JFN in q1.
  10828.         %cmCfm                  ; Get confirmation.
  10829.          %pret                  ;  Fail-return on error.
  10830.         retskp                  ; Return successfully.
  10831.  
  10832. $dir:   comment | Execute the "directory" command. |
  10833.  
  10834.         setzi p1,               ; File counter.
  10835.         move t1, q1             ; JFN of first file.
  10836.  
  10837. ; Loop to get the next file that matches the given specification
  10838. ;  and to print its name at the terminal.
  10839.  
  10840. $dLoop: aos p1                  ; Count the file.
  10841.         hrrzs t1                ; Clear out the wildcard flags,
  10842.         %print < %j%/>,<t1>     ;  and print the filename.
  10843.         move t1, q1             ; Get back the original JFN.
  10844.         GNJFN                   ; Get the Next JFN that matches.
  10845.          jrst $dDone            ;  If none, then all done.
  10846.         jrst $dLoop             ; Loop for all files.
  10847.  
  10848. ; Come here when no more files match the given specification.
  10849.  
  10850. $dDone: %print <%/ %d File>,<p1> ; Say how many files.
  10851.         caie p1, 1              ; If other than one,
  10852.          %print <s>             ;  then pluralize.
  10853.  
  10854.         retskp                  ; Return successfully.
  10855. Examples: COMND JSYS                                                 Page 199
  10856.  
  10857.  
  10858. .echo:  comment | Parse rest of "echo" command. |
  10859.  
  10860.         %cmNoi <line>           ; Issue noise word.
  10861.          %pret                  ;  Fail-return on error.
  10862.         %cmTxt <line to be echoed,> ; Get a text line.
  10863.          %pret                  ;  Fail-return on error.
  10864.         move t1, [point 7, buf] ; Get the text line into buf
  10865.         %cmGab t1               ;  from the atom buffer.
  10866.         %cmCfm                  ; Get confirmation.
  10867.          %pret                  ;  Fail-return on error,
  10868.         retskp                  ;  otherwise return successfully.
  10869.  
  10870. $echo:  comment | Execute the "echo" command. |
  10871.  
  10872.         %print <%s>,<[point 7, buf]> ; Print the text line.
  10873.         retskp
  10874. Examples: COMND JSYS                                                 Page 200
  10875.  
  10876.  
  10877. .exit:  comment | Parse the rest of the "exit" command. |
  10878.  
  10879.         %cmNoi <from Foo>       ; Issue guide words.
  10880.          %pret                  ;  Fail-return on error.
  10881.         %cmCfm                  ; Get confirmation.
  10882.          %pret                  ;  Fail-return on error,
  10883.         retskp                  ;  otherwise, return successfully.
  10884.  
  10885. $exit:  comment | Execute the "exit" command. |
  10886.  
  10887.         %trnOn xitFlg           ; Just turn on the exit flag,
  10888.         retskp                  ;  and return successfully.
  10889. Examples: COMND JSYS                                                 Page 201
  10890.  
  10891.  
  10892. .help:  comment | Parse the rest of the "help" command. |
  10893.  
  10894.         %cmNoi <about>          ; Issue noise words.
  10895.          %pret                  ;  Fail-return on error.
  10896.         %cmKey hlpTab, <command,>, help ; Get command to help with.
  10897.          %pret                  ;  Fail-return on error.
  10898.         hrrz p1, (t2)           ; Get address of help text.
  10899.         %cmCfm                  ; Get confirmation.
  10900.          %pret                  ;  Fail-return on error,
  10901.         retskp                  ;  otherwise return successfully.
  10902.  
  10903.  
  10904. $help:  comment | Execute the "help" command. |
  10905.  
  10906.         %print <%s>,<[point 7, (p1)]> ; Print the help text.
  10907.         retskp
  10908.  
  10909. hlpTab: %table                  ; Table of help commands.
  10910.         %key <directory>, $$dir
  10911.         %key <echo>, $$echo
  10912.         %key <exit>, $$exit
  10913.         %key <help>, $$help
  10914.         %key <information>, $$info
  10915.         %tbEnd
  10916.  
  10917. $$dir:  asciz |
  10918. Type "directory xxx", where "xxx" is a file specification.  If there
  10919. is a file that matches that specification, its name will be typed.
  10920. If the specification is "wild", i.e. contains "*" or "%" characters,
  10921. the names of all files that match will be typed.
  10922.  
  10923. |
  10924. $$echo: asciz |
  10925. The 'echo' command types back what you type as its argument, e.g.
  10926. "echo xxx" types "xxx" at your terminal.
  10927.  
  10928. |
  10929. $$exit: asciz |
  10930. The 'exit' command halts the program.  You can continue by
  10931. typing the Exec 'continue' command.
  10932.  
  10933. |
  10934. $$help: asciz |
  10935. The 'help' command gives information about the various Foo commands.
  10936. Type "help xxx" where 'xxx' is any Foo command.  Type "help ?" to see
  10937. what commands have help available.
  10938.  
  10939. |
  10940. $$info: asciz |
  10941. The 'information' command prints information about various things.
  10942. Type 'information ?' to see what things are available.
  10943.  
  10944. |
  10945. Examples: COMND JSYS                                                 Page 202
  10946.  
  10947.  
  10948. .info:  comment | Parse rest of "information" command. |
  10949.  
  10950.         %cmNoi <about>          ; Noise word.
  10951.          %pret                  ;  Fail-return on error.
  10952.         %cmKey <infTab>         ; Get keyword.
  10953.          %pret                  ;  Fail-return on error.
  10954.         hrrz p1, (t2)           ; Get info routine index.
  10955.         %cmCfm                  ; Get confirmation,
  10956.          %pret                  ;  Fail-return on error,
  10957.         retskp                  ;  otherwise return successfully.
  10958.  
  10959. infTab: %table                  ; Info command table.
  10960.         %key <connected-directory>, 0
  10961.         %key <date-and-time>, 1
  10962.         %key <logged-in-directory>, 2
  10963.         %tbEnd
  10964.  
  10965. $info:  comment | Execute the "information" command. |
  10966.  
  10967.         xct [   %print < You are connected to %c> ; Print the quantity
  10968.                 %print < %n>                      ;  given by the
  10969.                 %print < You are logged in as %u> ;  "case index"
  10970.                 ](p1)                             ;  in p1.
  10971.  
  10972.         retskp                  ; Return successfully
  10973. Examples: COMND JSYS                                                 Page 203
  10974.  
  10975.  
  10976.         subttl  Impure Data Section
  10977.  
  10978.         %impure                 ; Declare it impure for sharability.
  10979.  
  10980. ; GTJFN block for %cmFil.  Some of the words are filled in by COMND,
  10981. ;  so this block must be in the impure section.
  10982.  
  10983. gjfBlk: GJ%OLD!GJ%IFG!GJ%FLG!GJ%ACC!.GJALL ; Flag bits,,generation number.
  10984.         .PRIIN,,.PRIOU          ; Input,,output JFNs.
  10985.         0                       ; Default device (none).
  10986.         0                       ; Default directory (none).
  10987.         point 7, [asciz/*/]     ; Default Filename (wild).
  10988.         point 7, [asciz/*/]     ; Default filetype (wild).
  10989.         0                       ; Default protection (none).
  10990.         0                       ; Default account (none).
  10991.         0                       ; JFN to assign (none).
  10992.         0                       ; No extended block.
  10993.         block ^d10              ; Other args not used either.
  10994.  
  10995. buf:    block ^d500/5+1         ; Buffer for "echo" string.
  10996. ^L
  10997.         end <evLen,,entVec>     ; Address,,length of entry vector.
  10998.  
  10999. ; - EMACS editing modes -
  11000.  
  11001. ; local modes:
  11002. ; mode:Macro
  11003. ; comment start:;
  11004. ; comment rounding:+1
  11005. ; end:
  11006. Assembly Language Guide                                              Page 204
  11007.  
  11008.  
  11009.                                     Index
  11010.  
  11011.  
  11012.  
  11013.           %clear   152
  11014.           %cmRes   141
  11015.           %erMsg   84, 153
  11016.           %jsErr   74, 153
  11017.           %print   136
  11018.           %prSkp   137
  11019.           %setEnv   151
  11020.           %setUp   141, 151
  11021.  
  11022.           .EXE   97, 174
  11023.           .MAC   34, 172
  11024.           .PRIIN   75, 78, 79, 83, 88
  11025.           .PRIOU   75, 78, 79, 83, 88
  11026.           .REL   34, 51, 97, 172, 177
  11027.           .REQUIRE   57, 124
  11028.           .RTJST   126
  11029.           .UNV   34, 57
  11030.  
  11031.           Accumulator   3, 8, 9, 12, 15, 73, 132, 149, 159, 165, 167, 174
  11032.           Accumulators, Restoring   167
  11033.           Accumulators, Saving   11, 167
  11034.           ACVAR   134
  11035.           ADD   19, 28
  11036.           Address   4, 8, 62, 159, 174, 175
  11037.           Address Space   184
  11038.           ADJBP   25
  11039.           ADJSP   12
  11040.           AND   26, 36, 77
  11041.           ANDCA   26
  11042.           ANDCB   26
  11043.           ANDCM   26
  11044.           AOBJ   15
  11045.           AOJ   17, 28, 67
  11046.           AOS   16, 28
  11047.           Appending to a File   79, 80
  11048.           Argument   37, 63, 64, 67, 70, 73, 163, 168
  11049.           Arithmetic   19, 20, 21
  11050.           Arithmetic Expression   45
  11051.           Arithmetic Shift   23
  11052.           AROV   27
  11053.           Array   15, 37, 47
  11054.           ASCII   35, 36, 47, 70, 75, 101, 174, 177
  11055.           ASCIZ   48, 76, 79, 101
  11056.           ASH   22, 23, 27
  11057.           ASHC   23, 27
  11058.           Assembler   7, 34, 97
  11059.           Assembly Language   2, 159
  11060.           ASUBR   134
  11061.  
  11062.           BIN   83
  11063.           Binary   7, 35, 38
  11064.           Bit   4, 8, 19, 26, 40, 75, 124, 174
  11065.           BLOCK   48
  11066. Assembly Language Guide                                              Page 205
  11067.  
  11068.           BLT   10, 11
  11069.           Boolean Logic   26
  11070.           BOUT   83
  11071.           Breakpoint   179, 186
  11072.           Byte   4, 24, 48, 58, 75, 93, 174
  11073.           Byte Pointer   24, 25, 55, 75, 126, 146, 165
  11074.  
  11075.           CAI   18
  11076.           CALL   131, 165
  11077.           CALLRET   131, 166
  11078.           CAM   18
  11079.           Case Statement   32
  11080.           Character   4
  11081.           CLOSF   78, 81
  11082.           Closing a File   81
  11083.           Command Initialization   114, 140
  11084.           Comment   36, 49, 59, 61, 64, 105, 159, 160, 168
  11085.           COMND   85, 102, 136, 140, 144, 149, 154
  11086.           COMPILE   172
  11087.           Concatenation   37, 67
  11088.           Conditional Assembly   164
  11089.           Confirmation   79, 114
  11090.           Continuation   35, 37, 105
  11091.           CPU   4
  11092.           CUrel   144
  11093.           CUsym   104
  11094.           CUUOs   136
  11095.  
  11096.           Data Structure   128, 165
  11097.           DCK   28, 29
  11098.           DDT   58, 160, 172, 174
  11099.           DDT Type-in   176
  11100.           DDT Type-out   174, 182
  11101.           Debug   172
  11102.           DEC   3, 50
  11103.           Decimal   34, 36, 38, 177
  11104.           DECR   129
  11105.           DECsystem-10   33
  11106.           DECSYSTEM-20   3
  11107.           Default Argument   64, 67
  11108.           DEFINE   50, 63
  11109.           DEFSTR   128, 165
  11110.           Destination   12, 75
  11111.           Device   78, 114, 138
  11112.           DFAD   22
  11113.           DFDV   22, 29
  11114.           DFMP   22
  11115.           DFSB   22
  11116.           Difference   36
  11117.           Directory   4, 78, 114, 138
  11118.           Disk   3
  11119.           DIV   20, 29
  11120.           Divide   19, 20, 29
  11121.           DMOVE   20
  11122.           DMOVN   28
  11123.           DMUL   27
  11124.           Double Precision   20, 21, 22
  11125.           Double Word   20, 23
  11126. Assembly Language Guide                                              Page 206
  11127.  
  11128.           DPB   24
  11129.           Dummy Argument   63, 64
  11130.  
  11131.           Effective Address   8, 175
  11132.           EMACS   172
  11133.           END   50, 54, 55
  11134.           End of File   81, 82, 83, 85, 93, 96
  11135.           ENTRY   45, 51
  11136.           EQV   26
  11137.           ERCAL   73, 137
  11138.           ERJMP   73, 137
  11139.           Error Message   73, 138, 153
  11140.           Errors   71
  11141.           Excess 200   21
  11142.           EXCH   10
  11143.           Exec   3, 97, 172, 184, 185, 187
  11144.           Execute   172
  11145.           EXP   51, 54
  11146.           Exponent   21, 22, 23, 39
  11147.           Expression   10, 37, 40, 45, 60, 70, 178
  11148.           EXTERN   51
  11149.  
  11150.           FAD   21
  11151.           Fail   2, 159
  11152.           Failure Return   73, 157
  11153.           FDV   21, 29
  11154.           FDVR   29
  11155.           Field   77, 113, 126
  11156.           File   4, 75, 77, 78, 93
  11157.           File Name   78
  11158.           File Pointer   93
  11159.           File Type   78
  11160.           FIX   22, 28
  11161.           Fixed Point Arithmetic   19, 20
  11162.           FIXR   23, 28
  11163.           Flag   157, 165
  11164.           FLD   77, 126
  11165.           FLIN   92
  11166.           Floating Point   21, 23, 36, 39, 92, 114, 138, 177
  11167.           Floating Point Arithmetic   21
  11168.           Floating Point Overflow   28
  11169.           Floating Point Zero   21
  11170.           FLOUT   92
  11171.           FLTR   22, 23
  11172.           FMP   21
  11173.           Fork   97, 184
  11174.           Fortran   39
  11175.           FOV   28, 29
  11176.           Fraction   21, 39
  11177.           FSB   21
  11178.           FSC   22
  11179.  
  11180.           Generation Number   78, 79
  11181.           GetOK   144
  11182.           Global   44
  11183.           GTJFN   78, 140
  11184.           GTSTS   82
  11185.           Guide Word   112
  11186. Assembly Language Guide                                              Page 207
  11187.  
  11188.  
  11189.           Halfword   12, 36, 46, 59, 76, 165, 174
  11190.           HALTF   100
  11191.           Handle   99
  11192.           Help Message   105, 116, 144
  11193.           HRROI   76
  11194.  
  11195.           IBP   25
  11196.           IDDT   184
  11197.           IDIV   19, 29
  11198.           IDPB   25, 55
  11199.           IFx   51
  11200.           ILDB   25, 55
  11201.           IMUL   19, 28
  11202.           INCR   129
  11203.           Indefinite Repetition   69
  11204.           Indentation   160
  11205.           Index   8, 15, 37, 62, 159, 174
  11206.           Indirect   8, 29, 30, 32, 37, 62, 159, 174
  11207.           Indirect File   105, 173
  11208.           Input File   79, 112
  11209.           Input/Output   4, 81, 82, 84
  11210.           Instruction   4, 7, 165
  11211.           Instruction Modifier   9, 27
  11212.           Integer   22, 23, 38, 90, 91
  11213.           Integer Arithmetic   19, 20
  11214.           INTERN   52
  11215.           INTERNAL   36, 37, 44
  11216.           IOR   26
  11217.           IOWD   12, 53
  11218.           IPB   55
  11219.           IRP   53, 58, 69
  11220.           IRPC   54, 58, 69
  11221.  
  11222.           JAND   130
  11223.           JFCL   32, 63
  11224.           JFFO   33
  11225.           JFN   78, 99
  11226.           JFNS   79, 138
  11227.           JFOV   63
  11228.           JNAND   130
  11229.           JNOR   130
  11230.           JOR   130
  11231.           JRA   30
  11232.           JRST   31, 132
  11233.           JSA   30
  11234.           JSERR   135, 153
  11235.           JSHLT   135
  11236.           JSP   27, 30
  11237.           JSR   27, 30
  11238.           JSYS   7, 73
  11239.           JSYS Error Recovery   74
  11240.           JUMP   15
  11241.           JXm   127
  11242.  
  11243.           KA10   2, 7, 20, 21, 25
  11244.           Keyword   111, 141, 154
  11245.           KI10   2, 7, 11, 25
  11246. Assembly Language Guide                                              Page 208
  11247.  
  11248.           KL10   2, 7, 11, 25, 73
  11249.           KS10   2, 7
  11250.  
  11251.           Label   36, 43, 59, 159
  11252.           LDB   24
  11253.           Link   34, 51, 57, 124, 172
  11254.           Linked List   130
  11255.           LIT   40, 54, 55
  11256.           Literal   10, 37, 40, 54, 136, 169
  11257.           LOAD   129, 165, 172
  11258.           Load-Class Commands   172
  11259.           LOC   62
  11260.           Local   44
  11261.           Local Label   153
  11262.           Location Counter   36, 41, 62
  11263.           Logical Complement   36
  11264.           Logical Expression   18, 45
  11265.           Logical Shift   23
  11266.           Logical Testing   26
  11267.           Loop   15
  11268.           Lowercase   35
  11269.           LSH   23
  11270.           LSHC   23
  11271.  
  11272.           Macro Expansion   65
  11273.           Macro-20   2, 34, 73, 159
  11274.           Macros   35, 36, 37, 50, 59, 61, 63, 77, 124, 163
  11275.           MACSYM   77, 86, 104, 124, 149, 165
  11276.           MAKLIB   51
  11277.           Mask   26, 77, 124, 126, 127
  11278.           MASKB   127
  11279.           Memory   3, 9, 12, 62, 97
  11280.           Midas   2, 159
  11281.           MOD.   135
  11282.           Module   167
  11283.           Modulo   135
  11284.           Monitor   3, 7
  11285.           Monitor Call   2, 7, 43, 73
  11286.           MONSYM   75, 77, 149
  11287.           MOVE   9, 20
  11288.           MOVM   28
  11289.           MOVN   28
  11290.           MOVX   76, 127
  11291.           MSKSTR   128, 165
  11292.           MUL   20, 27
  11293.           Multiply   19
  11294.  
  11295.           NIN   90, 92
  11296.           NOUT   77, 91, 92, 138
  11297.           Number   111, 116, 152, 170
  11298.           Number Conversion   22, 90
  11299.  
  11300.           OCT   54
  11301.           Octal   34, 36, 38, 138, 177
  11302.           Opcode   59, 60, 62, 73, 159, 162, 174, 178
  11303.           OPDEF   55, 60, 61, 165
  11304.           OPENF   78, 80
  11305.           Opening a File   80
  11306. Assembly Language Guide                                              Page 209
  11307.  
  11308.           Operand   59, 60
  11309.           Operating System   3, 7
  11310.           Operator   60
  11311.           OPSTR   130
  11312.           OPSTRM   130
  11313.           OR   36, 77, 78
  11314.           ORCA   26
  11315.           ORCB   26
  11316.           Output File   79, 112
  11317.           Overflow   11, 12, 19, 20, 22, 23, 27, 31
  11318.  
  11319.           Page   93, 145
  11320.           Pagination of Programs   162
  11321.           Pass   34, 61, 72
  11322.           Patch   182
  11323.           PBIN   83
  11324.           PBOUT   83
  11325.           PC   8, 19, 27, 31, 32, 125, 179, 188
  11326.           PDP-10   3, 7, 33
  11327.           PDP-6   3, 7, 21, 25
  11328.           Phase   51, 72
  11329.           POINT   25, 55
  11330.           POINTR   126
  11331.           POP   11, 12, 165, 171
  11332.           POPJ   165
  11333.           POS   126
  11334.           PRGEND   55, 58
  11335.           PRINTX   56
  11336.           Process   97
  11337.           Product   36
  11338.           Program   97
  11339.           Program Control   15, 30, 42, 73, 162, 170
  11340.           Program Counter   27
  11341.           Program Version Number   152
  11342.           Prompt   88, 105, 140
  11343.           Pseudo-op   47, 60
  11344.           PSOUT   86
  11345.           PURGE   56
  11346.           PUSH   11, 12, 133, 165, 171
  11347.           PUSHJ   27, 31, 133, 165
  11348.  
  11349.           Quadruple Word   20
  11350.           Quotient   36
  11351.  
  11352.           R   166
  11353.           Radix   38, 56, 175
  11354.           RADIX50   174
  11355.           Random-access Input/Output   93
  11356.           RDTTY   85, 87, 90
  11357.           Recognition   78, 79, 105
  11358.           Reentrant   30, 170
  11359.           Register   3, 9
  11360.           RELOC   62
  11361.           Remainder   19
  11362.           REPEAT   56, 61
  11363.           Rescan   147
  11364.           RESET   99
  11365.           RET   131, 133
  11366. Assembly Language Guide                                              Page 210
  11367.  
  11368.           RETSKP   131, 133
  11369.           Return   165
  11370.           RFORK   100
  11371.           RFPTR   95
  11372.           RIN   96
  11373.           ROT   23
  11374.           Rotate   23
  11375.           ROTC   24
  11376.           Round   23
  11377.           ROUT   96
  11378.           RSKP   166
  11379.  
  11380.           Save   187
  11381.           Scale   22
  11382.           SEARCH   57, 124, 149
  11383.           Sequential Input/Output   82, 94
  11384.           SETA   26
  11385.           SETCA   26
  11386.           SETCM   26
  11387.           SETCMP   129
  11388.           SETM   26
  11389.           SETO   26
  11390.           SETONE   129
  11391.           SETZ   26
  11392.           SETZRO   129
  11393.           SFPTR   94, 95
  11394.           Sharability   170
  11395.           Shift   23, 37, 40, 126
  11396.           Sign   21, 38, 39, 91
  11397.           SIN   84, 147
  11398.           SIXBIT   36, 37, 57, 70, 138, 174, 177
  11399.           SKIP   16
  11400.           Skip Return   31, 73, 166
  11401.           Skipping Instruction   160
  11402.           SOJ   17, 28
  11403.           SOS   16, 28
  11404.           Source   12, 75
  11405.           Source/Destination Designator   75
  11406.           SOUT   85
  11407.           Stack   11, 12, 31, 132, 151, 165, 171
  11408.           Standards   159
  11409.           Statement   34, 59, 61, 159
  11410.           STCMP   101
  11411.           STKVAR   132, 171
  11412.           STOPI   58, 69, 70
  11413.           STOR   165
  11414.           String   75, 115
  11415.           String Input/Output   84, 86
  11416.           Style   159
  11417.           SUB   19, 28
  11418.           Subroutine   45, 73, 142, 165, 168
  11419.           SUBTTL   58, 164
  11420.           Sum   36
  11421.           Swap   37
  11422.           Switch   112
  11423.           Symbol   37, 42, 75, 124, 150, 170, 177
  11424.           Symbol Table   42, 44, 55, 57, 58, 61, 177
  11425.           Symbol, Created   67, 68
  11426. Assembly Language Guide                                              Page 211
  11427.  
  11428.  
  11429.           Terminal   75, 78, 87, 99
  11430.           TEST Instructions   26
  11431.           TEXTI   85
  11432.           Timesharing   3
  11433.           TITLE   58, 164, 177
  11434.           TMSG   134, 152
  11435.           Token   115
  11436.           Tops-10   34, 57, 58
  11437.           Tops-20   3, 73
  11438.           TRVAR   133, 171
  11439.           Two's Complement   19, 21, 36, 38
  11440.           TXmn   82, 127, 165
  11441.  
  11442.           Unconditional Jump   31
  11443.           UNIVERSAL   57
  11444.           UUO   7, 144, 150
  11445.  
  11446.           WID   126
  11447.           Word   4, 7, 19, 21, 38, 40, 175
  11448.  
  11449.           XCT   32
  11450.           XOR   26
  11451.           XWD   59
  11452.  
  11453.           Z   59
  11454. Assembly Language Guide                                                Page i
  11455.  
  11456.                               Table of Contents
  11457.  
  11458. 1. Introduction                                                              2
  11459.  
  11460. 1.1. Basic Concepts                                                          3
  11461.      1.1.1. Terminology                                                      3
  11462.      1.1.2. Machine Organization                                             3
  11463.      1.1.3. Instructions and Addressing Modes                                4
  11464.      1.1.4. Internal Representation of Numbers                               4
  11465.           1.1.4.1. Binary Numbers                                            4
  11466.           1.1.4.2. Two's Complement Representation                           5
  11467.           1.1.4.3. Integers                                                  5
  11468.           1.1.4.4. Floating Point Numbers                                    5
  11469.      1.1.5. Arithmetic                                                       5
  11470.           1.1.5.1. Integer Arithmetic                                        5
  11471.           1.1.5.2. Floating Point Arithmetic                                 5
  11472.      1.1.6. Logical Operations                                               5
  11473.      1.1.7. Character String Manipulation                                    5
  11474.      1.1.8. Elementary Data Structures                                       5
  11475.           1.1.8.1. Tables (Arrays) and Indexing                              5
  11476.           1.1.8.2. Stacks                                                    6
  11477.  
  11478. 2. The PDP-10/DECSYSTEM-20 Instruction Set                                   7
  11479.  
  11480. 2.1. Introduction                                                            7
  11481. 2.2. Full Word Instructions                                                  9
  11482.      2.2.1. MOVE                                                             9
  11483.      2.2.2. EXCH - Exchange                                                 10
  11484.      2.2.3. BLT - Block Transfer                                            10
  11485.      2.2.4. Programming Examples Using Fullword Instructions                10
  11486. 2.3. Stack Instructions                                                     11
  11487.      2.3.1. PUSH - Push on Stack                                            11
  11488.      2.3.2. POP - Pop Stack                                                 12
  11489.      2.3.3. ADJSP - Adjust Stack Pointer                                    12
  11490. 2.4. Halfword Instructions                                                  12
  11491.      2.4.1. HR - Halfword Right                                             13
  11492.      2.4.2. HL Halfword Left                                                14
  11493. 2.5. Arithmetic Testing                                                     15
  11494.      2.5.1. AOBJ - Add One to Both Halves and Jump                          15
  11495.      2.5.2. JUMP                                                            15
  11496.      2.5.3. SKIP                                                            16
  11497.      2.5.4. AOS - Add One and Skip                                          16
  11498.      2.5.5. SOS - Subtract One and Skip                                     16
  11499.      2.5.6. AOJ - Add One and Jump                                          17
  11500.      2.5.7. SOJ - Subtract One and Jump                                     17
  11501.      2.5.8. CAM - Compare Accumulator to Memory                             18
  11502.      2.5.9. CAI - Compare Accumulator Immediate                             18
  11503. 2.6. Fixed Point Arithmetic                                                 19
  11504.      2.6.1. ADD                                                             19
  11505.      2.6.2. SUB - Subtract                                                  19
  11506.      2.6.3. IMUL - Single-Word Multiply                                     19
  11507.      2.6.4. IDIV - Single-Word Divide                                       19
  11508.      2.6.5. MUL - Multiply                                                  20
  11509.      2.6.6. DIV - Divide                                                    20
  11510. Assembly Language Guide                                               Page ii
  11511.  
  11512. 2.7. Double Word Move Instructions (KI10 and KL10)                          20
  11513. 2.8. Double Precision Integer Arithmetic (KL10 only)                        20
  11514. 2.9. Floating Point Arithmetic                                              21
  11515. 2.10. Other Floating Point Instructions                                     22
  11516.      2.10.1. FSC - Floating Scale                                           22
  11517.      2.10.2. FIX - Convert Floating Point to Integer                        22
  11518.      2.10.3. FIXR - Fix and Round                                           23
  11519.      2.10.4. FLTR - Float and Round                                         23
  11520. 2.11. Shift Instructions                                                    23
  11521. 2.12. Byte Instructions                                                     24
  11522.      2.12.1. LDB - Load Byte                                                24
  11523.      2.12.2. DPB - Deposit Byte                                             24
  11524.      2.12.3. IBP - Increment Byte Pointer                                   25
  11525.      2.12.4. ILDB - Increment and Load Byte                                 25
  11526.      2.12.5. IDPB - Increment and Deposit Byte                              25
  11527.      2.12.6. ADJBP - Adjust Byte Pointer                                    25
  11528.      2.12.7. POINT - Construct a Byte Pointer                               25
  11529. 2.13. Logical Testing and Modification                                      26
  11530. 2.14. Boolean Logic                                                         26
  11531. 2.15. PC Format                                                             27
  11532. 2.16. Program Control                                                       30
  11533.      2.16.1. JSR - Jump to Subroutine                                       30
  11534.      2.16.2. JSP - Jump & Save PC                                           30
  11535.      2.16.3. JSA - Jump and Save Accumulator                                30
  11536.      2.16.4. JRA - Jump and Restore Accumulator                             30
  11537.      2.16.5. PUSHJ - Push on stack and Jump                                 31
  11538.      2.16.6. POPJ - Pop stack and Jump                                      31
  11539.      2.16.7. Programming Hints Using PUSHJ and POPJ                         31
  11540.      2.16.8. JRST - Jump and Restore                                        31
  11541.      2.16.9. JFCL - Jump on Flag and Clear                                  32
  11542.      2.16.10. XCT - Execute                                                 32
  11543.      2.16.11. JFFO - Jump if Find First One                                 33
  11544. 2.17. References                                                            33
  11545.  
  11546. 3. The DECSYSTEM-20 Macro Assembler                                         34
  11547.  
  11548. 3.1. Introduction                                                           34
  11549. 3.2. Elements of Macro                                                      35
  11550.      3.2.1. Special Characters                                              35
  11551.      3.2.2. Numbers                                                         38
  11552.           3.2.2.1. Integers                                                 38
  11553.           3.2.2.2. Radix                                                    38
  11554.           3.2.2.3. Floating-point Decimal Numbers                           39
  11555.           3.2.2.4. Binary Shifting                                          40
  11556.           3.2.2.5. Underscore Shifting                                      40
  11557.      3.2.3. Literals                                                        40
  11558.      3.2.4. Symbols                                                         42
  11559.           3.2.4.1. Selecting Valid Symbols                                  43
  11560.           3.2.4.2. Defining Symbols                                         43
  11561.           3.2.4.3. Symbol-table Search Order                                44
  11562.           3.2.4.4. Symbol Attributes                                        44
  11563.      3.2.5. Expressions                                                     45
  11564.           3.2.5.1. Arithmetic Expressions                                   45
  11565.           3.2.5.2. Logical Expressions                                      45
  11566.           3.2.5.3. Evaluating Expressions                                   46
  11567. Assembly Language Guide                                              Page iii
  11568.  
  11569. 3.3. Pseudo-ops                                                             47
  11570.      3.3.1. ARRAY                                                           47
  11571.      3.3.2. ASCII                                                           47
  11572.      3.3.3. ASCIZ                                                           48
  11573.      3.3.4. BLOCK                                                           48
  11574.      3.3.5. BYTE                                                            48
  11575.      3.3.6. COMMENT                                                         49
  11576.      3.3.7. DEC                                                             50
  11577.      3.3.8. DEFINE                                                          50
  11578.      3.3.9. END                                                             50
  11579.      3.3.10. ENTRY                                                          51
  11580.      3.3.11. EXP                                                            51
  11581.      3.3.12. EXTERN                                                         51
  11582.      3.3.13. IFx Group                                                      51
  11583.      3.3.14. INTERN                                                         52
  11584.      3.3.15. IOWD                                                           53
  11585.      3.3.16. IRP                                                            53
  11586.      3.3.17. IRPC                                                           54
  11587.      3.3.18. LIT                                                            54
  11588.      3.3.19. OCT                                                            54
  11589.      3.3.20. OPDEF                                                          55
  11590.      3.3.21. POINT                                                          55
  11591.      3.3.22. PRGEND                                                         55
  11592.      3.3.23. PRINTX                                                         56
  11593.      3.3.24. PURGE                                                          56
  11594.      3.3.25. RADIX                                                          56
  11595.      3.3.26. REPEAT                                                         56
  11596.      3.3.27. .REQUIRE                                                       57
  11597.      3.3.28. SEARCH                                                         57
  11598.      3.3.29. SIXBIT                                                         57
  11599.      3.3.30. STOPI                                                          58
  11600.      3.3.31. SUBTTL                                                         58
  11601.      3.3.32. TITLE                                                          58
  11602.      3.3.33. XWD                                                            59
  11603.      3.3.34. Z                                                              59
  11604. 3.4. Macro Statements and Statement Processing                              59
  11605.      3.4.1. Labels                                                          59
  11606.      3.4.2. Operators                                                       60
  11607.      3.4.3. Operands                                                        60
  11608.      3.4.4. Comments                                                        61
  11609.      3.4.5. Statement Processing                                            61
  11610.      3.4.6. Assigning Addresses                                             62
  11611.      3.4.7. Machine Instruction Mnemonics and Formats                       62
  11612.      3.4.8. Mnemonics with Implicit Accumulators                            63
  11613. 3.5. Using Macros                                                           63
  11614.      3.5.1. Defining Macros                                                 63
  11615.      3.5.2. Invoking Macros                                                 64
  11616.      3.5.3. Macro Invocation Format                                         65
  11617.      3.5.4. Quoting Characters in Macro Arguments                           66
  11618.      3.5.5. Nesting Macro Definitions                                       67
  11619.      3.5.6. Concatenating Macro Arguments                                   67
  11620.      3.5.7. Default Arguments and Created Symbols                           67
  11621.           3.5.7.1. Specifying Default Values                                68
  11622.           3.5.7.2. Created Symbols                                          68
  11623.      3.5.8. Indefinite Repetition                                           69
  11624.      3.5.9. Alternate Interpretations of Characters Passed to Macros        70
  11625. Assembly Language Guide                                               Page iv
  11626.  
  11627. 3.6. Errors and Messages                                                    71
  11628.      3.6.1. Informational Messages                                          71
  11629.      3.6.2. Single-Character Error Codes                                    72
  11630.      3.6.3. MCRxxx Messages                                                 72
  11631.  
  11632. 4. Introduction to Tops-20 Monitor Calls                                    73
  11633.  
  11634. 4.1. Introduction                                                           73
  11635. 4.2. General Information                                                    73
  11636. 4.3. Using Mnemonic Symbols                                                 75
  11637. 4.4. Source/Destination Designators                                         75
  11638. 4.5. Setting up a JSYS Invocation                                           76
  11639. 4.6. JSYS's to Open and Close Files                                         77
  11640.      4.6.1. GTJFN (JSYS 20) - Get Job File Number (short form)              78
  11641.      4.6.2. OPENF (JSYS 21) - Open a File                                   80
  11642.      4.6.3. CLOSF (JSYS 22) - Close a File.                                 81
  11643. 4.7. File i/o JSYS's                                                        81
  11644.      4.7.1. GTSTS (JSYS 24) - Get file Status                               82
  11645.      4.7.2. Sequential Byte i/o                                             82
  11646.           4.7.2.1. BIN (JSYS 50) - Byte In                                  83
  11647.           4.7.2.2. PBIN (JSYS 73) - Primary Byte In                         83
  11648.           4.7.2.3. BOUT (JSYS 51) - Byte Out                                83
  11649.           4.7.2.4. PBOUT (JSYS 74) - Primary Byte Out                       83
  11650.           4.7.2.5. Example of Byte i/o                                      84
  11651.      4.7.3. String-oriented i/o                                             84
  11652.           4.7.3.1. SIN (JSYS 52) - String In                                84
  11653.           4.7.3.2. SOUT (JSYS 53) - String Out                              85
  11654.           4.7.3.3. PSOUT (JSYS 76) - Primary String Out                     86
  11655.           4.7.3.4. Example of String I/O                                    86
  11656.           4.7.3.5. RDTTY (JSYS 523) - Read string interactively from TTY    87
  11657.           4.7.3.6. RDTTY Example                                            89
  11658.      4.7.4. Number conversion JSYS's                                        90
  11659.           4.7.4.1. NIN (JSYS 225) - Number In                               90
  11660.           4.7.4.2. NOUT (JSYS 224) - Number Out                             91
  11661.           4.7.4.3. NIN/NOUT Example                                         92
  11662.      4.7.5. Random-access i/o                                               93
  11663.           4.7.5.1. RFPTR (JSYS 43) - Read File Pointer                      95
  11664.           4.7.5.2. SFPTR (JSYS 27) - Set File Pointer                       95
  11665.           4.7.5.3. RIN (JSYS 54) - Random byte In                           96
  11666.           4.7.5.4. ROUT (JSYS 55) - Random byte Out                         96
  11667. 4.8. Fork-Handling JSYS's                                                   97
  11668.      4.8.1. What's in a Fork?                                               97
  11669.      4.8.2. The Fork Environment                                            99
  11670.      4.8.3. Basic Fork-Handling JSYS's                                      99
  11671.           4.8.3.1. RESET (JSYS 147): Reset the current fork                 99
  11672.           4.8.3.2. HALTF (JSYS 170) - Halt the current fork                100
  11673.           4.8.3.3. Examples of RESET and HALTF                             100
  11674. 4.9. Miscellaneous JSYS's                                                  100
  11675.      4.9.1. STCMP (JSYS 540) - STring CoMParison                           101
  11676.  
  11677. 5. The COMND JSYS - JSYS 544                                               102
  11678.  
  11679. 5.1. Informal Introduction                                                 102
  11680. Assembly Language Guide                                                Page v
  11681.  
  11682. 5.2. General Information                                                   104
  11683. 5.3. Bits Supplied in State Block on COMND Call                            109
  11684. 5.4. Function Descriptor Block                                             110
  11685.      5.4.1. Words .CMFNP and .CMDAT of the FDB                             111
  11686.      5.4.2. Word .CMHLP of the FDB                                         117
  11687.      5.4.3. Default Help Messages                                          118
  11688.      5.4.4. Word .CMDEF of the FDB                                         119
  11689.      5.4.5. Word .CMBRK of the FDB                                         119
  11690. 5.5. Bits Returned on COMND Call                                           120
  11691. 5.6. Macros                                                                121
  11692.      5.6.1. FLDDB.(TYP,FLGS,DATA,HLPM,DEFM,LST)                            121
  11693.      5.6.2. FLDBK.(TYP,FLGS,DATA,HLPM,DEFM,BRKADR,LST)                     122
  11694.      5.6.3. BRMSK.(INI0,INI1,INI2,INI3,ALLOW,DISALLOW)                     122
  11695.      5.6.4. FLDBK.                                                         122
  11696. 5.7. Errors                                                                123
  11697.  
  11698. 6. MACSYM System Macros                                                    124
  11699.  
  11700. 6.1. Introduction                                                          124
  11701. 6.2. Definitions                                                           124
  11702.      6.2.1. Standard Program Version                                       125
  11703.      6.2.2. Miscellaneous Constants (Symbols)                              125
  11704.      6.2.3. Control Characters (Symbols)                                   125
  11705.      6.2.4. PC Flags (Mask Symbols)                                        125
  11706.      6.2.5. Macros to Manipulate Field Masks                               126
  11707.           6.2.5.1. WID(MASK)                                               126
  11708.           6.2.5.2. POS(MASK)                                               126
  11709.           6.2.5.3. POINTR(LOC,MASK)                                        126
  11710.           6.2.5.4. FLD(VAL,MASK)                                           126
  11711.           6.2.5.5. .RTJST(VAL,MASK)                                        126
  11712.           6.2.5.6. MASKB(LBIT,RBIT)                                        127
  11713.      6.2.6. Instructions Using Field Masks (Macros)                        127
  11714.           6.2.6.1. MOVX AC,MASK                                            127
  11715.           6.2.6.2. TXmn AC,MASK                                            127
  11716.           6.2.6.3. IORX AC,MASK; ANDX AC,MASK; XORX AC,MASK                127
  11717.           6.2.6.4. JXm AC,MASK,ADDRESS                                     127
  11718.      6.2.7. Data Structure Facility (Macros)                               128
  11719.           6.2.7.1. DEFSTR and MSKSTR                                       128
  11720.      6.2.8. Subroutine Conventions (Macros/opDefs)                         131
  11721.           6.2.8.1. CALL address                                            131
  11722.           6.2.8.2. RET                                                     131
  11723.           6.2.8.3. RETSKP                                                  131
  11724.           6.2.8.4. CALLRET address                                         131
  11725.           6.2.8.5. AC Conventions                                          132
  11726.      6.2.9. Named Variable Facilities (Macros and Runtime Code)            132
  11727.           6.2.9.1. STKVAR namelist                                         132
  11728.           6.2.9.2. TRVAR namelist                                          133
  11729.           6.2.9.3. ASUBR namelist                                          134
  11730.           6.2.9.4. ACVAR namelist                                          134
  11731.      6.2.10. Miscellaneous                                                 134
  11732.           6.2.10.1. TMSG string                                            134
  11733.           6.2.10.2. JSERR                                                  135
  11734.           6.2.10.3. JSHLT                                                  135
  11735.           6.2.10.4. MOD.(DEND,DSOR)                                        135
  11736. Assembly Language Guide                                               Page vi
  11737.  
  11738. 7. Columbia Macros and Packages                                            136
  11739.  
  11740. 7.1. Utility UUO Package for Macro-20                                      136
  11741.      7.1.1. Formatted Printing Package                                     136
  11742.      7.1.2. %prPush and %prPop                                             139
  11743.      7.1.3. COMND-Jsys-Made-Easy Package                                   140
  11744.           7.1.3.1.  %cmRes                                                 141
  11745.           7.1.3.2. %cmKey (keytab, help, default, flags)                   141
  11746.           7.1.3.3. %cmgab bp                                               142
  11747.           7.1.3.4. %comnd flddb                                            142
  11748.           7.1.3.5. %cmgfg flag                                             142
  11749. 7.2. CUrel Utility Subroutines                                             144
  11750.      7.2.1. Helper                                                         144
  11751.      7.2.2. GetOK                                                          144
  11752.      7.2.3. Gfcpg                                                          145
  11753.      7.2.4. pagMgr                                                         145
  11754.      7.2.5. Subbp                                                          146
  11755.      7.2.6. Rescan                                                         147
  11756. 7.3. CUsym MACSYM Augmentation Macros                                      149
  11757.      7.3.1. Accumulator Support                                            149
  11758.      7.3.2. %DefAC                                                         150
  11759.      7.3.3. Useful Symbols                                                 150
  11760.      7.3.4. UUO Package OPDEFs and Interface Symbols                       150
  11761.      7.3.5. Setup Environment Macros                                       151
  11762.           7.3.5.1. %setEnv                                                 151
  11763.           7.3.5.2. %setUp                                                  151
  11764.      7.3.6. Storage Declaration Macros                                     151
  11765.      7.3.7. General-Purpose Macros                                         151
  11766.           7.3.7.1. %Stack                                                  151
  11767.           7.3.7.2. %Version                                                152
  11768.           7.3.7.3. %Clear                                                  152
  11769.      7.3.8. Macros Used for Common Primary I/O                             152
  11770.           7.3.8.1. %typeCR(string)                                         152
  11771.           7.3.8.2. %crType(string)                                         152
  11772.           7.3.8.3. %typNum(num,cols,rdx)                                   152
  11773.           7.3.8.4. %crlf                                                   153
  11774.           7.3.8.5. %tab                                                    153
  11775.      7.3.9. JSYS Support Macros                                            153
  11776.           7.3.9.1. %jsErr                                                  153
  11777.           7.3.9.2. %erMsg                                                  153
  11778.      7.3.10. Local Label Support Macros                                    153
  11779.           7.3.10.1. %Cat(a,b)                                              154
  11780.      7.3.11. COMND JSYS Support Macros                                     154
  11781.           7.3.11.1. %Ptr(string)                                           154
  11782.           7.3.11.2. %table and %tbEnd                                      154
  11783.           7.3.11.3. %key(name, data, flags)                                154
  11784.           7.3.11.4. %Flddb (typ, flgs, data, hlpm, defm, lst)              155
  11785.           7.3.11.5. %Handlr(p,e), %PrsAdr, %EvlAdr                         155
  11786.           7.3.11.6. %CMxxx Macros to Invoke .CMxxx COMND Functions         155
  11787.      7.3.12. Macros to Handle COMND Errors                                 156
  11788.           7.3.12.1. %pret                                                  156
  11789.           7.3.12.2. %errep errlab, replab                                  156
  11790.           7.3.12.3. %merrep errlab, replab                                 157
  11791.           7.3.12.4. Macros for Fail-Return from Parsing Routines           157
  11792.           7.3.12.5. %jerrep errlab, replab, othrlb                         157
  11793.           7.3.12.6. %jmerrep errlab, replab, othrlb                        157
  11794.      7.3.13. Flag-Handling Macros                                          157
  11795.           7.3.13.1. %Flags(aFlg,bFlg,cFlg,...)                             157
  11796. Assembly Language Guide                                              Page vii
  11797.  
  11798.           7.3.13.2. %trnOn & %trnOff                                       157
  11799.           7.3.13.3. %TrOnS & %TrOfS                                        158
  11800.           7.3.13.4. %SkpOn & %SkpOff                                       158
  11801.           7.3.13.5. %AnyOn & %AnyOff                                       158
  11802.      7.3.14. CUuos (CUCCA Utility UUOs) Interface                          158
  11803.           7.3.14.1. %print, %prSkp                                         158
  11804.  
  11805. 8. Macro-20 Programming Standards and Conventions                          159
  11806.  
  11807. 8.1. Introduction                                                          159
  11808. 8.2.  Statements                                                           159
  11809. 8.3. Comments                                                              160
  11810. 8.4. Pagination of Source Programs                                         162
  11811. 8.5. Other Assembler Functions                                             163
  11812. 8.6. Instruction Mnemonics                                                 165
  11813. 8.7. Variables and Structures                                              165
  11814. 8.8. Subroutines                                                           165
  11815. 8.9. AC Definitions                                                        167
  11816. 8.10. Subroutine Documentation                                             168
  11817. 8.11. Multi-line Literals                                                  169
  11818. 8.12. Flow of Control - Branch Conventions                                 170
  11819. 8.13. Numbers                                                              170
  11820. 8.14. Sharability                                                          170
  11821. 8.15. Living in an Imperfect World                                         171
  11822.      8.15.1. AC Mnemonics                                                  171
  11823.      8.15.2. Stack Handling                                                171
  11824.  
  11825. 9. How to Write, Assemble, and Run Programs                                172
  11826.  
  11827. 10. Interactive Debugging of Assembly Language Programs                    174
  11828.  
  11829. 10.1. Typeout Modes                                                        174
  11830.      10.1.1. Address Mode Typeout                                          175
  11831.      10.1.2. Radix Typeout                                                 175
  11832.      10.1.3. Prevailing vs Temporary Modes                                 175
  11833. 10.2. Storage Words                                                        175
  11834.      10.2.1. Related Storage Words                                         176
  11835.      10.2.2. Retyping In Modes Other than the Prevailing Mode              176
  11836. 10.3. Typing In                                                            176
  11837. 10.4. Symbols                                                              177
  11838.      10.4.1. Special DDT Symbols                                           178
  11839.      10.4.2. Arithmetic Operators                                          178
  11840.      10.4.3. Field Delimiters In Symbolic Type-ins                         178
  11841. 10.5. Breakpoints                                                          179
  11842.      10.5.1. Proceeding from a Breakpoint                                  180
  11843.      10.5.2. Single Stepping                                               180
  11844.      10.5.3. Conditional Breakpoints                                       180
  11845.      10.5.4. Starting the Program                                          181
  11846. 10.6. Searching                                                            181
  11847.      10.6.1. Zeroing Memory                                                181
  11848. 10.7. Special Characters                                                   182
  11849. 10.8. Miscellaneous DDT Commands                                           182
  11850.      10.8.1. Immediate Mode Instruction Execution                          182
  11851.      10.8.2. Execute Indirect Command File                                 182
  11852.      10.8.3. Patch                                                         182
  11853. Assembly Language Guide                                             Page viii
  11854.  
  11855. 10.9. Sample DDT Session                                                   183
  11856. 10.10. IDDT (Invisible DDT)                                                184
  11857.      10.10.1. Using IDDT                                                   184
  11858.      10.10.2. EXEC-like Features                                           185
  11859.      10.10.3. View Cell                                                    186
  11860.      10.10.4. Breakpoints                                                  186
  11861.      10.10.5. Fork Handles                                                 186
  11862.      10.10.6. Escape character                                             186
  11863.      10.10.7. RUBOUT and Type-in Editing                                   186
  11864.      10.10.8. Interface with the Exec                                      187
  11865.      10.10.9. Saving a Core Image                                          187
  11866.      10.10.10. Single Instruction Executes                                 187
  11867.      10.10.11. Search Commands                                             187
  11868.      10.10.12. Single Stepping                                             188
  11869.      10.10.13. Other Commands                                              188
  11870.  
  11871. 11. Programming Examples                                                   189
  11872.  
  11873. 11.1. Binary Search Program                                                189
  11874. 11.2. COMND Example                                                        194
  11875.  
  11876. Index                                                                      204
  11877.  
  11878.