H A L K

                    A HIGH-LEVEL ASSEMBLY LANGUAGE 
                             FOR THE KMC11

                        AN INFORMAL INTRODUCTION

Introduction

HALK is based upon the language HAL, designed and implemented by HD on
the Interdata 70 series and the ICL 7502.  Various modifications have
been made to accommodate the idiosyncracies of the KMC11.

It is assumed that the reader is familiar with the following two
documents:

           KMC11 Programmer's Manual (DEC)
           HAL' MANUAL (CS DEPT)

                                                          Gordon Brebrer
                                                          April 1978


Index Tags, Literals 2 Expressions 3 Data memory: conditions 5 Statement termination, comments, spaces 6 Assignments 7 Jumps, conditional bracketing 8 Loop bracketing, control labels 9 Data, macro calls 10 Assembler directives 11 APPENDICES A-E TAGS Five different types of tag may appear in a HALK program, as follows: (1) Hardware names, e.g. SP12, BRG, CSR1, MAR. A full list is given in Appendix A. (2) Constants. These are defined by the user, either as an explicit constant, e.g. NL=10, or by labelling a control memory location, e.g. FRED: SP1=BRG. (3) Data memory identifiers. These are defined by the user by labelling a data memory location, e.g. FRED: 0. (4) Macro identifiers. (5) Keywords, e.g. JUMP, IF, REPEAT. Only the first six characters of tags are significant. LITERALS The following forms are provided: Decimal, e.g. 0, 5, 132 (non-negative) Binary, e.g. 2-101, 2-100011 Octal, e.g. 8-5, 8-43 Hexadecimal, e.g. 16-5, 16-83, 16-FF Character, e.g. 'A', '*', ''' EXPRESSIONS (a) EXPRESSIONS FOR ASSEMBLY-TIME EVALUATION The following operators are available, in order of precedence, / (unary NOT) <<, >> (left and right shift) &, !, !! (AND, OR, exclusive OR) +, - (add and subtract) Operands must be either literals or constant tags. The following special symbols are regarded as constants: (a) . : the current location in control memory (b) @ : the current location in data memory (c) # <name>, where <name> is a data memory identifier, : the address of <name> Brackets may be used freely to alter the order of evaluation. Expressions and bracketed sub-expressions are evaluated to full 16-bit accuracy, and then truncated to 10 bits. Data values are further truncated to 8 bits. A special case of an assembly-time expression consists solely of a (so far) undefined tag. When the tag occurs as a label, the current address (control or data) is taken as the value. (b) EXPRESSIONS FOR RUN-TIME EVALUATION These are restricted to binary and unary operations supported by the KMC11 ALU. The left hand side of a binary expression must be a scratch pad memory, i.e. SP<n>. The right hand side may be a hardware name, a constant, or a data memory identifier. The syntax for each operator is as follows: <A> + <B> : addition <A> + <B> + C : addition with carry <A> - <B> - / C: subtraction with borrow <A> + C : identity plus carry (<A> is SPM) <A> : identity (<A> as for binary RH5) <A> !/ <B> : Av(7B) <A> ! <B> : Logical OR <A> & <B> : Logical AND <A> !! <B> :Exclusive OR <A> - <B> : Subtraction (2s C) <A> - <B> -1 : Subtraction (1s C) C is a hardware name tag. Note that any RHS which cannot be immediately used will be temporarily stored in the Branch register prior to evaluation of the expression. DATA MEMORY The current data memory location at run-time (as selected by the MAR) may be used by giving the tag MEMORY as an operand. If a data memory identifier is used, the MAR low-order bits are loaded with the correct address before memory is used as an operand. Note that the correct setting of the PAGE (high order bits of the MAR) is the responsibility of the user. Particular memory locations may be accessed by using the construct B(<assembly-time expre>). This has the same effect as above, with the MAR being loaded with the expression value. RUN-TIME CONDITIONS A simple condition has the form: <A> <relator> <B> with two meanings, as follows: (1) <A> is a SPM > is =, #, <, >, <, > <B> is a hardware name, constant, or data memory identifier. (2) <A> is <A'>.<bit>, where <A'> is a hardware name, constant, or data memory identifier, and <bit> is 0, 1, 4, or 7 or C (carry bit) or Z (zero bit) <relator> <B> is =0 or #0. (#0 may be omitted, if desired) The appropriate bit of <A'> is tested, using the branch register temporarily. Complex conditions may be constructed from simple conditions {using AND and OR. The condition is evaluated from left to right, as far as is necessary to make a decision. Where ANDs and ORs occur in the same condition, the condition is considered as being right parenthesesed, e.g. <c1> AND <c2> OR <c3> AND <c4> is equivalent to <c1> AND (<c2> OR (<c3> AND <c4>)). STATEMENT TERMINATION AND COMMENTS A statement is terminated by semi-colon (;), exclamation mark (!), or newline. Any text between ! and ; or newline is ignored. SPACES Spaces may be included freely, except within tags and literals. ASSIGNMENT STATEMENTS ASSIGNMENT STATEMENTS HAVE THE FORM <A>=<B> <A>, the destination, is one of the following: (i) A hardware name (ii) NODEST, the null destination (iii) MAR, the memory address register (bits 0-7) (iv) PAGE, the memory address register (bits 8,9) (v) BRGSHR,the BREG, shifted right. Where the instruction format permits, multiple assignments are possible. These are: (a) MAR = <A> =, or PAGE = <A> =, where <A> is from (i), (ii), or (v) above. (b) SP<n> = BRS = The ordering of multiple destinations is arbitrary. <B>, the source, is an expression, either assembly-time or run-time. Note that the branch register may be used temporarily is the source and destination are incompatible. If the destination(s) do not include MAR or PAGE, the assignment statement may be followed by the construct: MAR=MAR+1, which causes the MAR to be incremented after the assignment. An assignment may be made conditional by following it with: IF <condition>. JUMP STATEMENTS Jump statements have the form JUMP <expression>. If <expression> is to be computed at run-time, it may be preceded by the construct, <page>:, where <page> is PAGE0, PAGE1, PAGE2, or PAGE3. The page bits are set correctly for addresses known at assembly time. Note that <expression> yield a control memory address. A jump may be made conditional by following it with: IF <condition>. CONDITIONAL BRACKETING STATEMENTS Form: IF <condition> <sequence of statements> ELSE optional <alternative sequence> FINISH Instructions are dumped to ensure correct conditional execution at run-time. The construct ELSE IF is permitted as an abbreviation in nested conditions, with the additional FINISH omitted. LOOP BRACKETING STATEMENTS Forms: CYCLE WHILE <condition> <sequence> or <sequence> REPEAT REPEAT Instructions are dumped to execute a loop (conditional in the case of WHILE). Repetition may be made conditional by following REPEAT by IF <condition> CONTROL LABELS Any of the above four types of statement may be labelled by preceding them with <tag>:. The tag should have any other defined meaning. Multiple labels are permitted. The label tag created has type constant, and its value is that of the current control memory location. DATA STATEMENTS A data statement consists of a list of (defined) assembly-time expressions separated by commas. An expression may be optionally followed, by a second expression in parentheses, which is a repeat count. Data statements may be labelled by preceding them with <tag>:. The label tag created has type data memory identifier. MACRO CALL STATEMENTS A macro call statement consists of a macro identifier followed by a list of arguments, which are substituted for the dummy arguments in the macro expansion. If the characters space, comma, semi-colon, or the sequence 'IF', are to be included in an argument, they must be placed in square brackets, which are removed on substitution. Recursive, and nested, calls are permitted. A macro call may be made conditional by following it with IF <condition. Any labels on a macro call statement are transferred to the next code, or data generating statement. ASSEMBLER DIRECTIVES Assembler directives consists of $ followed by a keyword tag and possibly parameters. (1) TAG DEFINITION Form: $DEF <def1>, <def2>, ..., where <defn> is <tag1> = <tag2>. <tag1> must not have been previously defined <tag2> must have been previously defined. <tag1> is given the type and value of <tag2>. Alternatively, <tag2> may be a (defined) assembly-time expression, in which case <tag1> gets type constant. (2) LOCATION COUNTER SPECIFICATION (a) Control. Form: $CTRL <assembly-time expr> The current control memory location at assembly (.) is set to the value of the expression. (b) Data. Form: $DATA <assembly-time expr> The current data memory location at assembly (@) is set to the value of the expression. (3) LISTING CONTROL Form: $LIST <assembly-time expr> The value of the expresion should lie between 0 and 4 inclusive, with the following meanings: 0: List only error reports 1: 0, and list statements 2: 1, and list macro expansions 3: 2, and list all code and data dumped 4: 3, and list failed conditional assembly lines. Option 3 is the default. (4) CONDITIONAL ASSEMBLY STATEMENTS Form: $IF <tag1><relator><tag2> <sequence of statements> $ELSE optional <alternative sequence> $FINISH <tag1> and <tag2> should either be tags, or assembly-time expressions, which are treated as constant tags. <relator> is either =, meaning type and value of both <tag1> and <tag2> are the same, or #, meaning the converse. If the condition is true, the following sequence of statements is assembled. If the condition is false and an alternative is given, it is assembled. Conditional assembly statements may not be nested. (5) MACRO DEFINITIONS A macro defintion is introduced by a statement of the form: $MACRO <macro identifier tag> <dummy arg list> where <dummy arg list> is a list of tags separated by commas. These tags can be arbitrary. The macro text then follows, terminated by a statement of the form: $END. When the macro is called, any occurrences of the dummy argument tags in the macro text are replaced by the actual argument. The macro text must not include macro definition. PROGRAM TERMINATION No special terminating statement is used. An EOT character in the source file terminates assembly. The EOT should not occur within macro text, or within a skipped conditional assembly sequence. APPENDIX A - PRE-DEFINED TAGS (a) Hardware SP0,SP1,...,SP15 :Scratchpad memories. BRG : Branch register. MEMORY : Memory Location addressed by MAR. CSR0,CSR1,...,CSR7 : Control and status regsters. ADR0,ADR1,...,ADR7 : NPR address and data registers. NPR : NPR control register. MISC : uPMISC control register USR0,USR1,...,USR7 : User-defined external registers. C : Carry bit (valid only in conditions and expressions). Z; Zero bit (valid only in condition) MAR : Memory address register bits 0-7 (write-only) PAGE : Memory address register bits 8,9 (write-only) NODEST : Null destination (write-only) BRGSHR : BRG shifted right (write-only) (b) Data memory identifier B : Byte at given memory address (c) Keywords PAGE0, PAGE1, PAGE2, PAGE3, JUMP, IF, ELSE, FINISH, CYCLE, WHILE, REPEAT, CTRL, DATA, DEF, MACRO, LIST, END, AND, OR. APPENDIX B - IMPLEMENTATION The HALK assembler is implemented on a PDP-11/40, running under the DEIMOS operating system. Command form: KMC KPRIMS, <src>/<obj>,<list> where <src> is the source file <obj> is the object file (see appendix D) <list> is the listing file. The input file KPRIMS is necessary during the development stage of the assembler. An illustration of the listing file produced from a demonstration program is included as appendix E. The assembler is one-pass - forward references are filled in as they are resolved, the new code or data dumped being marked with an asterisk, in the listing. Data memory locations used are marked by @@ in the listing. APPENDIX C - ERROR REPORTS Error reports have the form: *** ERROR: <message> [<integer>] <message> outlines the general area of the error, and <integer> gives more specific information, as indicated below. LIMIT EXCEEDED (due to variable assembler restriction) [1] Too many tags (>256) [2] Too many labels on statement (>15) [3] Too many forward references (>256) [4] IFs and CYCLEs nested to deeply (>10) [5] Macro has too many dummy arguments (>6) [6] Macro calls nested to deeply (>5) [7] Too much macro text (>8192 bytes) [8] Condition too complex (>30 instructions). INVALID ASS EXPR (invalid assembly-time expression) [1] Invalid operand INVALID RUN EXPR (invalid run-time expression) [1] Invalid right hand side [2] Extra operand should be C (carry) INVALID COND (invalid run-time condition) [1] Invalid relator [2] Bit test not =0 or #0 [3] Invalid left hand side [4] Invalid right hand side INVALID ASSIGN (invalid assignment) [1] Destination not followed by '=' [2] MAR already assigned [3] Multiple assignment invalid [4] Destination invalid [5] MAR= MAR+1 invalid INVALID JUMP [1] Specified page inconsistent with address [2] Page specifier not followed by : BAD TERMINATION (legal construct not terminated correctly) [1] No '!', ';', or NL at end of statement [2] No ')' after data value repeat count [3] No ')' after assembly-time subexpression [4] No matching ']' in macro actual parameter NESTING [1] Macro definition not terminated by $END [2] IF does not precede ELSE or FINISH statement [3] WHILE or CYCLE does not preced REPEAT [4] Missing FINISH [5] Missing REPEAT DIRECTIVE [1] Invalid tag following $ [2] $DEF lhs already defined, or not followed by = [3] $DEF rhs not defined [4] $MACRO identifier already used [5] Nested macro definitions not permitted [6] $LIST value invalid [7] Nested $IFs not permitted [8] Comparitor in $IF must be = or # [9] $IF does not precede $ELSE or $FINISH MACRO [1] Actual argument not set. APPENDIX D - OBJECT FILE FORMAT Format has been defined, but is not important until loader available and tested. APPENDIX E - KMC DEMONSTRATION LISTING