CHR$ Assembler This is a more capable assembler than the BBC BASIC assembler with a less capable BASIC tacked on. Many statements and commands are similar or the same as in BBC BASIC. Similarities and differences with BBC BASIC: - All Statements/commands/functions/keywords must be specified in upper case. Unlike the BBC Basic assembler, mnemonics must also be in upper case. Like BBC BASIC, statements/commands/functions/keywords can be abbreviated with a full stop provided the letters that are specified are unique. Mnemonics and pseudomnemonics can not be abbreviated. - Source is tokenised but not compatible with BBC BASIC tokenising as the assembly mnemonics are also tokenised. Like BBC BASIC, *SPOOL can be used to convert tokenised programs to ASCII and *EXEC can be used to tokenise ASCII text (Hint: include AUTO as the first line in the file). - Two pass assembly takes place automatically without any need to code a loop. Each line in the program is normally executed twice but a listing is only generated on the second pass and output is only stored on the second pass. However lines which begin with a colon (:) are only executed on the second pass. The pseudovariable PASS is set to 1 on the first pass and 2 on the second pass. - The EXEC statement can be used to process files on disk (or other filing system) as if they were part of the current program. When an EXEC statement is encountered, the file specified is opened and processed until end of file. Then control is returned to the point following the EXEC statement. EXEC files can be nested to a depth of 10 (provided the cumulative length of the filenames does not exceed 100 characters). EXEC does not clear variables or reset the environment in the way that RUN (or CHAIN under BBC BASIC) does. EXEC can also be entered at the command prompt. A fast filesystem is helpful. - The RUN command also substitutes for CHAIN when a filename is also specified. A line number can also be specified to start execution from. - LIST can list a tokenised assembly file without loading it into memory if given a filename as argument. A fast filesystem is also helpful here. - The VERIFY command can be used to verify that the program in memory corresponds with the file specified on disk (or other filesystem). - Only one statement, command or assembler mnemonic is allowed per line. - A NAME statement on the first line of the program allows it to be SAVEd, VERIFYed etc without having to specify the filename, avoiding accidentally overwriting the wrong file when making changes to several different ones. - Variables are either 16 bit integers or strings. There are no arrays. In addition, 26 resident 32 bit integer variables (A-Z) correspond directly with BBC Basics resident integer variables (A%-Z%) allowing values to be passed between the two languages. There are no floating point variables. - Mathematical operations are very similar with the following exceptions: - There is no support for floating point operations. Integer operations are done in 32 bits. Strings can be up to 255 characters long. However, strings cannot be lengthened if anything has been allocated after them so make them as big as they will ever need to be the first time they are used. - In addition to round brackets (), square brackets [] and curly brackets {} are also allowed to group parts of a mathematical expression. - Multiplication of strings by integers is allowed, giving the effect of the BBC Basic function STRING$. For example sixts$ = "T" * 6. This can also be used to emulate the SPC keyword of PRINT which is not provided. For example, PRINT " " * 8; "Hello World". - Binary numbers may be entered if prefixed with a % sign. For example, PRINT %1101. - Numeric quantities can be converted to a binary string using the %$ operator. - The standard ?, ! and $ indirection are supported. In addition, # is available to provide access to 16 bit quantites. - The / operator performs integer division as per BBC Basics DIV operator. - The ^ operator is implemented by performing successive multiplication. - The BASE pseudovariable can be used to cause numeric output to be presented in any reasonable radix. Note: PRINT BASE always gives 10... - The FIELD pseudovariable is used rather than @% to set the numeric field width. - The BEGIN@ statement is used instead of P% to indicate where to begin assembly. For example BEGIN@ &D00. - The STORE statement is used to tell the assembler where to place the assembled code. It can go to main memory (Eg: STORE@ &C00) or to a sideways RAM bank (Eg: STORE@ &9000 ROM 4) or to a file (Eg: STORE IN "Exefile") - There is no equivelant of the [ directive. Assembly mode is automatically entered on encountering any valid assembler mnemonic or label assignment (Label assignments are as per the BBC Basic assembler - a dot as the first item on the line followed by the name of the variable). - Assembly mode is exited on encountering the FIN pseudo-mnemonic rather than ]. - Only \ is allowed as a comment introducer. In the BBC Basic assembler, anything after the operand was ignored allowing use of various other characters to introduce comments, in particular the semicolon ;. - OPT is a program statement rather than a pseudo-mnemonic so it should be executed before the first valid mnemonic. - Some errors can be treated as warnings which do not cause assembly to stop, allowing several problems to be located per assembly run. Use OPT WARN ON to activate this feature. - There are two forms of IF statement: IF is similar to the IF in BBC BASIC except that ELSE is not allowed. The second form is: IF THEN ... ELSE ... ENDIF - Various different types of loops are possible. All start with LOOP and end with ENDLOOP. For-next type loop: LOOP FOR = TO [STEP ] ... ENDLOOP Repeat-until type loop: LOOP ... ENDLOOP IF While-endwhile type loop: LOOP IF ... ENDLOOP Other variations are possible. For example: LOOP FOR = TO [STEP ] IF ... ENDLOOP IF Infinite loop: LOOP ... ENDLOOP - The assembler uses zero page locations &45 to &8F for workspace. Locations &70 to &8F which BBC BASIC normally reserves for users are not available. &00 to &44, normally used by BBC BASIC, are not used by the assembler. - The editing environment is slightly different and more comprehensive than that provided with the BBC Basic assembler. Line numbers always go in steps of two. To insert a line between lines 8 and 10, call it line 9. As soon as it is entered it becomes line 10 and all the other lines are effectively moved up 2. To enter a block of lines between lines 14 and 16, enter line 15 followed by 17, 19 etc or simply type AUTO 15. - DELETE operates similarly to DELETE under BBC Basic except that it is much faster and like the other editing commands which operate on ranges of line numbers, the same syntax as the LIST command can be used. So, for example DELETE ,120 will delete from the beginning of the program to line 120 and DELETE 4000, will delete from line 4000 to the end of the program. - The MOVE command can be used to move one or more lines from one location to another. For example to move lines 50 to 60 to the location between lines 10 and 12, enter MOVE 50,60 TO 11. To move a block consisting of line 400 to the end of the program to between lines 10 and 12, enter MOVE 400, TO 11. To move the block consisting of the beginning of the program up to line 350 to between lines 842 and 844, enter MOVE ,350 TO 843. - The COPY command performs a similar function to the MOVE command except that the original lines are left in place rather then being deleted. - The FIND command (which must be abbreviated to F. or FI. due to a conflict with the FIN pseudonemonic) can be used to locate strings within the program. A single wildcard character can be specified using |@ and the end of line can be specified using |M. If either of these constructions are used, the string to be found should be enclosed in single quotes '. If specified, |M must be the last item inside the quotes. For example, FIND '55|M' will list all program lines ending in 55. Lines containing 55 with more text afterwards will not be listed. - The CHANGE command can be used to change all occurrances of one string into another string. The format is CHANGE , . must be enclosed in single quotes ' but this is optional for . All occurrances changed are listed on the screen. FIND can be used as a preview to see what would be changed by a CHANGE command. - The EDIT command should operate as per BASIC IV but has not been tested. - The MERGE command can be used to merge a program on disk with the program in memory at a given line number. Usage is MERGE [,] - The following constructs were planned but were never completed: - Macros and user defined functions - READ / DATA / RESTORE - INPUT - GOTO or equivelant. - FIX (recover from "Bad program" situations.) Assembler mnemonics supported: PHP CLC PLP SEC PHA CLI PLA SEI DEY TYA TAY CLV INY CLD INX SED ORA AND EOR ADC STA LDA CMP SBC TXA TXS TAX TSX DEX PHX NOP PLX BPL BMI BVC BVS BCC BCS BNE BEQ ASL ROL LSR ROR INA DEA PHY PLY BRK JSR RTI RTS STX LDX DEC INC TSB TRB CPY CPX STY LDY BBS BBR RMB SMB BIT STZ JMP BRA Assembler pseudomnemonics: EQB EQW EQS EQD FIN Commands (valid only at the command prompt or in an EXEC file started from the command prompt): AUTO [] [, ] CHANGE , COPY TO DELETE | EDIT FIND (use F. or FI.) LIST [] [] LOAD LABEL MERGE , MOVE TO NEW OLD VERIFY Statements (valid in programs or at command prompt): BEGIN@ CALL CLEAR CLOSE# CLS EXEC ELSE END ENDIF ENDLOOP [IF ] IF ( | THEN) LOOP [FOR = TO [STEP ]] [IF ] MODE NAME OPT [LIST ON | OFF] [WARN ON | OFF] [TAB(, )] OSCLI PRINT PUT# RUN [] [] SAVE STORE ( IN ) | ( @ [ROM ] ) SOUND , , , THEN VDU [, ] [; ] Functions: ABS AND ASC CHR$ EOR EVAL GET GET# GET$ LEN MID$( , , ) MOD NOT OPENIN OPENOUT OPENUP OR RESERVE STR$ USR Pseudovariables: BASE ERR ERRL ERR$ FIELD LOMEM HIMEM PAGE PASS TIME TIME$ TOP WIDTH Keywords: FILE FOR IN OFF ON OUT ROM STEP TAB( TO UP WARN