Home
Assembler Manual THE COMMODORE PET ASSEMBLER
Contents
1. 6C do not subtract one from the address of the operand Equal is the EQUATE directive and is used to reserve memory locations reset the program counter or assign a value to a symbol HERE 1 RESERVE ONE BYTE WHERE 2 RESERVE TWO BYTES 200 SET PROGRAM COUNTER NB 8 ASSIGN VALUE MB NB 101 ASSIGN VALUE The directive is very powerful and can be used for a wide variety of purposes Asterisk directive is used to change the program counter To create an object code programthat starts assembly at any address greater than zero the directive must be used For example 200 starts assembling at address 200 Expressions must not contain forward references or they will be flagged as an error For example 2 C D E F would be legal if C D E and F are all defined but would be illegal if any of the variables were defined later on in the program Note also that expressions are evaluated in strict left to right order PAGE is used to cause an immediate jump to the top of page on the output listing and may also be used to generate or reset the title Seite 9 Assembler Manual printed at the top of the output listing PAGE THIS IS A TITLE PAGE PAGE NEW TITLE If a title is defined it will be printed at the top of each page unti it is redefined or cleared A title may be cleared with PAGE aa SKIP is used to generate blank lines in a listing The directive wil
2. not appear but its position may a found in a listing The directive is treated as a valid input list and the list number printed on the left side of the listing will jump ny two when the next line is printed SKIP 2 SKIP TWO BLANK LINES SKIP 3 2 1 SKIP FIVE LINES SKIP SKIP ONE LINE OPT is the most powerful directive and is used to control the generation of output fields listings and expansion of ASCII stri BYTE directives The options available are ERRORS NOERRORS L NOLIST GENERATE NOGENERATE SYM and NOSYM OPT ERRORS LIST GENERATE OPT NOE NOL NOG n a MR Also valid is OPT LIST ERR Default Settings are OPT LIST ERR NOGEN Here are descriptions for each of the options ERRORS NOERRORS Used to control creation of a separate error file The error file contains the source line in error and the error message This facility is normally of greatest use to time sharing users who have limited eee capacity The error file may be turned on and examined until all errors have been corrected This listing file may then be examined Another possibility is to run with OPT ERROR NOLI ST until all errors have been corrected and then make one more run with OPT NOERRORS LIST LIST NOLIST Used to control the generation of the listing file which source input errors warnings code generation symbol t instruction count if enabled GENERATE NOGENERATE Used to control printing of ASCII strings i
3. FIND THE COMMAND CD12 DO 19 CC CMP CMD X CD15 FO 11 BEQ CALL10 CD17 CA DEX CD18 10 F8 BPL FINDC CD1A A CD1A NOTCMD Seite 18 Assembler Manual 00203 CDIA Ad A6 LDA BUFPT RESTORE REGS 00204 CDIC A6 A7 LDX BUFPT 1 00205 CDIE C9 3A CMP COMPLETE CHRGOT 00206 CD20 B0 03 BCS STRTS 00207 CD22 4C 80 00 MP CHRGOT 7 00208 CD25 4C 8A 00 STRRTS MP CHRGOT 17 TO THE END OF CHRGOT 00209 CD28 00210 CD28 CALL10 00211 CD28 86 A9 STX CNTDN SAVE NDEX 00212 CD2A 8D 7A CC STA FLAG SAVE THE COMMAND FOR LATER 00213 CD2D 20 A3 CE LSR RDFILE GET FILENAME AND LENGTH 00214 CD30 A6 A5 LDX CNTDN RESTORE NDEX 00215 CD32 A9 27 LDA lt FILE SET FILENAME ADDRESS APPENDIX IV EXPLANATION OF ERROR MESSAGES Error messages are given in the program statements in error The following Is a which might be produced during assembly A MODE NOT ALLOWED ompanying the error messages RQ a w A TEN Following the legal opcode and one or more spaces is the letter A followed by one or more spaces The assembler is trying to use the accumulator A accumulator mode as the operand However the opcode in the statement is one which does not allow reference to the accumulator Check for a statement labelled A an illegal statement which this statement is referencing If you were trying to reference the accumulator look up the valid operands for the opcode used A X Y S P RESERVED A label on a statement is one of the
4. a Loader 6 1 Loading the Loader Program To load the Loader program type SYS 44421 6 2 Using the Loader Program When activated the loader prints a copyright notice and prompts the user for a load offset The offset is used to place object code into an address range other than the one that it was assembled into This allows the user to assemble for an area where there is no RAM and load into a RAM area The object can then be programmed into EPROM etc The offset is a two byte hexadecimal address that is added to the program addresses If the program address plus the offset is greater than FFFF the address wraps around through 0000 The following examples show how offset works Program Address Offset Address of Object Code 0400 0000 0400 3000 0000 3000 0400 2000 2400 9000 9000 2000 E000 4000 2000 After the offset is entered the loader will prompt the user for the object filename to be loaded The loader will then initialize the drive search for the file and start the load As the data is laoded the eee will print the input data to the CRT This is for user feedback only When the load is completed the loader prints the message END OF LOAD and returns to BASIC There are three errors that can occur during a load each is self documenting BAD RECORD COUNT Seite 16 Assembler Manual NON RAM LOAD CHECKSUM ERROR Errors are considered fatal the load is terminated the object file is closed and c
5. as a comment use of a semicolon tabs the comment out to the next tab position PC NEGATIVE RESET 0 An assembled programis loaded into core in the range of position 0 to 64K 65535 This is the extent of the machine A maximum of two bytes can be used to define an address Because there is no such thing as negative memory an attempt to reference a negative position will cause this error and the program counter or pointer to the current memory Seite 22 Assembler Manual location to be reset to zero When this error occurs the assembler continues assembling the code with the new value of the program counter This could cause multiple bytes to be assembled into the same locations Therefore care should be taken to keep the program counter within the proper limits RAN OFF END OF CARD This error message will occur if the assembler is looking for a needed field and runs off the end of the card or line image before the field is found The following should be checked for a valid opcode field without an operand field on the same card an opcode that was thought to take an implied operand which in fact needed an operand an ASCI string that is missing the closing quote make sure any embedded quotes are doubled to have a quote at the end of the string there must be three quotes two for the embedded quote and one to close off the string a comma at the end of the operand field indicates there are more operands to come if th
6. begin w the error message is printed Check for an unlabelled statement with Ai an operand field that does not start with a special character Also check for an illegal label in the instruction LABEL TOO LONG Al ee are limited to six characters in length When par stig the assembler looks for one of the separating characters usually a blank to find the end of a label or string If other than one of these separators is used the error message will be printed providing that the illegal separator causes the symbol to extend beyond six characters in length Check for no spacing between labels and opcodes Also check for a comment card with a long first word that doesn t begin with a semicolon In this case the assembler is trying to interpret part of the comment as a label NON ALPHANUMERI C Labels are made up of one to six alphanumeric digits The label field must be separated from the opcode field by one or more blanks If a special character or other separator is between the label and the opcode this error message might be printed Each of the 56 valid opcodes are made up of three alphabetic characters They must be separated from the operand field if one is necessary by one or more blanks If the opcode ends with a special character such as a comma this error message will be printed In the case of a lone label or an opcode that needs no operand they can be followed directly by a semicolon to denote the rest of the card
7. d x are the ASCII characters zero through F each representing a hexadecimal digit 2 The semicolon is a record mark indicating the start of a record 3 nl1no The number of bytes of data in this record in hexadecimal Each pair of hexadecimal characters d1d0 represents a single byte 4 a3a2ala0 The hexadecimal starting address for the record The a3 represents address bits 15 through 12 etc The 8 bits Seite 11 Assembler Manual represented by dld0 1 is stored in address a3a2ala0 dld0 2 is stored in a3a2ala0 1 etc 5 d1d0 Two hexadecimal digits representing an 8 bit byte of data dl high order 4 binary bits and dO low order 4 bits A maximum of 18 hex or 24 decimal bytes of data per record is permitted 6 x3x2x1x0 Record check sum This is the hexadecimal sum of al characters in the record including the nln0 and a3a2ala0 but excluding the record mark and the check sum of characters To generate the check sum each byte of data represented y two ASCII characters is treated as 8 binary bits The binary sum of these 8 bit bytes is truncated to 16 ntar bits 4 hexadecimal digits and is then represented in the record as four ASCII characters x3x2x1x0 The format for the last record in a file is as follows 00 c3c2c1c0 x3x2x1x0 l1 00 Zero bytes of data are in this record The zeros identify this as the final record in a file 2 c3c2c1c0 This represent i S e tot ae number of records in hexadecimal
8. equate the assembler never enters it in the symbol table as a defined symbol When pass two tries to interpret the operand field the symbol is in there is no corresponding value for the symbol and the field cannot be interpreted Therefore the error message is printed with no value for the operand This error will also occur if a reserved symbol A X Y S or P is used as a label and referred to elsewhere in the program On the statement that references the reserved symbol the assembler sees it as a symbol that has not been defined Check for use of reserved symbols misspelled labels or missing labels to correct this error Note When the assembler finds an expression whether it is in an OPERAND field or on the right of an equals sign it tries to evaluate the expression If there is a symbol within the expression that hasn t been defined yet the assembler will flag it as a forward reference and wait to evaluate it in the second pass If the expression is on the Seite 23 right side of an equa will be flagged as such field of a valid OPCODE the first pass will set aside two bytes f value of the expression and flag it as a forward reference second pass fills in the value of the epee a expression is one byte long i e 256 t This is because the forward reference to page zero memory wastes one byte of During the first pass longer than required Sign Assembler Manual the forward reference is a Severe err or and if the expre
9. five reserved names A X Y S and P They have special men to the assembler and therefore cannot be used as labels Use of one of these names will cause this error message to be printed No code will be generated for the statement The labe does not get defined and will appear in the symbol table as an undefined variable Reference to such a label elsewhere in the program ane a error messages to be printed as if the label were never eclare BRANCH OUT OF RANGE of the branch instructions excluding the two jumps are assembled into two bytes of code One byte is for the opcode and the other for the address to branch to The branch is taken relative to the address of the beginning of the next instruction If the value of the byte is 0 127 the branch is forward if the value is 128 255 the branch is backward A negative branch is in two s complement form Therefore a branch instruction can only branch forward 127 or backward 128 bytes relative to the beginning of the next instruction If an attempt is made to branch further than these limits this error message will b printed To correct restucture the program CAN T EVAL EXPRESSION e In evaluating an expression the assembler found a character it couldn t interpret as being part of a valid expression This can happen if the field following an opcode contains special characters not valid within Steen i e parentheses Check the operand field and make sure only valid special c
10. in fi th this NOT including the last record 3 x3x2x1x0 Check sum for this record 4 0 CREATING AND EDITING A SOURCE FILE The editor is used to enter and modify source files for the assembler The editor retains all of the features of the BASIC screen editor and allows AUTOmatic line numbering FIND CHANGE DELETE within a range and reNUMBER Other commands include COLD GET PUT BREAK KILL and eee All of the commands are detailed in the summary at the end of this section The editor commands operate in a similar fashion to the commands already existing in the computer s BASIC For practice we suggest that you try to create short example files using the editor commands The data files on which the assembler operates are made up of CBM ASCI characters with each line terminated by a carriage return The only restriction on data lines is in naming Due to the method in which the assembler parses spaces are not allowed in filenames The files are Sequential and must be terminated by a zero byte 00 When listing a directory these files will show as file type SEQ Each file s format is sequential with a terminating zero byte 00 4 1 Loading the Editor Program The editor must be loaded with the BASIC SYS command SYS 59648 After typing the SYS command the editor has been loaded At this point type a NEW command to clear the text pointers You are now ready to edit or enter assembler source files 4 2 Using the Editor Program W
11. three output files genereated by the assembler Each file is optional and can be created through the use of the OPT assembler directive The listing file contains the programlist with errors and the symbol table The error file contains all error lines and errors as included in the listing file The interface file contains the object code for the loader Listing File The listing file will be produced unless the NOLIST option is used on the OPT assembler directive This file is make up of two sections Program and Error List and Symbol Table o Program and Error List This listings will always be produced unless the NOLIST option is selected It contains the source statement of the program along with the assembled code Errors and warnings appear after erroneous statements An explanation of error codes is presented in Appendix VI A count of the errors and warnings found during the assembly is presented at the end of the program o Symbol Table The symbol table will always be produced unless the NOSYM option is eh It contains a list of all symbols used in the program and their addresses Interface File This file does not contain true object code but data which can be loaded and converted to machine code by the loader The format for the oe and all succeeding records except for the last record is as ol lows nln0 a3a2ala0 dld0 1 d1ld0 2 d1d0 23 x3x2x1x0 Where the following statements apply 1 All characters n a
12. A 12 The label is L2 the opcode is LDA and the operand is 12 At least one blank must separate the three parts fields of the instruction Additional blanks may be inserted by the programmer for ease of reading Instructions for the 6500 series processors have at most one operand and may have none In these cases the e to be performed is totally specified by the opcode as in CLC Clear the Carry Bit Programming in Assembly Language requires learning the instruction set opcodes addressing conventions for referencing data the data structures within the processor as well as the structure of Assembly Language programs The user will be aided in this by reading and studying the 6500 series hardware and programmi ng manuals supplied with this development package 1 0 INSTRUCTION FORMAT CONVENTI ONS Assembler instructions for the Commodore PET Assembler are of two basic types according to function o Machine instructions and o Assembler directives Machine instructions correspond to the 56 operations implemented on the 6500 series processors The instruction format is label opcode operand comments Fields are bracketed to indicate that they are optional Labels and comments are always optional and many opcodes such as RTS Return from Subroutine do not require operands A line may also contain only a label or only a comment A typical instruction showing all four fields is LOOP LDA BETA X FETCH BETA INDEXED BY X A fiel
13. AT nl n2 nl n2 Range parameters of the same format as LIST Optional Note This command has the same controls as FIND For example press Space bar to halt printing and press it again to restart printing Press the RUN STOP key to terminate the listing GET Command This command is used to load assembler source text files into the editor from disk It can also be used to append to files already in memory GET filename nl n2 3 nl Begins inputting source at this line in the file currently in memory Optional n2 Device number default is 8 Optional n3 Secondary address default is 8 Optional Note GET starts numbering lines at 1000 and incrementing the line numbers by 10 If nl is greater than any line number in memory the file being loaded is appended to the end of the current file KI LL Command t the editor This command causes the editor to disengage To art 59648 res type the same command used to start the editor SYS LIST Command The editor LIST command works in the same manner as the LIST command in BASIC LIST n1 n2 where nl n2 specifies a range of lines Valid parameters also include nl which will list all lines from nil to the end and n2 which will list all lines fromthe beginning up to and including n2 ReNUMBER Lines Seite 14 Assembler Manual The NUMBER command allows the user to renumber all or part of the file in memory NUMBER n1 n2 n3 nl Old start line numb
14. Assembler Manual THE COMMODORE PET ASSEMBLER DEVELOPMENT SYSTEM Copyright 1979 Commodore Business Machi nes Professional Comput er Division 1200 Wilson Drive West Chester PA 19380 COPYRI GHT This software product is copyrighted and all rights reserved The distribution and sale of this ee are intended for the use of the original purchaser only Lawful users of this program are hereby licensed a to read the program fromits medium into memory of a computer solely for the purpose of executing the program Duplicating se distributing this product is a violation CET selling or otherwi 0 This manual is copyright and all rights are reserved This document may not in whole or part be copied photocopied ele eee translated or reduced to any electronic medium or machine readable form a prior consent in writing from Commodore Business Machines BM PREFACE The Commodore PET ASSEMBLER DEVELOPMENT SYSTEM software package allows you to programin the native 6500 series Assembly language code arec on the Commodore PET computer It provides you with a very powerful assembler editor and loader These development tools apera t like and provide the same level of direct machine interface as the assemblers on much larger computers This package contains everything that you will need to create assemble load and execute 6500 series Assembly language code You will notice that like the software this user s manual is directed towards th
15. Code sequentially which means that all of the symbo that are encountered fall into two classes i e already defined symbols and non previ ously encountered symbols The assembler assigns defined values and builds a table of undefined symbols When a previously defined symbol is discovered it is substituted into the table The assembler then processes all of the input statements a second time using currently defined values ut Is mb ne ef A label or expression which uses a yet undefined value is considered to be referenced forward to the to be defined value To allow for conformity of evaluating expressions this assembler allows for one level of forward reference so that the following code is all owed Card Sequence Label Opcode Operand 100 BNE NEWONE 200 NEWONE LDA 5 The following is not allowed Card Sequence Label Opcode Operand 100 BNE NEWONE 200 NEWONE I NC NEXT 5 300 NEXT LDA 5 This feature should not disturb the normal use of labels The correction for this problemin this example is Card Sequence Label Opcode Operand 100 BNE NEWONE 300 NEXT LDA 5 301 NEWONE I NC NEXT 5 This error may also mean that a value on the right side of the is not defined at all in the program in which case the cure is the same as for undefined values Seite 20 Assembler Manual The assembler cannot process more than one level of computed forward reference All expressions with symbols that appear on the right side of
16. ON OF ERROR MESSAGES Appendix V EDITOR COMMAND SUMMARY NTRODUCTI ON This manual describes the Assembly Language and assembly process for Commodore PET progeam which use one of the 6500 series METOPO oari Several assemblers are available for 6500 series program development each is slightly different in detail of use yet all are the same in principle The 6500 series processors include the 6502 through the 6515 the instruction sets are identical The process of translating a mnemonic or symbolic form of a computer program to actual machine code is called assembly and a program which performs the translation is an assembler We refer to the symbolic form of the program as source code and the actual association for those symbols are the Assembly Language In general one Assembly Language statement will translate into one machine instruction This distinguishes an assembler from a compiler which may produce many machine instructions froma single statement An assembler which executes on a computer other than the one for which code is generated is called a cross assembler Use of cross assemblers for program development for microprocessors is common because often a microcomputer system has fewer resources than are needed for an assembler However in the case of the Commodore PET this is not true With a floppy disk and printer the system is well suited for software development Normally digital computers use the binary number system for rep
17. alue is the indirect page zero address which contains the actual operand address In this example LDA BETA X the parentheses around the operand indicates indirect mode In the above example the value in index register X is added to BETA That sum must reference a location in page zero mno During execution the high order byte of the address is ignored US forcing a page zero address The two bytes starting at that local on in page zero memory are taken as the address of the operand in low byte high byte format For purposes of illustration assume the following BETA contains 12 X contains 04 Locations 0017 and 0016 contain 01 and 25 Location 0125 contains 37 Then BETA X is 16 the address at location 16 is 0125 the value at 0125 is 37 and hence the instruction LDA BETA X loads the value 37 into the accumulator This addressing mode is often used for accessing a table of address vectors in page zero This form of addressing is shown in the following illustration LDA BETA X Address Value BETA 12 04 0016 te 0016 25 Treated as Low Byte 0017 01 Treated as High Byte result is 0125 te te eee 0125 37 This value is loaded into the Accumulator 1 6 Indirect Indexed Another mode of indirect addressing uses index register Y and is illust Pael by LDA GAMMA Y In this case GAMMA references a page zero location at which an address is to be found The value in inde
18. any equal sign must refer only to previously defined symbols for the equate to be processed LLEGAL OPERAND TYPE After finding an opcode that does not have an implied operand the assembler passes the operand field the next non blank field following the eos and determines what type of operand it is indexed absolute etc If the type of operand found is not valid for the opcode this error message will be printed Check to see what types of operands are allowed for the opcode and make sure the form of the operand type is correct see the section 1 1 on addressing modes Check for the operand field starting with a left parenthesis If it is Supposed to be an indirect operand recheck the correct format for the two types available If the format was wrong missing right parenthesis or index register this error will be printed Also check for missing or wrong index registers in an indexed operand form expression index register MPROPER OPCODE The assembler searches a line until it finds the first non blank character string If this string is not one of the 56 valid opcodes it assumes it is a label and places it in the symbol table It then continues parsing for the next non blank character string If none are found the next line will be read in and the assembly will continue However if a second field is found it is assumed to be an opcode since only one label is allowed per line If this character string is not a vali
19. arry Flag CLD Clear Decimal Mode CLI Clear Interrupt Disable Bit CLV Clear Overflow Flag CMP Compare Memory and Accumul ator CPX Compare Memory and Index X CPY Compare Memory and Index Y DEC Decrement Memory Dy One DEX Decrement Index X by One DEY Decrement Index Y by One EOR Exclusive Or Memory with Accumulator INC Increment Memory by One INX Increment X by One INY Increment Y by One JMP jump to New Location JSR Jump to New Location Saving Return Address LDA Transfer Memory to Accumul ator LDX Transfer Memory to Index X LDY Transfer Memory to Index Y LSR Shift One Bit Right Memory or Accumul ator NOP Do Nothing No Operation ORA OR Memory with Accumulator PHA Push Accumulator on Stack Seite 17 PHP PLA PLP ROL ROR RTI RTS SBC SEC SED SEI STA STX STY TAX TAY TSX TXA TXS TYA Appen p N 1 1 1 1 1 1 1 1 1 1 1 oDOOOOOCOOCOCCC Cr D O OOOO OOOO OT Juu DOA OOOO OO O mMm e O Oo Noco U1 BUNE H RO DO DO Fe FE ee ee ee ee Pe PP pa PP NIFH OO COHAD UT SW NIE OW CHAD UT AUN Ee O C CHD UT amp W PY D O OOOO OOOO OO OOOO OOOO OOOO OOOO OOO D O OOOO OOOO OOOO OOOO OOOO COCO OO OO OOO O D O LO WW LO WH WHO WH WH WH WH OO CO OO CO CO oo CO CO CO OO HI N N NN HH N Assembler Manual Push Processor Status on Stack Pull Accumulator From Stack Pull Processor Status From Stack Rotate One Bit Left Memory or Accumul ator Rotate One Bit Right Memory or Accumul ator Return From Interrup
20. d is defined as a string of characters separated by a space A label is an alphanumeric string of from one to six characters the first of which must be alpha A label may not be any of the 56 opcodes nor any of the special single characters i e A S P Xor Y These special characters are used by the assembler to reference the Accumulator A Stack pointer S Processor status P Index registers X 0 0 0 0 and Y A label may begin in any column provided it is the first field of an instruction Labels are used on instructions as branch targets and on data elements for reference in operands Seite 4 Assembler Manual The operand portion of an instruction specifies either an address or a value An address may be computed by expression evaluation and the assembler allows considerable A in expression formation An Assembly Language expression consists of a string of names and constants separated by operators and add subtract multiply and divide Expressions are evalued by the assembler to computer operand addresses Expressions are evaluated left to right with no operator precedence and no parent ce grouping Note that expressions are evaluated at assembly time and not execution time Any string of characters following the operand field is considered a comment and is listed but not further processed If the first nonblank character of any record is a semi colon the record is processed as a comment On i
21. d opcode the error message is displayed This error can occur if opcodes are misspelled in which case the assembler will et ae the opcode as a label if no label appears on the card It will then try to assemble the next field as the opcode If there is another field this error will be printed Check for a misspelled opcode or for more than one label on a line NDEXED MUST BE X OR Y After finding a valid opcode the assembler looks for the operand In this case the first character in the operand field is a left parenthesis The assembler interpretes the next field as an indirect addrses which with the exception of the jump statement must be indexed by one of the index registers X or Y In the erroneous case the character that the assembler was trying to interpret as an index register is not X or Y and this error message is printed Check for the operand field starting with a left parenthesis If it is Supposed to be an indirect operand recheck the correct format for the two types available If the format is wrong missing right parenthesis or index register this error will be printed Also check for missing or wrong index registers in an indexed operand form expression index register NDI RECT OUT OF RANGE The assembler recognizes an indirect address by the parentheses that surround it If the field following an opcode has parentheses around it the assembler will try to assemble it as an indirect address If the
22. e There are eight conditional branch instructions available to the user In this example BEQ START iF EQUAL BRANCH TO START If the values compared are equal a transfer to the instruction labelled START is made The branch address is a one byte positive or negative offset which is added to the program counter during execution At the time the addition is made the program counter is pointing to the next instruction beyond the branch instruction The offset is based on the location of the next instruction A branch address must be within 127 bytes forward or 128 bytes backward fromthe conditional branch instruction An error will be flagged at assembly time if a branch target falls outside the bounds for relative addressing Relative addressing is not used for any instructions other than branch 1 4 Implied Twenty five instructions such as TAX Transfer Accumulator to Index X require no operand and hence are single byte instructions Thus the operand addresses are implied by the operation code Four instructions ASL LSR ROL and ROR are special in that the accumulator A can be used as an operand In this special case these four instructions are treated as implied mode addressing and only an operation code is generated 1 5 Indexed Indirect Seite 6 Assembler Manual In this mode the operand address is computed by first adding the X o ver the index to the argument in the operand in the example below BETA The resulting v
23. e experienced computer user that already has some familiarity with the 6500 series Assembly language and the operations of the Commodore PET computer This preaun is not intended to provide the oe eoe of how to in assembly language but provides the software tools for the experienced assembly language programmer It is recommended that the user obtain one or more of the reference manuals listed below for a more detailed description of 6502 assembly language and the Commodore PET The publisher is listed in parenthesis o 6502 Assembly Language Subroutines Leventhal and Saville Osborne McGraw HIII o 6502 Software Design Scanlon Howard W Sams amp Co o 6502 Assembly Language Programming Leventhal Osborne McGraw Hil 0 one Programmer s Reference Guide Commodore Howard W Sams amp Co o Programming in 6502 Rodnay Zaks Sybex This manual has been divided into five parts for easier reference Part One Introduction provides a brief description of how an assembler works along with some basic terminology used throughout this manual It is recommended that the novice user read this section first to obtain a feel for the level of knowledge needed to programin assembly anguage and use this manual Part Two PET Assembler Capabilities and Conventions is composed of Sections 1 3 and describes those capabilities and conventions used by Seite l l Assembler Manual this assembler Part Three Creating and Editing Ass
24. embly Source Files is composed of Section 4 and describes how to create and edit an assembly language source file Section 4 contains the operating instructions for loading and running the Editor program This program allows the user to create and edit assembly source files Part Four of the manual Assembling and Testing a Program is composed of Sections 5 6 and contains information on the programs that allow the user to assemble and test object programs Section 5 describes the operation of the assembler program Section 6 describes the program that must be used to load an object program into memory Finally Part Five Appendices includes those charts and tables that can be used as a reference to other sections It also provides a quick reference to the commands available when running certain programs USER CONVENTI ONS Throughout this manual there are certain conventions used to help make p ana Tai less ambiguous A list of these conventions is given below We recommend that the user become familiar with these Parentheses are used to denote an option The only exceptions to this rule are in those sections where indirect indexed and indexed indirect addressing are explained In these cases the parentheses are required label This is used to denote a label reference in an assembler Source program The actual label used is determined by the programmer opcode This is used to denote one of the 6502 instructions as specif
25. emory whenever possible Please avoid assembling code in page zero as problems may be encountered Remember the assembler makes decisions on which formto use based on operand address computation If B e ge c A is at 01 m s AD 3C 01 ize st 1 2 Constants Constant values in Assembly Language can take several forms If a constant is other than decimal a prefix character is used to specify type Dollar sign specifies hexadeci mal Commercial at specifies octa Percent specifies binary Seite 5 Assembler Manual specifies an ASCII literal character in immediate The absence of a prefix symbol indicates decimal a value In the statement LDA BETA 5 the decimal number 5 is added to BETA to compute the address Similarly LDA BETA 5F denotes that the hexadecimal value of 5F is to be added to BETA for the address computation The immediate mode of addressing is signified by a pound sign followed by a constant For example LDA 2 specifies that the decimal value 2 is to be put into the accumulator Similarly LDA G will load the ASCII value of character G into the accumulator Since the accumulator is one byte the value loaded must be in the range of 0 to 255 decimal Note that constant values can be used in address expressions and as values in immediate mode addressing They can also be used to initialize locations as explained in a later section as assembler directives 1 3 Relativ
26. enth asterisk eans the value of the current location counter This corresponds to he ORG directive in some assemblers It is sometimes read as here or this location Some equate examples are RED 5 BLUE FF and me 0200 A list of the directives is given below their use is earned in this section BYTE WORD DBYTE PAGE SKIP OPT END FILE LIB x Labels and symbols other than directives may not begin with a period Examples of assembler directives can be seen in the sample Assembl er program in Appendix Ill If desired all directives which are preceded by the eee my be abbreviated to the period and three characters e g BY BYTE is used to reserve one byte of memory and load it with a value The directive may contain multiple operands which will store values in consecutive bytes ASCII strings may be generated by enclosing the string with quotes All quotes are single quotes i e SHIFT 7 It should be noted however that there is a limitation of 40 ASCI characters that can be stored in each BYTE directive HERE BYTE 2 THERE BYTE 1 F ASCII BYTE ABCDEF 101 7 represented in the most convenient form In series expression which can be resolved to eight s directive If it is desired to include a insert two quotes in the string For example general any valid 650 bits may be used in t quote in an ASCII stri BYTE JIM S CYCLE 3 H Note that numbers may be 0 h
27. er n2 New start line number n3 Step size for resequence PUT Command The PUT command outputs source files to the disk for later assembly PUT has the ability to output all or part of the memory resident file PUT filename nl n2 n3 n4 nl Starting line number Optional n2 Ending line number Optional n3 Device number default is 8 Optional n4 Secondary address default is 8 Optional If nl n2 n3 n4 are left out the whole file is output to the disk 5 0 ASSEMBLING A SOURCE FILE Once a source file is ready to assemble you must first save it on disk by using the PUT command P t i ease be sure to do this before loading is is completed you will load the the same area that BASIC programs do the assembler program Once assembler which will reside 5 1 Loading the Assembler Program To load the assembler type SYS 36864 The assembler will print a copyright notice and the first user prompt when execution begins 5 2 Using the Assembler Program When a program is being assembled the user has the option of creating an object file which contains the data necessary to create a machine code program by the loader The name of this file is specified by the user before assembly starts It should be noted however that the assembler program will not overwrite any files If you wish to use the same object filename each time you assemble a program you must scratch the old object file before you run the asse
28. ere aren t other operands the assembler will run off the current line looking for them READ ERROR This message refers to a disk drive read error Refer to your disk drive manual for a description of these errors and their causes UNDEFI NED DIRECTIVE All assembler directives begin with a period If a period is the first character in a non blank field the assembler interprets the following character string as a directive If the character string that follows is not a valid assembler directive this error message will be printed Check for a misspelled directive or a period at the beginning of a field that is not a directive UNDEFI NED SYMBOL This error is generated by the second pass If in the first pres the assembler finds a symbol in the operand field the field following the opcode or an equals sign that has not been defined yet the assembler puts the symbol into the table and flags it for interpretation by pass two If the symbol is defined shows up on the left of an equate or as the first non blank field in a statement pass one will define it and enter it in the symbol table Therefore a symbol in an operand field found before the definition will be defined with a value when pass two assembles it In this case the assembly process can be completed This is what is meant by one level of forward reference See Forward Reference Error However if pass one doesn t find the symbol as a label or on the left of an
29. haracters are within a field between commas DUPLICATE SYMBOL The first field on the card is not an opcode so it is interpreted as a label If the current line is the first line in which that symbo appears as a label or on the left side of an equals sign It is put Seite 19 Assembler Manual into the symbol table and tagged as defined in tha the symbol has appeared as a label or on the left to the current line the assembler finds the labe symbol table The assembler does not allow redefin will in this case print this error message FILE EXISTS The FILE EXISTS error mess exists on the diskette Thi old file or changing the di FILE NOT FOUND t line However if of an equate prior already in the t itions of symbols and ge occurs when the object file named already s error can be corrected by scratching the s a j i skette The FILE NOT FOUND error message is displayed when one of the following occurs o The source file was not found o A LIB specifies a nonexistant file o A FIL specifies a nonexistant file The user should make sure that the filename is not misspelled or that the wrong diskette was placed in the disk drive FORWARD REFERENCE The expression on the right side of an equals sign contains a Sy he that hasn t been defined previously One of the operations of the assembler is to evaluate expressions or labels and assign addresses or values to them The assembler processes the inp Source
30. hen the Editor Programis in operation any BASIC statement typed Seite 12 Assembler Manual such as 10 FOR 1 TO 10 will not be tokenized converted into BASIC keyword tokens Thus you cannot type a BASIC line with the editor turned on To avoid this problem disable the editor with the KILL command or reset the computer with the COLD command to return to BASIC Source files are loaded with the GET command As the file is loaded the editor generates the line numbers automatically starting at 1000 After editing the file ensure that the last line in the file is a FILE or a END assembler directive Then save the file on the disk with the PUT command mp an Be sure to save your completed ae BEF or ing the PUT command ORE loading the assembler or your file wil lo us be st Refer to Appendix V for an Editor Command Summary 4 3 Editor Program Commands AUTO Line Numbering ering a new source The AUTO command generates new line numbers while t f owi ng en code file To enable the AUTO command type the fol AUTO n1 where nl is the optional increment between line numbers printed To disable the AUTO function type the AUTO command without an increment BREAK Command Calls the built in TIM Monitor CHANGE string The CHANGE command automatically locates and replaces one string with another multiple occurrences This command is entered in the following format CHANGE strl str2 nl n2 l Delimits the strl and st
31. i ng Seite 8 Assembler Manual could be used to store JIM S CYCLE It should be noted that the use of arithmetic yah in the BYTE directive is not supported in this version of the package WORD is used to reserve and load two bytes of data at a time Any valid expression except for ASCII strings may be used in the operand field For example HERE WORD 2 THERE WORD 1 FFO03 3 WHERE WORD HERE THERE The most common use for WORD is to generate addresses as shown in the previous example labelled WHERE which stores the 16 bit address of HERE and THERE Addresses in the 6500 series are fetched from memory in the order low byte then high byte Therefore WORD generates the value in this order The hexadecimal portion of the example FF03 would be stored 03 FF If this order is not desired use DBYTE rather than WORD DBYTE is exactly like WORD except the bytes are stored in high byte low byte order For example DBYTE FF03 will generate FF 03 Thus fields generated by DBYTE may not be used as indirect addresses An advanced technique is to set up vector tables under the assembler directive DBYTE and to push the starting vector address onto the stack then execute an RTS instruction to access pay routine Remember that the addresses for the operands should be the actual address location minus one When constructing a JUMP table in the usual way using an indirect jump instruction opcode MP
32. ied in Appendix II operand This is used to denote the operand or argument portion of an instruction comment s This is used to specify user comments filename This is used to specify a filename on disk The actua name is determined by the user fi ename This is used to denote a wild card filename i e a ee i that begins with the characters preceding the lower case Generally lower case variables specify that it is up to variable you to supply the actual data UPPER CASE Generally UPPER CASE NAMES are the actual input to be NAMES typed TABLE OF CONTENTS PET A ER CAPABILITIES AND CONVENTI ONS 1 0 TION FORMAT CONVENTI ONS A B R Zv xed Indirect irect Indexed DI RECTI VES LES GENERATED BY THE ASSEMBLER Seite 2 L UC Sy Co Re Im In In BL T UN ona Ce el el el eel ANDURWMNrH Wm rm ir ooo _ _ 7z o Assembler Manual CREATING AND EDITING ASSEMBLY SOURCE FILES 4 0 CREATING AND EDITING A SOURCE FILE 4 1 Loading the Editor Program 4 2 Using the Editor Program 4 3 Editor Program Commands ASSEMBLY AND TESTING A PROGRAM 5 0 ASSEMBLING A SOURCE FILE 5 1 Loading the Assembler Program 5 2 Using the Assembler Program 6 0 LOADING AN OBJECT FILE 6 1 Loading the Loader Program 6 2 Using the Loader Program APPENDICES Appendix DESCRIPTION OF FILES Appendix Il 6500 SERIES MICROPROCESSOR INSTRUCTION SET OPCODES Appendix IIl A SAMPLE OUTPUT LISTING OF THE COMMODORE PET ASSEMBLER Appendix IV EXPLANATI
33. mbler When the assembler starts the first prompt will be OBJECT FILE CR OR D NAME If you want the assembler to create an object file enter the filename and press RETURN If not press RETURN Next you will be prompted with HARD COPY CR Y OR N If you want a hardcopy printout enter Y and press RETURN or simpl press RETURN If not enter N and press RETURN This will cause th Seite 15 y e Assembler Manual output to be listed to the screen Finally you will be prompted with SOURCE FILE NAME Enter the name of the source file that you wish to assemble After entering this last prompt the assembler p execute If during this assembly the symbol ta assembly process will stop HALTING THE ASSEMBLER m begins to ogra le overflows the b When the assembler is running ee may be halted by pressing the RUN STOP key If this is done the assembly process will be stopped and the program will wait for the user to either continue the assembly or to terminate it completely Press the B key to terminate the assembly and return to BASIC Pressing any other key will continue the assembl y process This feature is useful for users without printers as the screen listing can be examined during assembl y 6 0 LOADING AN OBJ ECT FILE The Commodore PET Assembler produces protable output in an ASCII format that can not be directly executed This output must be LOADED so the program can be executed This is the function of
34. n the BYTE directive The first two characters will always be printed and subsequent characters will be printed normally two bytes per line if GENERATE is used contains able and END should be the last directive in a file and is used to signal the physical end of the file Its use is optional but highly recommended for program documentation LIB allows the user to insert source code from another file into the assembly When the assembler encounters this directive it temporarily Seite 10 Assembler Manual ceases reading source code fromthe current file and starts reading from the file named in the LIB Processing of the original source file resumes when end of file EOF or END is encountered in the cee ae file The control file containing the LIB can contain other assembler directives to turn the listing function on and off etc FIL can be used to link another file to a current one during assembly A library file called by a LIB may not contain another LIB but it may contain a FIL A FIL terminates assembly of the file containing it and transfers source reading to the file named on the OPERAND There are no restrictions on the number of files which may be linked by FIL directives Caution should be exercised when using this directive to ensure that no circular linkages are created An assembler pass can only be terminated by EOF or the END directive 3 0 OUTPUT FILES GENERATED BY THE ASSEMBLER There are
35. nstructions which require no operand comments may follow the opcode At least one space must separate the fields of an instruction Appendix IIl presents a sample output listing fromthe assembler Various examples of instruction format are included 1 1 Symbolic Perhaps the most common operand addressing mode is the symbolic form as in LDA BETA PUT BETA VALUE IN ACCUMULATOR In this example BETA is a label referencing a contains the value to be loaded into the accumu for an address at which the value is located S instruction yte in memory that ator BETA is a labe m imilarly in the LDA ALPHA BETA the address ALPHA BETA is computed by the assembler and the value at the computer address is loaded Into the accumulator Memory associated with the 6500 series processors is segmented into Bade of 256 bytes each The first page page zero is treated differently by the assembler and processor for optimization of memory Storage space Many of the instructions have alternate operation codes if the operand address is in page zero memory In those cases the address is only one byte rather than the normal two For example LDA BETA located at byte 4B in page zero memory then th is A5 B4 This is called page zero addressing ch is located in me a page one the code generate This is an example of absolute addressing Thus to optimiz orage and execution time a programmer should design with data areas in page zero m
36. ontrol is returned to BASIC APPENDIX DESCRIPTION OF FILES ASSEMBLER See Section 5 This is the actual assembler program which assembles the files which were created by the EDITOR program To load the ASSEMBLER type SYS 36864 Any source text files not previously saved will be lost since the assembler loads into the same area used EDI TOR See Section 4 This program is to create and modify the source code files which will later be assembled To load the EDITOR type SYS 59648 Then type NEW to clear the pointers before proceeding to create or edit any files Be sure to save the source code file using the PUT command before loading the assembler LOADER See Section 6 This programis used to load the sequentia records which are created by the assembler as its output or object file When this programis run it loads the object file into memory in the specified location as true machine code which can be executed To load the LOADER type SYS 44421 APPENDIX Il 6500 SERIES MICROPROCESSOR INSTRUCTION SET OPCODES ADC Add with Carry to Accumul ator AND AND to Accumul ator ASL Shift Left One Bit Memory or Accumul ator BCC Branch on Carry Clear BCS Branch on Carry Set BEQ Branch on Zero Result BIT Test Bits in Memory with Accumul ator BMI Branch on Result Minus BNE Branch on Result not Zero BPL Branch on Result Plus BRK Force an Interrupt or Break BVC Branch on Overflow Clear BVS Branch on Overflow Set CLC Clear C
37. operano field extends into absolute mode i e larger than 255 two bytes would be required to specify the address this error will be printed Seite 21 Assembler Manual This error will only occur if the operand field is i e an index register following the address and t is out of page zero To correct this the address fiel page zero memory The implied high order byte is 00 correct form he address field d must refer to n NVALID ADDRESS An address referenced in an instruction or the address in one of the assembler directives BYTE DBYTE WORD is invalid In the case of an instruction the operand that is generated by the assembler must be greater than or equal to zero and less than or equal to FFFF 2 bytes long This excludes relative branches which are limited to 127 or 128 fromthe next instruction If the operand generates more than two bytes of code or is less than zero this error message will be printed For the BYTE directive each operand is limited to one byte Al address references must be greater than or equal to zero This validity is checked after the operand is evaluated Check for values of symbols used in the operand field see the symbol table for this information LABEL START NEED A Z pcode Therefore the d o bel However the first ith an alphabetic character and The first non blank field is not a val assembler tried to interpret it as a la character of the field does not
38. r2 use any character not in either string stri Search string str2 Replacement string nl n2 Range parameters The format is the same as the LIST command in BASIC If omitted the whole file is searched Optional COLD Command Performs a cold start of the PET CPUT Command The CPUT command outputs source files with no unnecessary spaces to the t disk for later assembly The syntax for this command is the same as the PUT command DELETE The DELETE command allows the user to delete several lines at a time Simply input the range of lines to be deleted n1 through n2 The format is the same as the LIST command in BASIC Seite 13 Assembler Manual DELETE nl n2 To delete a single line enter the line number alone on a blank line and press RETURN FIND string The FIND command is used to search for and locate specific character strings in text Each occurrence of the string is printed on the CRT You can pause the printing with the space bar Printing can then be continued with the space bar or terminated with the RUN STOP key The format of the FIND command is FIND strl nl1 n2 Delimiter use a character not in the string strl Search string nl n2 Range parameter Same as the LIST command in BASIC Optional FORMATted Print The FORMAT command is used to print the text file in tabbed format like the assembler For this function to work correctly you must type mnemonics in column two or one space from labels FORM
39. resentation of data and instructions Computers understand only ones and zeros corresponding to an ON or OFF state Users on the other hand find it difficult to work with the binary number system and hence use a more convenient representation such as octal base 8 decimal base 10 or hexadecimal base 16 Two representations of the 6500 series operation to load information into an accumulator are 10101001 binary A9 hexadeci mal An instruction to move the value of 21 decimal to the accumulator is A9 15 hexadecimal Users still find numeric representations of instructions tedious to work with and hence have developed symbolic representations For example the preceding instruction might be written as LDA 21 Seite 3 Assembler Manual In this example LDA is the symbol for A9 Load the Accumulator An assembler can translate the symbolic form LDA to the numeric form A9 Each machine instruction to be executed has a symbolic name referred to as an operation code opcode The ene for store accumulator is STA The opcode for transfer accumulator to index x is TAX The 56 opcodes for the 6500 series processors are detailed in Appendix II A machine instruction in Assembly Language consists of an opcode and perm operands which specify the data on which the operation is to e performed A label is a name for a line of code Instructions may be labelled for reference by other instructions as shown in L2 LD
40. ssion is in an OPERAN 0 h However When t s and the value of e instruction is one byte f D r the e the memory the extra one that was saved the assembler didn t know how large the value was so it saved for the largest value which was two bytes APPENDIX V Command AUTO n1 AUTO BREAK CPUT file DELETE nl n2 FIND s1 nl n2 FIND s1 FORMAT nl n2 GET file nl n2 n3 GET file KILL LIST NUMBER ni n2 n3 PUT file nl n2 n3 n4 PUT file EDITOR COMMAND SUMMARY Description Starts automatic line numbering Shuts off auto Calls the Monitor Routine Change string in line range Change string in entire file Performs a cold start of the PET Compacted PUT unnecessary spaces are removed Delete range Find string in line range Find string in entire fil Print formatted Bring in text from disk file Short form GET Disable the editor List lines of text Renumber text Save text on disk drive Save text short form e Seite 24
41. t Return From Subroutine Subtract Memory and Carry From Accumul ator Set Carry Flag Set Decimal Mode Set Interrupt Disable Status Store Accumulator in Memory Store Index X in Memory Store Index Y in Memory Transfer Accumulator to Index X Transfer Accumulator to Index Y Transfer Stack Pointer to Index X Transfer Index X to Accumulator Transfer Index X to Stack Pointer Transfer index Y to Accumulator dix Ill A SAMPLE OUTPUT LISTING OF THE COMMODORE PET ASSEMBLER LOC CODE LINE CCEl i aoe INIT THE MEMORY MANAGER STARTUP COMES HERE CCEl G000 CCE1 A202 LDX 02 MOVE THREE BYTES CCE3 BD DE CC WEDGE LDA J UMP X CCE6 95 7C STA CHRGOT 3 X CCE8 CA DEX CCE9 10 F8 BPL WEDGE CCEB CCEB A5 BA LDA FA USE CURRENT FA FOR DEVICE ADDRESS CCED 8D 77 CC STA SVFA CCFO f CCFO SAY HELLO AND EXIT CCFO ea 4C 4B CF J MP MSG PRINT HELLO J SR RTS F eae THIS S WHERE WE COME TO DO THE WORK F i CCF3 START CCF3 85 A6 STA BUFPT SAVE A X CCF5 86 A7 STX BUFPT 1 CCF7 BA TSX ACTIVATED CALL IN GONE CCF8 BD 01 01 LDA 0101 X CCFB C9 E6 CMP lt GONE FROM A RUNNING PROGRAM CCFD FO 04 BEQ TRYTWO CCFF C9 8C CMP lt MAIN FROM DIRECT MODE CD01 ODO 17 BNE NOTCMD CD03 BD 02 01 TRYTWO LDA 0102 X CD06 C9 A7 CMP gt GONE PROGRAM CD08 FO 04 BEQ FINDIT CD0A C9 A4 CMP gt MAIN DIRECT CDOC DO OC BNE NOTCMD CDOE A5 A6 FINDIT LDA BUFPT GET THE COMMAND BACK CD10 A2 08 LDA NCMD 1 CD12 FI NDC
42. x Y is added to that address to compute the actual address of the operand Suppose for example that GAMMA contai ins 38 Y contains 07 Locations 0039 and 0038 contain 00 and 54 Location 005B contains 26 The address at 38 is 0054 seven is then added to this giving an effective address 005B The value at 005 5B is 26 which is loaded into the accumulator In indexed indirect the a e X is added to the operand prior to the indirection In indirect indexed the indirection is done and then the Seite 7 Assembler Manual index Y is added to compute the effective address Indirect mode is always indexed except for a JMP instruction which allows an absolute indirect address as oe by JMP DELTA which causes a branch to the address contained in locations DELTA and DELTA 1 The indirect indexed mode of addressing is shown in the following illustration LDA GAMMA Y Address Value Abarat greet d GAMMA 38 Poeser 0038 54 Treated as low byte 0039 00 Treated as high byte result is 0054 fee ee eee Add 07 from Y result is 005B fie sch atereast 005B 26 This value is loaded into the Accumul ator Foes er seein 2 0 ASSEMBLER DIRECTIVES here are eleven assembler directives used to reserve storage and direct information to the assembler Nine have symbolic names with a period as he first character The tenth a symbolic equate uses an equals sign to establish a value for a symbol The elev
Download Pdf Manuals
Related Search
Related Contents
Teledex DCT1900 User's Manual Maintenance - Newtunings.com Symbol SAC2000-4000CR 0.1kW・三相(直交軸) Spektrum SPMAR636 Ariens ST5520 User's Manual Operating Instructions Bedienungsanleitungen RAPPORT d`AcTiviTé 2013 取扱説明書 - 打痕防止 精密加工 機械・部品のアリオテクノ|打痕を防止 1 - ソニー製品情報 Copyright © All rights reserved.
Failed to retrieve file