Home
MPASM Assembler
Contents
1. Library Collection of relocatable object modules Librarian Program that creates and manages a library Add remove replace list object modules David Rye MTRX 3700 MPASM Assembler Slide 7 of 78 MPLINK Linker Files Input to Linker Relocatable object file or lib Relocatable object code in library file Output from Linker hex Absolute machine code Intel Hex format cof Absolute machine code in Common Object File Format contains executable code and symbol table Load map file shows where program and data objects are placed in memory David Rye MTRX 3700 MPASM Assembler Slide 8 of 78 Workflow Assembler and Linker Assemble one or more assembly language Source Files xxxx asm to Relocatable Object Files using MPASM Link relocatable object files with linker MPLINK to form absolute executable file Even one file must be linked gt to calculate absolute addresses cocooocoo o o o o o o o Meo o o o o o o o oooocaa MORE O David Rye MTRX 3700 MPASM Assembler Slide 9 of 78 MPLAB X File Structure Assembler and Linker Outputs N Example X Source files asm inc Makefile build Assembler Output safe to delete default T debug Listing files lst Error files err Relocatable Object files o production Listing files 1st
2. Assembler directives Macro directives macro local exitm endm expand noexpand David Rye MTRX 3700 MPASM Assembler Slide 64 of 78 6 Directives for Macro Definition Control execution and data allocation within macros macro Declare macro Definition exitm Exit from a macro stop expansion exit to the endm endm End a macro definition expand Expand macro listing noexpand Turn off macro expansion local Declare a local macro variable David Rye MTRX 3700 MPASM Assembler Slide 65 of 78 Macro Definitions MACRO Declare a macro definition ENDM Enda macro definition len 10 size equ 20 label macro lt arg gt lt arg gt statements n Bottin endm macro size local len label LOCAL Declare local macro variable len set size 1 1 1 local lt label gt lt label gt abe res en len set len size Declared inside a macro local scope nam EXITM Exit from a macro exitm Forces immediate exit from macro during assembly David Rye MTRX 3700 MPASM Assembler Slide 66 of 78 Example Macro Definition Macro definition is include p18f452 inc Compare register aReg to a constant aConst and jump to aDest if register value constant mCmpJge David Rye MTRX 3700 macro aReg aConstant aDestination movlw subwf btfsc goto endm aConstant aReg W status carry aDestination MPASM Assembler Slide 67 of 78 Exa
3. MTRX 3700 MPASM Assembler Slide 60 of 78 Example Data Segments Contents of Program Memory moviw Ox0A movwf DEST start of cinit table START T Eni 0002 002B 0000 0000 P c 0000 EO 0010 0000 0001 0000 0080 0000 0009 CECI 0020 0000 7552 7262 6369 200 504 FFFF FFFF Rubric oR rb ci 0 initial value of Gain 0x04D2 initial value of Flags 0xA5 cinit Table 0002 num_init 2 0000 0028 0000 0000 0000 0001 copy 1 byte from 0x00002B ROM to 0000 0022 0000 0080 0000 0009 9 bytes from 0x000022 ROM to 0x080 RAM David Rye MTRX 3700 MPASM Assembler Slide 61 of 78 MPASM Macro Language A simple form of preprocessor that allows for limited higher level abstraction David Rye MTRX 3700 MPASM Assembler Slide 62 of 78 Macros Allow functions with arguments Macro processor can function like a simple compiler In reality macro processor is just doing substitutions macro expansion David Rye MTRX 3700 MPASM Assembler Slide 63 of 78 Macro Syntax Syntax is label macro lt argl gt lt arg2 gt lt argn gt statements endm ends macro definition label is the symbolic name of the macro Zero or more arguments Values assigned to arguments when macro is invoked are substituted for the argument names in the macro body Body statements may contain Assembly language mnemonics
4. DATABANK DATABANK DATABANK DATABANK DATABANK DATABANK DATABANK Access RAM NAME gpr0 NAME gpr1 NAME gpr2 NAME gpr3 NAME gpr4 NAME gpr5 NAME dbgspr ACCESSBANK NAME accesssfr David Rye MTRX 3700 START 0x080 START 0x100 START 0x200 START 0x300 START 0x400 START 0x500 START 0x5F4 START 0xF80 etc here are arbitrary END 0x07F END 0x0FF END 0x1FF END 0x2FF END 0x3FF END 0x4FF END 0x5F3 END 0x5FF END OxFFF PROTECTED PROTECTED MPASM Assembler Slide 74 of 78 Linker Script File xxx 1kr continued Logical sections specify which of the memory regions defined above should be used for a portion of relocatable code generated from a named section in the source code Each SECTION directive defines a name for previously define memory region This defined name can be referenced from the user s code SECTION NAME MAINCODE SECTION NAME PAGE2 ROM page RAM gpr2 Code sections are ref rred to in user code using for example in assembler MAINCODE CODE or in C pragma idata PAGE2 these names used in code David Rye MTRX 3700 MPASM Assembler Slide 75 of 78 Linker Usage See MPLINK User s Manual for Much more detail Many examples David Rye MTRX 3700 MPASM Assembler Slide 76 of 78 The Librarian MPLIB David Rye MTRX 3700 MPASM Assembler Slide 77 of 78 The Librarian MPLIB Allows construction amp maintenance of objec
5. MESSG Create user defined message messg message text error Both print user defined messages David Rye MTRX 3700 error text if size gt MAX INT error 16 bit value exceeded endif include p18f452 inc variable baudrate baudrate set D 5600 required baud rate if baudrate D 1200 amp amp baudrate D 2400 amp amp baudrate D 4800 amp amp baudrate D 9600 amp amp baudrate D 19200 error Selected baud rate is not supported messg only baud rates 1200 2400 4800 amp amp 9600 amp 19200 Hz are supported endif MPASM Assembler Slide 45 of 78 Relocatable Object Files David Rye MTRX 3700 MPASM Assembler Slide 46 of 78 Relocatable Object Files Assembled or compiled object files xxxxx o with no associated absolute load addresses Required for Building pre assembled object libraries with MPLIB Linking assembly language and C language modules Compiler output will be relocatable Specify the segment or section for placement of each part of the linker output rather than absolute addresses David Rye MTRX 3700 MPASM Assembler Slide 47 of 78 5 Directives for Relocatable Object Code So we need directives to work with Projects with multiple assembly language files Placing information into Program or Data Memory Relocatable Object Files Here they are David Rye MTRX 3700 MPASM Assembler Slide 48 of 78 Directi
6. 3 of 78 MPLAB X Help Files MPLAB X is Microchip s free IDE MPLAB X v 3 05 available from UoS website The on line help files in MPLAB X are good Goto Help gt Contents gt MPASMX Toolsuite David Rye MTRX 3700 MPASM Assembler Slide 14 of 78 Assembly Language Syntax Rules for assembly language source code David Rye MTRX 3700 MPASM Assembler Slide 15 of 78 Syntax Assembly Language File Each line of code may contain zero or more Labels Mnemonics Operands Comments Maximum line length is 255 characters Whitespace is not significant Wait btfss PIR1 ADIF wait for A D conversion done David Rye MTRX 3700 MPASM Assembler Slide 16 of 78 Syntax Assembly Language File Labels Start in column 1 corollary anything starting in column 1 is a label Are case sensitive by default Must begin with alphabetic character or underscore Can be 32 characters long Can be followed by a colon or whitespace Mnemonics e g movlw Must not start in column 1 Must be separated from label s by colon or whitespace Operands Must be separated from mnemonics by whitespace Multiple operands must be separated by a comma Comments Can start anywhere Everything from a semicolon to the end of line is a comment David Rye MTRX 3700 MPASM Assembler Slide 17 of 78 Syntax Assembly Language File Radixes Bases Hexadecimal H A3 or OxA3 defa
7. ASH The to address in idata or idata_acs RAM The size in bytes of the data element User code must copy each rom byte to the corresponding to at run time but before the main code assembler or C executes See the examples in IDATA asm and c18i c David Rye MTRX 3700 MPASM Assembler Slide 58 of 78 Example Data Segments From the 1st file generated by MPASM Segment type 60006 Uninitialised UDATA 000000 00006 LimitL RES 1 00008 00009 000000 52 75 62 72 69 00010 63 00 000007 D2 04 00011 Gain DW D 1234 1234 0x04D2 00012 00013 Access 00014 Flags db B 10100101 OxAS Name of this segment David Rye MTRX 3700 MPASM Assembler Slide 59 of 78 Example Data Segments From the map file generated by MPLINK Section cinit contains the cinit table Cinit section starts at 0x000008 Section Info Address Location Size Bytes ess scam suum NY ass cun oss ama cu Section x000000 program 0x000008 x000008 program 0x00001a 000022 program 0x000009 Access i 0x00002b program 0x000001 1 code 0x000124 program 0x000004 Access idata 0x000000 data 0x000001 C Initialised idata 0x000080 data 0x000009 Uninitialised V udata data 0 000002 x x000089 Section Initialised i contains the initial values of initialised variables Section Initialised contains the initialised variables David Rye
8. ASM Assembler Slide 55 of 78 idata initialised Data Memory Segment Data elements in idata or idata acs can be initialised that Is given initial values Use the DB DW or DATA directives to a reserve memory and b specify initial values Question idata is a RAM segment volatile so where do the initial values come from David Rye MTRX 3700 MPASM Assembler Slide 56 of 78 Directives for Object Code Memory Segments IDATA Begin an object file initialised data segment lt label gt idata RAM addr initialisedGlobals Use when generating relocatable object file PODER LimitL dw 0 If 1abe1 unspecified defaults to idata EON LimitH dw D 300 Location Counter initialised to RAM addr me t link time if no address specified i p Flags db 0 Linker generates look up table entry in ROM for string db v axis 0 each entry User must add initialisation code to copy values from ROM to RAM using the cinit table See the file IpATA asm fora good example David Rye MTRX 3700 MPASM Assembler Slide 57 of 78 idata initialised Data Memory Segment The linker generates and populates a table the _cinit table in ROM that contains an entry for each initialised data element Table begins with a 16 bit number num init that stores the number of initialised data element Each table entry has three 32 bit integers that store The from address in ROM FL
9. D 350 aString db Hello Room Relocatable code in RAM udata_acs accessVar db 0x55 udata 0x300 myVariable db D 99 MPASM Assembler Slide 37 of 78 DATA Data Definition General Create numeric and text data data lt expr gt lt expr gt lt expr gt data text string lt text_string gt General data definition places numeric or text data into Program Memory Single characters placed in low byte of word Strings packed 2 characters per 16 bit word first character in LSB Can be used to declare values in IDATA FILL Fill memory block with value fill lt expr gt count f bracketed by parentheses lt expr gt bea 16 bit long assembly language instruction David Rye MTRX 3700 data one character data Sharp string Numbers data 1 dy T some numbers fill 0 5555 D 10 fill nop NEXT BLOCK MPASM Assembler Slide 38 of 78 Data Definition Un initialised Memory RES Reserve memory res mem units Reserve a number of bytes of memory Do not initialize the memory In absolute code Program Memory will be reserved In relocatable code memory can be either in in Program Memory or Data Memory See code directive Program Memory and udata directive Data Memory David Rye MTRX 3700 Absolute code org 0x2000 res 0x20 32 bytes Relocatable code Globals udata temp res 1 time
10. MPASM Assembler with MPLINK and MPLIB Linker and Librarian David Rye MTRX 3700 MPASM Assembler Slide 1 of 78 What is lt A gt Assembly Language Instructions for a uP written in the form of mnemonics Confusingly also referred to as assembler as in assembler code or to program in assembler Assembler A program that translates from an assembly language to machine instructions A Cross Assembler is a program that runs on one type of processor e g x86 and produces machine instructions for another type PIC Assemble Translate to machine instructions an assembly language is assembled a HLL is compiled or interpreted Assembly The process of translation David Rye MTRX 3700 MPASM Assembler Slide 2 of 78 What is an Assembler At least a translator from mnemonics to binary instructions ADLW h AA 00001111 10101010 Invariably an assembler Has a set of directives that control assembler processing Calculates relative addresses from instruction labels and variable names Most assemblers are macro assemblers Perform macro substitution expansion and calculation at assembly time Macro language allows assembly language programming at a higher level of abstraction local 1 O establish local index variable and initialize while i lt 8 do lt something gt 8 times lt something gt i 1 increment loop counter endw break after eight loops Struc
11. address initialised to ROM addr or at link time if no address specified CODE PACK Begin packed code segment constants stored efficiently in program memory lt 1 1 gt code pack ROM addr Used to place constant data one byte per byte into FLASH memory use db Use with de to place constant data into EEPROM David Rye MTRX 3700 Executable code RST code 0x00 goto start Padded data append padding byte of 0 to odd number or bytes padded code DB 1 2 3 DB 4 5 Packed data no padding bytes appended packed code pack 0x1F0 DB 1 2 3 DB 4 5 MPASM Assembler Slide 51 of 78 Relocatable Data Memory Segments Data variables can be assigned to 1 of 5 segments udata udata acs Each Un initialised use the udata ovr RES directive idata idata acs Initialised at least potentially use DB DW etc directives The linker will place each of these RAM at locations specified by a linker file xxx 1lkr linker file is not added to the project the default generic linker file 18 452 g lkr is used David Rye MTRX 3700 MPASM Assembler Slide 52 of 78 Un initialised Data Memory Segments Data stored in any of these segments is not initialised Can only be accessed through Labels variable names declared in the segment Indirect addressing udata Un initialised data placed in RAM gt 0x80 udata acs access data placed in Ac
12. cess RAM udata ovr overlaid data Used for variables that can be placed at the same addresses because they exist at different non overlapping times David Rye MTRX 3700 MPASM Assembler Slide 53 of 78 Directives for Object Code Memory Segments UDATA Begin un initialised data segment lt label gt udata RAM addr gt If lt Labe1 gt unspecified defaults to udata Declares a segment of Un initialised data Starting address initialised to lt RAM_addr gt or at link time if no address specified UDATA_ACS Begin object file un initialised data segment in Access RAM lt label gt udata acs lt gt If lt 1 1 gt unspecified defaults to udata_acs Declares a segment of Un initialised data in Access RAM Starting address initialised to lt RAM_addr gt or at link time if no address specified David Rye MTRX 3700 Relocatable code variable in banked RAM udata aVariable res 1 Relocatable code variable in access RAM udata_acs accessVar res 1 MPASM Assembler Slide 54 of 78 Directives for Object Code Memory Segments UDATA OVR Begin object file un initialised data overlay segment lt label gt udata ovr lt RAM_addr gt If lt 1 1 gt unspecified defaults to udata_ovr Un initialised data in this segment is overlayed With all other data in udata ovr segments of the same name lt 1 1 gt David Rye MTRX 3700 MP
13. ctive at assembly time David Rye MTRX 3700 MPASM Assembler Slide 34 of 78 The Five ENDs Don t confuse the various ENDx directives END End of the assembly program ENDIF End ofa conditional block ENDW End of a while loop ENDM End of a macro definition ENDC Endan automatic constant block cblock defines a list of named constants David Rye MTRX 3700 any program end if lt endif while endw macro endm cblock endc MPASM Assembler Slide 35 of 78 3 Data Definition Directives Control memory allocation and symbol definition This is how to define named variables RAM and named constant values in FLASH David Rye MTRX 3700 MPASM Assembler Slide 36 of 78 Data Definition Integers DB Declare data of one byte in ROM or RAM DW Declare data of one word in ROM or RAM DE Declare EEPROM data of one byte db lt expr gt lt expr gt lt expr gt dw lt expr gt lt expr gt lt expr gt de lt expr gt lt expr gt lt expr gt All reserve storage in program or data memory and initialize the memory location s db packs 8 bit values into 16 bit memory dw behaves like db for PIC18 devices dw packs words into data memory in low byte high byte order See the idata and code pack directives de places 8 bit values into EEPROM David Rye MTRX 3700 Absolute code in FLASH org 0x2000 errorFlags db B 10100011 highLimit dw
14. cute if symbol is not defined constant BuffLen D 512 ENDIF Terminates conditional block variable RecLen D 64 ifdef lt symbol gt endif lt something gt undefine DEBUG endif David Rye MTRX 3700 MPASM Assembler Slide 27 of 78 Assembler Control Include INCLUDE Literally include a file at this point get register symbols etc include lt path filename gt g g include p18f452 inc include path filename include path filename define configuration bits Similar to ANSI C include configReg inc No difference in behaviour between the forms iie and fiie and fiie Search path order is current directory source file directory MPASM executable directory David Rye MTRX 3700 MPASM Assembler Slide 28 of 78 The 1ow high and upper Operators LOW Return the low byte bits lt 7 0 gt table of a multi byte value data I m a data beatles data eater HIGH Return the high byte bits lt 15 8 gt of a multi byte value Load TBLPTR with the address of I movlw UPPER table UPPER Return the upper byte bits lt 21 16 gt movwf TBLPTRU of a multi byte value movlw HIGH table movwf TBLPTRH moviw LOW table movwf TBLPTRL David Rye MTRX 3700 MPASM Assembler Slide 29 of 78 The banksel Directive BANKSEL Generate bank selecting code mov1b that selects the correct banksel Varl Select correct bank for a variable in any bank of bank for Va
15. label gt lt expr gt label lt expr gt variable variable A variable does not need to be initialised when defined as in SET and value can be changed subsequently Variable value must be formed before being used as an operand BuffLen D 512 MASK 0xAA MASK D 64 RecLen BuffLen RecLen Memory David Rye MTRX 3700 MPASM Assembler Slide 25 of 78 Assembler Control Placing Code ORG Set absolute program origin label org lt expr gt org 0x000008 Sets the value of the assembler s location counter goto HighISR For PIC18 lt expr gt must be an even number HighISR replaced by address The location counter value at assembly time is equivalent to the PC value at run time Cannot be used when generating a HighISR relocatable object file Z reis dues Bebe Use CODE UDATA UDATA ACS IDATA vede RETFIE directives instead see later David Rye MTRX 3700 MPASM Assembler Slide 26 of 78 Assembler Control Defines DEFINE Define a text substitution symbol UNDEFINE Delete a text substitution symbol define symbol lt string gt undefine lt symbol gt define MAX INT D 65535 Same mechanism as in ANSI C define DEBUG lt string gt Will be substituted for lt name gt from the point where defined ifdef DEBUG constant BuffLen 8 variable RecLen 4 IFDEF Execute if symbol is defined IFNDEF Exe
16. mes Including files David Rye MTRX 3700 MPASM Assembler Slide 22 of 78 Assembler Control PROCESSOR Defines the build target processor processor processor RADIX Specify default radix base radix default radix Options are nex dec oct Radix defaults to hex if not specified ERRORLEVEL Set diagnostic message level errorlevel 0 1 2 msg number 0 is show all errors and warnings 2 is show Important hint Use errorlevel 0 lt msg_number gt suppresses a single message David Rye MTRX 3700 Configuration processor 18f452 radix hex errorlevel O0 MPASM Assembler Slide 23 of 78 Assembler Control Symbols EQU Defines a symbolic label for a constant label equ lt expr gt HEIGHT expr is number See examples in p18 452 inc SET Defines a symbolic label for a variable Length label set lt expr gt Area Length Same as except that value of 1ape1 can be redefined with another seT equ equ set set set D 17 HEIGHT 2 2 HEIGHT Length Length 1 David Rye MTRX 3700 MPASM Assembler Slide 24 of 78 Assembler Control Symbols CONSTANT Declare symbol constant constant label lt expr gt constant label lt expr gt constant A constant must be initialised when defined flags amp and cannot be changed VARIABLE Declare symbol variable variable lt
17. mple Macro Invocation When invoked called mCmpJge switchVal maxSwitch switchOn the macro mCmpJge Will produce expand to movlw maxSwitch subwf switchVal W btfsc status carry goto switchOn David Rye MTRX 3700 MPASM Assembler Slide 68 of 78 The Linker MPLINK David Rye MTRX 3700 MPASM Assembler Slide 69 of 78 The Linker MPLINK Locates code and data Given relocatable object code and linker script places code and data in memory Resolves addresses calculates absolute addresses of external object modules Generates an executable a HEX file of specified format Configures software stack size and location in C Identifies address conflicts Produces symbolic debug information allows the use of symbols for variables functions rather than addresses David Rye MTRX 3700 MPASM Assembler Slide 70 of 78 MPLINK Inputs O Relocatable object files lib Collections of relocatable object files Usually grouped in a modular fashion Only used modules are linked into the executable lkr Linker script files tell the linker What files to link Range of valid memory addresses for a particular target David Rye MTRX 3700 MPASM Assembler Slide 71 of 78 MPLINK Outputs hex Binary executable file Intel HEX format 8 bit split format 32 bit HEX format No debug information cof Binary executable file in COFF Comm
18. nbproject Project Configuration don t edit Error files err configurations xml Relocatable Object files o Makefile default mk Makefile genesis properties dist Linker Output safe to delete Makefile impl mk N default Makefile local default mk T debug Makefile variables mk Example X debug hex project properties Example X debug cof Package default bash project xml Example X debug map N private production configurations xml Example X production cof private properties Example X production hex Example X production map David Rye MTRX 3700 MPASM Assembler Slide 10 of 78 Workflow Librarian Librarian MPLIB can be used to create and manage libraries of relocatable object code For example clib lib p18f452 lib myLib lib UNIT2 ASM UNIT3 ASM UNIT1 ASM UNITS LIB UNIT3 O David Rye MTRX 3700 MPASM Assembler Slide 11 of 78 The Assembler MPASM David Rye MTRX 3700 MPASM Assembler Slide 12 of 78 The Assembler MPASM Universal macro assembler for all PIC devices Device capabilities and mnemonics of course change from one device to another Choice of three interfaces Command line DOS shell interface Stand alone MS Windows application Integrated with Microchip s MPLAB IDE An integral part of MPLAB X IDE David Rye MTRX 3700 MPASM Assembler Slide 1
19. on Object File Format Also contains symbolic debug information map Load map showing memory use after linking Identify absolute addresses of globals functions David Rye MTRX 3700 MPASM Assembler Slide 72 of 78 Linker Script File xxx 1kr Sample linker command file for the PIC18F452 processor when used with the MPLAB ICD2 Names of different CODE segments Search Search for Libraries in the current directory path LIBPATH CODEPAGE defined memory regions are in Program Memory and are used for program code constants including const strings and the initial values of initialised variables NAME vectors START 0x000000 END 0x000029 PROTECTED Only usable CODEPAGE START 0x00002A END 0x007DBF by code that CODEPAGE NAME debug START 0x007DCO END 0x007FFF PROTECTED P udi requests it CODE CODEPAGE NAME idlocs START 0x200000 END 0x200007 PROTECTED pragma code NAME config START 0x300000 END 0x30000D PROTECTED CODEPAGE NAME devid START 0x3FFFFE END 0x3FFFFF PROTECTED CODEPAGE NAME eedata START 0xF00000 END 0xF000FF PROTECTED David Rye MTRX 3700 MPASM Assembler Slide 73 of 78 Linker Script File xxx 1kr continued ACCESSBANK defined memory regions in Access RAM used for data variables DATABANK defined memory regions in Banked RAM used for data variables The names gpr0 grpl ACCESSBANKJNAME accessram START 0x000
20. res 2 2 bytes MPASM Assembler Slide 39 of 78 Data Definition Configuration PROCESSOR Set processor type processor processsor type CONFIG Set processor configuration bits config lt bit gt lt value gt _ config is deprecated Sets the configuration bits Processor must previously have been declared Best practice use to over ride MPLAB X config bit settings See configReg inc server See usage and definitions in p18 452 inc IDLOCS Set values of processor ID locations Similarto CONF IG David Rye MTRX 3700 PROCESSOR 18f452 include configReg inc or Configuration Register 1H Oscillator switch disabled EC oscillator CONFIG OSCS OFF OSC EC etc MPASM Assembler Slide 40 of 78 Data Definition RAM Configuration __ MAXRAM Specify maximum RAM address maxram lt expr gt Specifies the highest address of physical RAM __BADRAM Specify invalid RAM addresses __badram lt expr gt Can have more than one badram directive _maxramand__badram together allow strict RAM address checking David Rye MTRX 3700 processor 18F452 H FFF Unimplemented banks _ BADRAM H 600 H F7F Unimplemented SFRs BADRAM H F85 H F88 BADRAM H F8E H F91 BADRAM H F97 H F9C __BADRAM H FA3 H FA5 BADRAM H FAA BADRAM H FB4 H FB9 MPASM Assembler Slide 41 of 78 4 Listing Control Directives Directi
21. rl RAM movwf Varl F BANKED Write to Varl banksel label David Rye MTRX 3700 MPASM Assembler Slide 30 of 78 Assembler Control Termination END End of assembly language program end Every program must finish with an end directive Everything after ena is ignored David Rye MTRX 3700 MPASM Assembler Slide 31 of 78 2 Conditional Assembly Directives Permit sections of code to be conditionally assembled These are active only during assembly they are not active at run time Similar to C language preprocessor directives e g ifdef TESTING some C code here endif David Rye MTRX 3700 MPASM Assembler Slide 32 of 78 Conditional Assembly 1 We have already seen IFDEF IFNDEF IF Begin conditionally assembled block ELSE Begin alternative block to IF PET INCF speed F ENDIF End conditional assembly block else DECF speed F endif if lt expr gt assembly code else alternative assembly code endif lt expr gt is evaluated non zero is interpreted as logically TRUE David Rye MTRX 3700 MPASM Assembler Slide 33 of 78 Conditional Assembly While WHILE Loop while expr is TRUE ENDW End of a WHILE loop while lt expr gt assembly code endw lt expr gt is evaluated and a non zero value is interpreted as logically TRUE assembly code cannot exceed 100 lines Cannot loop more than 256 times A
22. t libraries Runs from the command line DOS Window Syntax is mplib q ctdrx Library Member where q x Ka A Quiet mode Create Library with Member s List table showing Library members Delete Member s from Library Add replace Member s in Library Extract Member s from Library David Rye MTRX 3700 MPASM Assembler Slide 78 of 78
23. tured assembler see Peatman for example and source code Very simple form of compiler Allows control structures e g if then else that are active at run time David Rye MTRX 3700 MPASM Assembler Slide 3 of 78 MPASM Assembler Files Input to Assembler asm Assembly language source file Output from Assembler 15 Assembler listing file err Assembler error messages Relocatable object file David Rye MTRX 3700 MPASM Assembler Slide 4 of 78 Assembler Listing File 1st Format MPASM 5 57 LOC OBJECT CODE VALUE 0000000B 000000 000000 OEOA 000002 6E0B 000004 EF F 000124 EF F David Rye MTRX 3700 SAMPLE ASM LINE SOURCE TEXT 00001 Sample MPASM Source 00002 00003 00004 Dest 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 list p 18F452 equ 8 25 2014 12 37 00 MPASM Assembler Slide 5 of 78 Assembler Listing File 1st Format MPASM 5 57 SYMBOL TABLE LABEL Dest Start Errors Warnings Messages 0 0 reported 0 reported SAMPLE ASM 8 25 2014 12 37 00 VALUE 0000000B 00000000 00000001 0 suppressed 0 suppressed defined because we are building for the PIC18F452 processor David Rye MTRX 3700 MPASM Assembler Slide 6 of 78 What is lt L gt Linker Program that translates one or more relocatable object modules into executable instructions with absolute addresses
24. ult Decimal D 163 Note all the same number Octal 0 243 but different radixes Binary B 10100011 Default radix is Hexadecimal There is no floating point type ASCII Character C ASCII String A String Note A string is not Null terminated unless you add the terminator David Rye MTRX 3700 MPASM Assembler Slide 18 of 78 Assembler Directives Directives Instructions in the source code that tell the assembler how to assemble a source file David Rye MTRX 3700 MPASM Assembler Slide 19 of 78 Assembler Directives Assembler directives are placed in the assembly language source file and tell the assembler how to assemble the source They are not active at run time They are not case sensitive There are many arithmetic and logic operators that can be used to construct directive expressions For example lt lt lt amp etc See precedence table in MPASM User s Guide David Rye MTRX 3700 MPASM Assembler Slide 20 of 78 Assembler Directives There are six types of assembler directives for Assembler Control Conditional Assembly Data Definition Listing Control Object File Control Macro Definition UU ge gt qe David Rye MTRX 3700 MPASM Assembler Slide 21 of 78 1 Assembler Control Directives Defining which processor we are building for Defining assembler error reporting level Defining symbolic na
25. ves for Object File Imports Exports EXTERN Declare an externally defined label Subroutine is called from one extern label label assembly language file extern Subroutine Use when using generating relocatable object file Similar to C C extern declare a label name of subroutine etc that is declared outside the file being assembled Resolved by the linker call Subroutine GLOBAL Export a label to the linker Subroutine is defined in a different file global label lt label gt global Subroutine Use when using generating relocatable object file subroutine code Declare a label name of subroutine etc to body of subroutine make it visible outside the file being assembled return Resolved by the linker David Rye MTRX 3700 MPASM Assembler Slide 49 of 78 Relocatable Program Memory Segments Location of executable code or constant values in ROM Absolute Use an org directive to locate code at an absolute address Relocatable Declare a code segment or a code pack segment and allow the linker to calculate the address Valid address ranges specified in a Linker Script File David Rye MTRX 3700 MPASM Assembler Slide 50 of 78 Directives for Object Code Memory Segments CODE Begin an executable code segment or constants stored in program memory lt label gt code ROM addr If 1abe1 unspecified defaults to code Starting
26. ves to control the content and format of the assembler listing file xxxxx Ist David Rye MTRX 3700 MPASM Assembler Slide 42 of 78 4 Listing Control Directives TITLE Specify Program Title for listing title Code Release 2006 03 16 SUBTITLE Specify Program Subtitle for listing MEUM ee title lt title text gt subtitle lt subtitle text gt page subtitle Memory Diagnostics If defined title and subtitle print on each Memory Diagnostic code here page of the listing SPACE Insert Blank Lines PAGE Insert Page Eject space lt expr gt page space inserts a number of blank lines into the listing file page inserts a new page character into the listing file David Rye MTRX 3700 MPASM Assembler Slide 43 of 78 Listing Control Directives LIST Turn on listing with options NOLIST Turn off listing suppress listing of symbols etc nolist list optionl lt option2 gt include p18f452 inc 1 nolist turn listing back on list list With no options turns listing on Options 14 of them control various listing settings see Assembler Manual help nolist turns off listing EXPAND Expand Macros in Listing NOEXPAND Don t Expand Macros in Listing expand Or noexpand Expand or suppress expansion of all macros in listing file David Rye MTRX 3700 MPASM Assembler Slide 44 of 78 ERROR Issue a user defined error Listing Control Directives message
Download Pdf Manuals
Related Search
Related Contents
Samsung RSA1DTVG Instrukcja obsługi Lissage des cheveux Copyright © All rights reserved.
Failed to retrieve file