Assembly Language ELEC 330 Digital Systems Engineering Dr. Ron Hayne
330_032 The Assembly Process Assembly Language Symbolic representation of instructions and data Source module (.ASM) Assembler Program which translates symbols to machine code Object/Load module (.S19) Listing (.LST) Loader Utility that places machine code into target memory Some assemblers require Linker to convert object module into load module
330_033 Source & Load Modules Source Module (.ASM) Symbolic Instructions, Data and Addresses Instruction mnemonics Symbols Assembler Directives Control instructions for assembler program Comments Explanation of program Load Module (.S19) Binary Instructions and Data Object Module Load Information Address information Error-checking info Checksum
330_034 Listing (.LST) Source Code Source Module Object Code Object Module Symbol Table User symbols Numeric values of symbols (Cross-references) Error Messages
330_035 Motorola Assembly Language Source Statement Single line of program Symbols and Numbers Spaces (or tabs) delineate fields Label Operation Operand Comment Line beginning with an * is also a comment
330_036 Numbers and Symbols Numbers Assembler translates into 16-bit binary Number Systems Decimal 34, -34 Hex $12, $ABCD Binary %1001, % Symbols Characters used to represent addresses or data Assembler translates into numbers Characteristics One to six alphanumeric characters First character a letter Can’t be single letter A, B, X, or Y Must be unique
330_037 Addressing Modes Addressing Mode Operand Format Operand Type Example Inherentnone INCA Immediate#operanddata numberLDAB #40 ExtendedoperandaddressSTAA LENGTH DirectoperandaddressSUBA COUNT Indexedoperand,XoffsetLDD 0,X Relativeoperandaddress/offsetBVS LOOP
330_038 Assembler Directives ORGorigin RMBreserve memory bytes FCBform constant bytes FCCform constant characters FDBform double-bytes EQUequate ENDend
330_039 Source Module (.ASM) * This line is a comment * CONSTEQU17 * ** Data Section ORG$20 DATA1FCB$10 DATA2FDB$B610 STORERMB3 VALUEFCB20 ORG$B600 PTRNFCB% SAVERMB1 *
330_0310 Source Module (.ASM) ** Program Section ORG$E100 STARTLDAAVALUE DECA STAASAVE LDAB#23 LDXDATA2 STABCONST,X DONEBRADONE "STOP" * ORG$FFFEreset vector FDBSTARTset to start END
330_0311 Assembler Listing (.LST) * This line is a comment * CONST EQU 17 * ** Data Section ORG $ DATA1 FCB $ B6 10 DATA2 FDB $B610 STORE RMB VALUE FCB 20 ORG $B600 B600 0C PTRN FCB % SAVE RMB 1 *
330_0312 Assembler Listing (.LST) ** Program Section ORG $E100 E START LDAA VALUE E102 4A DECA E103 B7 B6 01 STAA SAVE E106 C6 17 LDAB #23 E108 DE 21 LDX DATA2 E10A E7 11 STAB CONST,X E10C 20 FE DONE BRA DONE "STOP" * ORG $FFFE reset vector FFFE E1 00 FDB START set to start END
330_0313 Assembler Listing (.LST) Symbol Table CONST 0011 DATA DATA DONE E10C PTRN B600 SAVE B601 START E100 STORE 0023 VALUE 0026
330_0314 THRSim11 68HC11 Simulator setup setup license Source Module (.ASM) Assemble Object/Load Module (.S19) Listing (.LST) Label Window (List) Memory List Memory Map $0000-$00FFRAM $1000-$103FI/O $B600-$B7FFRAM $E000-$FFFFROM Run (Step) CPU Registers Memory List Reset
330_0316 Project 1 THRSim11 Write, Assemble, Test Copy-a-table Program (Figure 2-49, p.108) Individual Work Due Date See web site
330_0317 Bad Assembly Language Bad Documentation too little, too much confusing comments Bad Labels confusing meaningless Bad Numbers mixed bases complex calculations Bad Expressions single/double-bytes mixed constants Bad Instructions mixed addresses/data Extraneous Statements unused symbols unused instructions
330_0318 * Bad Example * CONST EQU $15 * ORG 32 Data Section MARY FCB $ BOB FDB $ABCD/ ABCDEF FCB CONST+BOB LDAA RMB A A FCB $A 0026 EC TWOONES FCB % START LDAA LDAA A DEC A 002C STAA $45 Load the A reg 002E C6 20 LDAB #MARY 0030 D7 25 STAB ABCDEF DF 15 STX CONST 0034 E7 20 STAB MARY,X F3 BRA START F SWI "Stop" END
330_0319 Summary Assembly Process Source Module (.ASM) Object/Load Module (.S19) Listing (.LST) Assembly Language Label, Operation, Operand, Comment Numbers, Symbols Addressing Modes Assembler Directives THRSim11