| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
Assembler-Linker This manual describes using Assembler-Linker dev
Top Searches for this datasheetUM0144 User Manual Assembler-Linker This manual describes using Assembler-Linker develop applications STM8 microcontrollers. assembly tools described this book form development system that assembles, links formats your source code. Purpose scope This manual provides information about producing application executable STM8 microcontrollers from your application source code assembler language. includes: overview assembly language STM8 microcontrollers Instructions running Assembler-Linker Descriptions assembler output ST7xxxx Datasheet full description xxxxmicrocontroller STM8xxxx Datasheet full description STM8xxxx microcontroller Programming Manual complete reference assembly language STM8 Programming Manual complete reference STM8 assembly language Schematic overview assembler toolset information related subjects refer following documentation: Figure Source files Stored object files (*.lib) Objects (*.obj) Listings (*.lst) with relative addresses *.map *.cod *.lst (with absolute addresses) Obsend Programmable binary file (*.s19 *.hex) June 2008 1/86 www.st.com Contents Assembler-Linker Contents Introduction STM8 incompatibilities Tools Host system requirements Getting assistance Conventions Getting started STM8 addressing modes Overview STM8 addressing modes General instruction syntax Short long addressing modes Inherent addressing mode Immediate operands Direct indirect modes Indexed modes Relative mode High, addressing modes assembler Overview Source files Assembler source code format 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 Label structure Label size Label relativity Label scope Opcodes Operands Comments source code example 2/86 Assembler-Linker Contents Segmentation 4.4.1 4.4.2 Segments explained Parameters Macros 4.5.1 4.5.2 Defining macros Parameter substitution Conditional assembly #IF, #ELSE #ENDIF directives Running assembler 4.7.1 4.7.2 Command line Options Linker What linker does Invoking linker Command line 5.3.1 5.3.2 Arguments Response files Linking detail 5.4.1 5.4.2 5.4.3 PUBLICs EXTERNs Segments linker Symbol files linker more detail 5.5.1 5.5.2 5.5.3 composition .OBJ files composition .COD files Reading mapfile listing OBSEND What OBSEND does Invoking OBSEND 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 Destination type Destination arguments Format definitions Straight binary format Intel format Motorola S-record format S-record formats 3/86 Contents 6.2.8 Assembler-Linker binary Librarian Overview Invoking librarian Adding modules library Deleting modules from library Copying modules from library Getting details your library Definitions Appendix Assembler directives. Introduction Directives. Appendix Error messages Format error messages File CBE.ERR Assembler errors Linking errors. 4/86 Assembler-Linker List tables List tables Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Description installed files STM8 addressing modes only addressing modes STM8 addressing modes Numeric constants radix formats Level operators Level operators Level operators Level operators Alignment types Combine types Some useful directives Summary conditional assembly directives Other special directives Command line options Output formats Library file options. Acronyms terms used this document List directives .BELL BYTE BYTES CEQU .CTRL DATE DC.B DC.W DC.L #DEFINE. DS.B DS.W DS.L EXTERN #ELSE. #ENDIF (STM8 only) FCS. .FORM GROUP. #IF. #IF1 Conditional #IF2. #IFB #IFIDN #IFDEF #IFLAB 5/86 List tables Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Assembler-Linker #INCLUDE INTEL INTERRUPT .LALL .LIST #LOAD LOCAL LONG LONGS MACRO MEND MOTOROLA NEAR .NOCHANGE .NOLIST %OUT .PAGE PUBLIC REPEAT .SALL SEGMENT .SETDP SKIP STRING SUBTTL .TAB TEXAS TITLE UNTIL WORD WORDS .XALL ZILOG Assembler errors Linking errors Document revision history 6/86 Assembler-Linker List figures List figures Figure Figure Figure Schematic overview assembler toolset. Assembler source code format example Error message format example 7/86 Assembler-Linker STM8 incompatibilities ST7/STM8 assember development toolchain supports both STM8 core core. placing trigger (st7/ stm8/) first line your code, tell assembler which rules apply. STM8 assembler compatible with assembler. STM8 assembler (16-bit) features that compatible with assembler (8-bit): bits wide (ST7 bits): been replaced A,XL been replaced XL,A been replaced A,YL been replaced YL,A Stack pointer (SP) bits wide (ST7 bits wide): instructions have been removed been replaced X,SP been replaced SP,X been replaced Y,SP been replaced SP,Y more generally 8-bit transfer, example: A,$5000 16-bit transfer, example: X,$5000 (instead X,$5000) instruction been removed Some addressing modes have been removed, example: short pointer short data [pointer.b], example: A,[$10.b] btjf [$11.b],#3,skip short pointer short data indexed ([pointer.b],X) ([pointer.b],Y), example: A,([$10.b],X) ([$12.b],Y),A short pointer short data relative [pointer.b], example: jreq [$13.b] callr [$39.b] Short operations have been replaced long operations, example: btjf $1011,#2,jump (instead btjf $11,#2,jump) bset $1000,#1 (instead bset $00,#1) suffixes supported, example: A,#mem.h replaced A,#{high mem} A,#mem.l replaced A,#{low mem} 8/86 Assembler-Linker Generally, instruction sets similar, with following notable differences: STM8 instruction supports several addressing modes. Stack Pointer (SP) used index. Long pointers have been added. There 3-byte addressing mode called extended. Altogether there addressing modes: short offset indexed, extended direct, extended offset indexed, long pointer long data, long pointer long data indexed, long pointer 24-bit data indexed. Several instructions have been added. STM8 instruction allows longer instructions which span bytes, instead ST7. Tools Assembler-Linker includes following tools: Assembler (ASM): translates your source code (.ASM) written assembly language, into object code (.OBJ) specific target machine optional listing file (.LST). Linker (LYN): processes object files (.OBJ) produced assembler, resolves cross-references between object files locates modules memory. resulting code output object code file (.COD). second pass, Assembler used produce listings with absolute addresses from source files file generated linker. Converter (OBSEND): translates object code file produce final executable format that specify (Motorola S-record, Intel Hex). Librarian (LIB): librarian enables store frequently used subroutines location with number microcontroller applications. Note: utility file asli.bat automatically runs ASM, LYN, OBSEND after other you. this batch file only have only assembly source file .ASM. Host system requirements Please release notes ensure have most up-to-date information. Getting assistance more information, application notes, FAQs software updates microcontroller development tools, check CD-ROM site: www.st.com. 9/86 Assembler-Linker assistance microcontroller subjects, help developing applications that your microcontroller's MSCI peripheral, refer contact list provided Product Support. We'll glad help you. Conventions following conventions used this document: Bold text highlights terms phrases, used when referring names dialog boxes windows, well tabs entry fields within windows dialog boxes. Bold italic text denotes menu commands sequence commands), options, buttons checkboxes which must click with your mouse perform action. symbol used sequence commands mean "then". example, open application Windows, would write: Click Start>Programs>ST Toolset>. Courier font designates file names, programming commands, path names text commands must type. Italicized type used value substitution. Italic type indicates categories items which must substitute appropriate values, such arguments, hypothetical filenames. example, text demonstrating hypothetical command line compile generate debugging information file, might appear cxst7 +mods +debug file.c Items enclosed [brackets] optional. example, [options] means that zero more options specified because options appears brackets. Conversely, line: options means that more options must specified because options enclosed brackets. another example, line: file1.[o|st7] means that file with extension .st7 specified, line: file1 [file2.] means that additional files specified. Blue italicized text indicates cross-reference-you link directly reference clicking while viewing with Acrobat Reader. 10/86 Assembler-Linker Getting started Getting started Installing Assembler-Linker Assembler-Linker delivered part STVD toolset. free installation package available www.st.com. install either select ST7/STM8>ST toolset from main menu Microcontroller Development Tools CD-ROM, installation executable that have downloaded from internet. Note: release notes more guidance installing software components. After installation, installation directory should contain files listed Table Table ASM.EXE LYN.EXE OBSEND.EXE LIB.EXE ST7.TAB STM8.TAB ASLI.BAT ASM_LNK_RELEASE_NOTES.PDF Description installed files assembler linker Output file formatter Librarian description file STM8 description file Batch file ASM+LYN+OBSEND Release notes Up-to-date release notes provided format. additional file contains demonstration examples. 11/86 STM8 addressing modes Assembler-Linker STM8 addressing modes Overview STM8 addressing modes ST7/STM8 assembler instruction incorporates following addressing modes: Table STM8 addressing modes Example A,#$F5 A,$F5 A,$F5C2 A,(X) A,($F5,X) A,($F5C2,X) A,[$F5.w] A,([$F5.w],X) Addressing mode Inherent Immediate Direct (short address) Direct (long address) indexed offset) indexed (short offset) indexed (long offset) Short pointer indirect (long pointed data) Short pointer indirect (long pointed data) indexed Direct relative (short offset) Table only addressing modes Example A,[$F5] A,([$F5],X) [$F5] bset $10, Addressing mode Short pointer indirect (short pointed data) Short pointer indirect (short pointed data) indexed Short pointer indirect relative (short pointed data) Short operation Table STM8 addressing modes Example callf $F5C2A0 A,($F5,SP) A,($F5C2A0,X) A,[$F5C2.w] A,([$F5C2.w],X) A,([$F5C2.e],X) bset $1000, Addressing mode Direct (extended address) indexed (short offset) indexed (extended offset) Long pointer indirect (long pointed data) Long pointer indirect (long pointed data) indexed Long pointer indirect (extended pointed data) indexed Long operation STM8 addressing modes described full detail, with specific examples, relevant programming manual, which downloaded from internet www.st.com. This chapter only gives brief explanation main addressing mode types. 12/86 Assembler-Linker STM8 addressing modes General instruction syntax STM8 instruction sets provide single source-coding model regardless which components operands. operands accumulator (A), 8-bit index register 8-bit stack pointer condition code register (CC), memory location. accumulator (A), 16-bit index register XH,XL (where high byte, byte) YH,YL (where high byte, byte) 16-bit stack pointer (SP) condition code register (CC), memory location. STM8 operands example, single instruction, originates register register transfers well memory accumulator data movements. Two-operand instructions coded with destination operand first position. example, lab01 lab02 A,memory memory,A XL,A load load load load accumulator with memory contents memory location with contents with accumulator contents (ST7 only) with accumulator contents (STM8 only) Short long addressing modes addressing modes that differ memory address size (one byte short mode bytes long mode). STM8, addition long short modes, there also extended addressing mode (three bytes). Because these different addressing modes, target address range operands depends upon addressing mode chosen: 0-$FF short addressing mode $100-$FFFF long addressing mode $10000-$FFFFFF extended addressing mode (STM8 only) Some instructions accept both long short addressing modes, while others only accept other. example: lab10 lab11 A,memory memory accepts both types addressing modes instruction accepts only short addressing mode, while STM8 instruction accepts both modes STM8 accepts only long addressing mode, push memory does exist push memory 13/86 STM8 addressing modes Assembler-Linker instructions supporting both short long formats, when external symbols referenced, long mode chosen assembler. example: symb1 EXTERN symb3; $10; A,symb1; short mode A,symb3; long mode chosen STM8 instructions using extended addressing mode always have suffix. following instructions extended addressing mode: callf $10000 $20000 A,($30000,X) retf permits return previous function stack subroutines that called CALLF Inherent addressing mode This concept hardware-oriented, meaning that instruction operands coded inside operation code. source code level, operands written explicitly. example: lab06 lab07 push accumulator onto stack multiply SP,X load stack pointer Immediate operands Immediate operands permit input specific value with instruction. They signaled sharp sign before value. range 8-bit immediate operand from 255. example: lab08 lab09 bset btjt A,#1 load with immediate value memory,#3 memory location memory,#3,label test memory jump true (set) Direct indirect modes direct addressing mode means that data byte(s) required operation found memory address, which follows op-code. indirect addressing mode means that data byte(s) required operation found memory address which located memory (pointer). pointer address follows op-code. short pointer byte long. long pointer bytes long. 14/86 Assembler-Linker This last group consists memory indirect variants: STM8 addressing modes Short pointer short data, only [shortpointer Short pointer long data [shortpointer Short pointer short data indexed, only ([shortpointer .b],X) ([shortpointer .b],Y) Short pointer long data indexed ([shortpointer .w],X) ([shortpointer .w],Y) STM8 devices only: long pointer long data [longpointer long pointer long data indexed ([longpointer .w], long pointer extended data indexed ([longpointer .e],X)([longpointer .e],Y) page (its address must less than $100) section (its address must less than $10000) STM8 Pointer addresses must always Examples: A,[80] short pointer short (ST7) long (ST8) data A,[80.b] short pointer short data (ST7 only) A,[80.w] short pointer long data A,[$1000.w] long pointer long data (STM8 only) A,([$1000.e],X)long pointer 24-bit data (STM8 only) lab12 A,([lab12],X) short pointer short (ST7) long (ST8) data X-indexed A,([lab12.b],X) short pointer short data X-indexed (ST7 only) A,([lab12.w],Y) short pointer long data Y-indexed distinguish between short long indirect addressing mode, suffix.w indicates that want work long indirect mode (this also true indexed addressing mode). Short indirect means that pointed data short (one byte long) Long indirect means pointed data long (two bytes long) ST7, short indirect addressing mode assumed, also specify short indirect addressing mode with indexed addressing mode). specify long indirect addressing mode. STM8, long indirect addressing assumed, could necessary. With STM8 instruction, must specify extended indirect addressing mode. Implicitly, nothing specified, Indexed modes supports following types indexed mode: indexed without offset, indexed with 8-bit unsigned offset (range [0:255]), indexed with 16-bit offset. 15/86 STM8 addressing modes Assembler-Linker addition these modes, STM8 also supports following indexed mode: indexed with 24-bit offset. no-offset indexing. (offset,X) (offset,Y) indexed with offset. source code syntax Some instructions (such add) support first three types indexed mode. Some instructions (such inc) only support first types (that indexed without offset indexed with 8-bit unsigned offset). STM8 instructions (such inc) support first three types. Only STM8 instruction, ldf, supports "indexed with 24-bit offset" addressing mode. Examples: A,(X) A,(0,X) A,(127,X) A,(259,X) A,($FFF00, ($F5, no-offset mode 8-bit offset mode 8-bit offset mode 16-bit offset mode 24-bit offset mode (STM8 only) indexed mode, 8-bit offset short(STM8 only) Relative mode This addressing mode used modify program counter (PC) register value adding 8-bit signed offset range -128 +127). relative addressing mode made sub-modes: relative (direct) where offset follows op-code. This used instructions JRxx, CALLR, BTJx. relative (indirect) where offset defined memory, this address follows opcode (ST7 only). target label specified source code level (the assembler computes displacement). High, addressing modes some instances, necessary access highest part address highest bits) lowest part address lowest bits) well. this feature ST7, syntax following: <expression>, where <expression> symbol.H (highest part), symbol.L (lowest part). Examples: lab12 $0012 A,#lab12.h; load with A,#lab12.l; load with STM8, symbols available. high primitives instead example: lab1 $112233 A,#{low{seg lab1}} load with 16/86 Assembler-Linker A,#{high lab1} A,#{low lab1} STM8 addressing modes load with load with 17/86 assembler Assembler-Linker assembler Overview assembler program cross-assembler, meaning that produces code target machine STM8 microprocessor) which different from host machine. assembler turns source code files into re-locatable object modules ready linking. During process, checks many different types errors. These errors recorded ASCII file called cbe.err (Note that linker also writes this file). Error messages explained Appendix Error messages page produce code ready execution, must assembler (ASM), linker (LYN), object code formatter (OBSEND). Source files Source program code written STM8 assembler language saved ASCII text file named source file. source file extension .asm. made lines, each which terminated line character. complete reference STM8 assembler language, refer relevant programming manual. Assembler source code format first line assembler source code file reserved specifying *.tab file target processor. cannot other instructions comments this line. this line specify directory location *.tab file. directory specified, default Assembler searches first current directory, then directory where Assembler's executable located. '.tab' suffix left out, assembler only looks this file type. first line your source code might look like: st7\ c:\sttools\asm\st7\ processor) stm8\ c:\sttools\asm\stm8\ STM8 processor) file st7.tab stm8.tab) cannot found specified default directories, then error produced assembly aborted. rest source code lines have following general format: where <space> refers either SPACE ($20) ($09) character. four fields left blank, <space> fields mandatory unless: whole line blank, line begins comment, line ends before remaining fields. 18/86 Assembler-Linker example: Figure Assembler source code format example examp A,$ffff long addressing mode assembler opcode label operand separator comments next sections describe main components source code file. 4.3.1 Label structure Labels must start column one. label contain following characters: Upper case letters (A-Z) Lower case letters (a-z) Digits (0-9) Underscore first letter label must letter underscore. Note that upper lower case treated differently because assembler case sensitive. Upon assembly, label that exceeds characters truncated warning alerts user that this occurred. When truncated, more labels have same name, phase inconsistency error generated. When labels defined, several attributes defined along with value. These are: Size (Byte, Word Long) Relativity (Linker Relative Absolute) Scope (Internally Externally defined) function each attribute explained following sections. 4.3.2 Label size Defining label's size allows assembler determine what kind addressing mode choose even value associated with label undefined. default size memory location label word bytes). Whenever label suffix, then default size assumed. directives BYTES, WORDS LONGS bytes) allow change default. Regardless default size, define size specific label adding suffix byte, word long. 19/86 assembler Assembler-Linker suffix used when label referred Using suffixes other than results error upon assembly. example: word-size label (default) label1.b byte-size label label2.l long label segment byte `ram' bytes force size label bytes count ds.b byte-size label pointer ds.w byte-size label with word-size space reserved this address 4.3.3 Label relativity There sorts labels: absolute labels relative labels. Absolute labels usually assigned constants, such port addresses, common values used within program. Relative labels defined derived from) external label label derived from position some program code. They exclusively used labels defined within pieces program data. example: ioport start loop absolute label `count' $8000 absolute word label `ioport' segment `eprom' X,#count A,#'*' ioport,A jrne loop stop then loop ever stop Only linker sort actual address code, assembler idea many segments precede this class. assembly time, labels such 'start' 'loop' actually allocated 'blank' values ($0000). These values will filled later linker. Labels such 'count' 'ioport', which were defined absolutely will filled assembler. Source code lines that have arguments containing relative labels marked with listing, showing that they 'linker relative'. Segments discussed Section page 20/86 Assembler-Linker assembler 4.3.4 Label scope Often, multi-module programs, piece code needs refer label that actually defined another module. this, module that exports label must declare PUBLIC, module which imports label must declare EXTERN. directives EXTERN PUBLIC together pair. Most labels program interest other pieces program, these known 'internal' labels since they only used module where they defined. Labels 'internal' default. Here incomplete example modules that pass labels between them: module EXTERN _sig1.w EXTERN _sig2.w PUBLIC _handlers segment byte _handlers: _sig1 _sig2 module EXTERN _handlers.w PUBLIC _sig2 segment byte _sig2: call _handlers import _sig1 import _sig2 export _handlers define _handlers refer _sig1 refer _sig2 import _handlers (addr. word) export _sig2 define _sig2 refer _handlers see, module refers '_sig2' subroutine which defined module Note that when module refers '_sig2' label EXTERN directive specifies WORD size with '.w' suffix. Because assembler cannot look definition '_sig2' told address size explicitly. doesn't need told relativity: external labels assumed relative. Absolute labels declared between modules should defined INCLUDE file that called modules program; this idea using INCLUDE files very important since reduce number PUBLIC symbols, therefore link time, significantly. Lines source code listing which refer external labels marked with given 'empty' values linker fill. short cut, labels declared PUBLIC preceding them with their definition. this done label name need given PUBLIC directive. example, following code fragment declares label 'lab4' PUBLIC automatically: lab3 .lab4 A,#0 21/86 assembler Assembler-Linker 4.3.5 Opcodes Opcode field serve three different purposes. contain: opcode mnemonic assembly instruction. name directive. name macro invoked. Opcodes must separated from preceding field (that label, there one) space tab. comprehensive Opcode description found programming manual. Macros discussed Section page Directives discussed Chapter Librarian page 4.3.6 Operands Operands following: Numbers addresses. String character constants. Program counter references. Expressions. following paragraphs explain these types operands. Number address representation default, representation numbers addresses follows MOTOROLA syntax. When want hexadecimal number with instructions labels, they must preceded When nothing specified, default base decimal. example: lab03 lab04 A,$ffff A,#$cb A,#100 decimal hexadecimal long addressing mode immediate addressing mode decimal representation change Motorola format representation using directives (.INTEL, .TEXAS) indicate setting format. more information, refer Appendix Assembler directives page Caution: Addresses SEGMENT definition always given hexadecimal: segment byte 100-1FF 'test' segment 'test' defined within 256-511 address range. Numeric constants radix Constants need special characters define radix given number. assembler supports MOTOROLA format default. INTEL, TEXAS, ZILOG formats also available format forced .INTEL .TEXAS .ZILOG directives. Table page shows summary these formats. Note: Decimal constants always default, require special characters. 22/86 Assembler-Linker Table Format Motorola Intel Texas Zilog assembler Numeric constants radix formats $ABCD &ABCD 0ABCDh >ABCD %ABCD Binary %100 100b ?100 %(2)100 Octal ~665 665o 665q ~665 %(8)665 Current *(use MULT MULTIPLY) String constants String constants strings ASCII characters surrounded double quotes. example: "This ASCII string" ASCII character constants assembler's arithmetic parser also handles ASCII characters single quotes, returning ASCII given character(s). example: `AB' $4142 characters used within single pair quotes give long constant. following special sequences used denote special characters: `\b' `\f' `\n' `\r' `\t' `\\' `\0' `\"' backspace formfeed linefeed carriage return tabulation slash single-quote null double-quote Program counter reference current value program counter (PC) specified asterisk "*". example: lab05 Expressions operators Expressions numeric values that made from labels, constants, brackets operators. Labels constants have been discussed previous paragraphs. Arithmetic brackets allowed nested levels, curly braces used instead common "()" because instructions parenthesis denote indexed addressing modes. Operators have levels precedence. Operators level (listed Table take precedence over operators level (listed Table each level, operators have same precedence, they evaluated from left right. 23/86 assembler Table Level operators Result, level negated logical logical logical shifted right times shifted left times a<b, else a>b, else a=b, else a>=b, else unequal else a/256, force BYTE type 256, force BYTE type 65536, force WORD*16 type a/65536, force WORD*16 type invert bits invert bits invert bits sign extend byte bits sign extend byte bits sign extend word bits Assembler-Linker Operation high offset bnot wnot lnot sexbw sexbl sexwl Table Level operators Result, level divided divided Operation Table Level operators Result, level multiplied above motorola (character reserved) Operation mult Table Level operators Result, level minus plus Operation 24/86 Assembler-Linker assembler Operator names longer than character must followed space character. example, correct, '1AND2' not. Place curly braces around arithmetic expressions. Always curly braces top-level, when defining numeric expression. doing produce unexpected results. Wrong syntax: #define SIZE DS.W SIZE+1 Wrong, syntax error SIZE Wrong, same SIZE #ENDIF Correct syntax: #define SIZE DS.W {SIZE+1} {SIZE #ENDIF 4.3.7 Comments Comments preceded semicolon. Characters following semicolon ignored assembler. 4.3.8 source code example Below example short source code. st7/ small example module showing source formats ioport $8000 port handshake $9000 write here strobe segment 'program' a,#0 zero counter ioport,x store into ioport segment word FFFC 'code' WORD start worry some directives make sense yet; they will covered soon. Also, take special notice SEGMENT directive. start loop 25/86 assembler Assembler-Linker 4.4.1 Segmentation Segments explained Segments very important. have understand segments before assembler. Take time understand them will save yourself puzzling later. Segmentation 'naming' areas your code making sure that linker collates areas same name together same memory area, whatever order segments object files. different segments defined each module. segment directive itself four arguments, separated spaces: [<name>] example: FILE1: st7/ BYTES segment byte 80-FF `RAM0' ds.b loop counter ds.w address storage ds.b stack allocation ds.b stack grows downward segment byte E000-FFFF `eprom' A,#stack init stack pointer SEGMENT [<align>] [<combine>] '<class>' [cod] counter.b address.b stack FILE2: st7/ serialtemp serialcou segment `RAM0' ds.b ds.b WORDS segment `eprom' A,#0 serial_in preceding example, FILE1 FILE2 separate modules belonging same program. FILE1 introduces classes: 'RAM0' 'eprom'. class-names names choose characters. first time class used, introduced, have declare default alignment, start addresses class, course, name class. Users generally specify class each 'area' their target system. examples above, user class bytes on-chip from 0080 00FF ('RAM0') another 'eprom'. code stored from E000 FFFF ('eprom'). have supply this information very first time class, otherwise only class-name necessary, FILE2. 26/86 Assembler-Linker assembler 4.4.2 Parameters Possible arguments are: Name Align Combine parameter, output file control following paragraphs describe each argument detail, final paragraph describes Copying code. Name <name> argument optional; contain name characters. does, then segments with same name grouped together within their class, order that names defined. Align <align> argument defines threshold which each segment must start. default alignment specified introduction class none specified class introduction then para alignment assumed), although alignment types described Table allowed specified overriding default. Table Type Alignment types Description Examples byte word para page long address Next address boundary Next address 16-byte boundary Next address 64-byte boundary Next address 128-byte boundary Next address 256-byte boundary Next address 4-byte boundary Next address 1k-byte boundary Next address 4K-byte boundary 1001->1002 1001->1010 1001->1040 1001->1080 1001->1100 1001->1004 1001->1400 1001->2000 Looking back example page should able that 'RAM0' class will allocate counter, address, stack FILE1, when linker meets segment FILE2 same class, serialtemp will allocated serialcou same processing happens 'eprom' class segments, second, FILE2, will tacked first FILE1. FILE2 'eprom' class segment specified, say, long align type instead default byte, then that segment would have been next long-word boundary after FILE1 'eprom' class segment. 27/86 assembler Assembler-Linker Combine <combine> argument tells assembler linker treat segment. There three types handle Table Combine types Type at:X[-Y] common <none> Description Starts class from address address common segments that have same class name will start same address. This address determined linker. Follows from last segment this class. at-type <combine> must used introduction class, only once. at-type <combine> must have argument: start address class, optionally given address limit) class too. given, linker checks that items class have gone over limit address; this does occur, warning issued link time. hexadecimal numbers should have radix specifiers. common-type <combine> segments that have same class name will start same address. linker keeps track longest segment. common segments used sharing data across different applications. example: st7/ dat1 com1 .lab1 com1 .lab2 com2 .lab3 com2 .lab4 dat2 .lab5 segment ds.w segment ds.w segment ds.w segment ds.w segment ds.w segment ds.w byte 'DATA' common 'DATA' common 'DATA' common 'DATA' common 'DATA' 'DATA' values labels lab1, lab2, lab3, lab4, lab5 respectively. Note: Since cannot specify both common combines simultaneously, only specify exact location commons insert empty combine segment before first common declaration. example: com1 com1 com1 segment byte 'DATA' segment common 'DATA' segment common 'DATA' 28/86 Assembler-Linker assembler parameter, output file control last field SEGMENT directive controls where linker places code given class. When introducing class, this field specified, code this class sent normal, default.COD file linker. [cod] file given number between then code generated under class being introduced will sent different '.COD' file linker. linker produces file called 'prog.cod', example, then code produced under classes with [cod] field will into that file, normal. class introduced with [cod] field though, then code produced under that class sent instead file prog_1.cod. code produced under other classes sent usual prog.cod. Using this scheme, bank switching schemes quickly directly, even when multiple EPROMs share same addressing space. Simply allocate each EPROM class own, introduce each class with different [cod] field. This will result linker collating EPROM's contents into different .COD file OBSEND independently. example: segment byte at:8000-BFFF 'eprom1' segment byte at:8000-BFFF 'eprom2' Copying code sometimes happens that need copy block code from EPROM RAM. This presents some difficulties because labels that piece code must have addresses, otherwise absolute address references code will point back EPROM copy. this case, helps specify class execution, different class storage, following example: segment byte 'code' segment byte 8000 'ram' segment 'ram>code' label1:nop code starting from label1 will stored code class usual, labels that special segment will given addresses class, memory will also reserved class contents special segment. 29/86 assembler Assembler-Linker Macros Macros assembly-time subroutines. When call execution-time subroutine have through several time-consuming steps: loading registers with arguments subroutine, having saved emptied contents registers necessary, pushing registers used subroutine (with attendant stack activity) returning from subroutine (more stack activity) then popping preserved registers continuing. Although macros don't these problems, they long toward making your program execute faster than using subroutines, cost. cost program size. Each time invoke macro particular job, whole macro assembly code inserted into your source code. This means there stacking return addresses, your program just runs straight into code; obviously feasible this subroutines above certain size. true macros small snippets code that repeatedly, perhaps with different arguments, which formalized into 'template' macros' definition. 4.5.1 Defining macros Macros defined using three directives: MACRO, MEND LOCAL. format <macro-name>MACRO [parameter-1][, parameter-2 [LOCAL] <label-name>[, label-name <body-of-macro> MEND example: add16 MACRO first,second,result A,first A,second result,A MEND piece code example might called add16 index,offset,index which would following statements source code that point: A,index A,offset index.X,A Note: formal parameters given definition have been replaced actual parameters given calling line. These parameters expressions strings well label names constants. Because they complex expressions, they bracketed when there extra numeric activity; this make sure they come with precedence correctly parsed. Macros need have parameters. leave MACRO argument field blank (and, this case, give parameters calling line). 30/86 Assembler-Linker assembler There further problem: because macro called several times same module, labels defined macro will duplicated. LOCAL directive gets around this problem: example: getio loop MACRO LOCAL loop A,$C000 loop MEND This macro creates code loop await port $C000 low. Without LOCAL directive, label 'loop' would defined many times macro called, producing syntax errors assembly time. Because it's been declared LOCAL start MACRO definition, assembler takes care Wherever sees label 'loop' inside macro, changes name 'loop' 'LOCXXXX' where XXXX number from 0000 FFFF. Each time local label used, XXXX incremented. first time getio macro called, 'loop' actually defined 'LOC0', second time 'LOC1' each these being unique reference name. reference 'loop' 'if' statement also detected changed appropriate local variable. directives Table very useful, conjunction with macros: Table Some useful directives Usage implement macro optional parameters. test parameter defined. test parameter label. compare parameter given string. Directive #IFB #IFDEF #IFLAB #IFIDN 4.5.2 Parameter substitution assembler looks macro parameters after every space character. want embed parameter, example, middle label, must precede parameter name with ampersand character, make parameter visible preprocessor. example, have parameter called 'param'., dc.w param works expected, ampersand necessary label¶m:nop label¶m&_¶m:nop Otherwise 'labelparam' would left valid label name; macro parameter 'param' value '5', then 'label5' 'label5_5' would created. 31/86 assembler Assembler-Linker Conditional assembly #IF, #ELSE #ENDIF directives Conditional assembly used choose ignore select whole areas assembler code. This useful generating different versions program setting particular variable INCLUDE file that forces certain pieces code instead others. There three main directives used perform conditional assembly, shown Table Table Directive #ELSE #ENDIF Summary conditional assembly directives Usage Marks start conditional decides whether following zone will assembled not. Optionally reserves condition previous following zone. Marks previous #IF's. condition given with '#IF' take form numeric expression. rule deciding whether resolves 'true' 'false' simple: zero value then false, else true. These directives should start column line, reserved labels. example: {count %OUT 'true' #ELSE %OUT 'false' #ENDIF This sequence would print true label count equal `false' not. example: {count %OUT count more than {count %OUT .and more #ELSE %OUT .but more than two! #ENDIF #ELSE %OUT count more than #ENDIF see, conditionals nested, #ELSE #ENDIF directive assumed apply most recent unterminated #IF. Other special directives available shown Table 32/86 Assembler-Linker Table Directive #IF1 #IF2 #IFDEF #IFB #IFF #IFIDN #IFLAB assembler Other special directives Usage Requires conditional argument. appropriate pass being assembled, condition considered 'true'; instance #IF1 will considered true while assembler first pass, #IF2 while second pass. Checks label definition. Checks empty argument (that empty, containing spaces tabs), useful testing macro parameter existence. False) similar #IF, checks negation condition argument. Tests string equality between arguments separated space. This useful testing macro parameters against fixed strings. Checks argument predefined label. 4.7.1 Running assembler Command line assembler needs following arguments: <file assemble>, <listing file>, <switches> arguments left command line, you'll prompted remaining arguments. example: STMicroelectronics Assembler rel. 4.44 File Assemble: game example above, parameters were given command line, parameters were prompted for. <file assemble> parameter assumes default suffix ".ASM". example, type 'game' then 'game.asm' actual filename used. listing file file which assembly report sent selected. default filename (which displayed square brackets), made from path base-name file assemble. default filename suffix assembly report file ".LST". instance, type 'game', then 'game.lst' actual filename used. Note that unless assembler told create either pass-1 pass-2 complete listing options argument, listing file will created. 4.7.2 Options Options always preceded with minus sign '-'. Upper lower cases accepted define options. Supported options listed Table 33/86 assembler Table Command line options Function Enable symbol table listing (see page Enable pass-2 listing (see page Enable listing specify name .LST file Specify .OBJ file (see page Specify 'final' listing mode (see page #define (see page Assembler-Linker Option -SYM -LI=<listfile> -OBJ=<path> -FI=<mapfile> Specify paths included loaded files (see page Output make rule (see page Enable pass-1 listing (see page Disable phase errors (seepage option Description: Format: Example: Allows generation symbol table. <file> -sym prog -sym output file prog.sym option Description: Format: Request generate complete listing file. specify pathname generated .LST file option -li=<pathname> <file> <file> -li=<pathname> Example: prog output file prog.lst current directory prog -li=obj\prog output file obj\prog.lst option Description: Format: Example: specify pathname generated .OBJ file, using this option: <file> -obj=<pathname> prog -obj=obj\prog Forces assembler generate object file obj\prog.obj. 34/86 Assembler-Linker assembler option Description: side effect using linker that modules assembled separately, leaving inter modules' cross-references fixed linker. result assembler listing file unresolved references displays warning character. option enables perform absolute patch desired listing. Therefore, must have produced listing file (.LST) linked your application compute relocations produce .COD file file. generate full listing, must have made edits since last link (otherwise named map-file would 'out date' module being assembled). This usually problem since full listings only needed after code been completed. automatically selects complete listing. <file> -fi=<file>.map output <file>.lst contains absolute patches. ex1+ex2,ex (produces ex1.lst) (produces ex2.lst) (produces ex.map, ex.cod) (see Chapter Linker page Format: Example: -fi=ex.map (produces ex1.lst) -fi=ex.map (produces ex2.lst) Note: When assembling '-fi' mode, assembler uses file produced linker, object files generated. When using option -fi=<file>.map, assembler step fail under certain circumstances: there empty segments (Error 73). avoid this, comment empty segments. assemble file that been used produce .map file (Error 73). Some EXTERN labels never used (Warning 80). avoid this, comment unused EXTERN labels out. 35/86 assembler Assembler-Linker option Description: Allows specify string that replaced another during assembly. blank space required between string replaced replacement string. example <string> same <string>=2. possible specify only argument <string>). which case, <string> replaced with This extremely useful changing assembly module using directives, because change value tests from assembler's command line. means that assembler with different switches same source file, produce different codes. Format: <file> <string> <string> <file> <string>=<string> <file> <string> Example: EPROM EPROM=2 RAM=3 both cases, EPROM replaced with replaced with EPROM this case EPROM replaced with Note: specify multiple switches, they should always separated space. option Description: Used specify list search paths files that included (with #include) loaded (with #load). paths separated character path list must enclosed within double quotes. also enter multiple include paths using option more than once separating each with blank space. current working directory always searched first. After that, assembler searches directories same order they were specified (from left right) command line. -I="<path1>;<path2>;.;<pathN>" call -I="<path1>" -I="<path2>". -I="<pathN>" call Example: -I="include;include2" call -I="include" -I="include2" call Format: 36/86 Assembler-Linker assembler option Description: Tells assembler output rule suitable make, describing dependencies make object file. given source file, assembler outputs make rule whose target object file name that source file whose dependencies included (#include) source files loaded (#load) binary files uses. rule printed standard output. <source file name> -I="include;include2" call output appears screen rule: call.obj: call.asm include\map.inc include2\map2.inc include\map3.inc include\code.bin Format: Example: option Description: Request generate pass-1 listing. this listing internal forward references known. They marked undefined with listing file. <file> file1 output file file1.lst Format: Example: option Description: Format: Example: Disables error generation. <file> file1 37/86 Linker Assembler-Linker Linker What linker does After having separately assembled component modules your program, next step link them together into .COD file which then sent final destination using OBSEND. This linking process just simple concatenation object modules. resolves external references. referenced label defined PUBLIC, error detected. also checks type relocation places segment according your mapping, checks them overrun. 5.3.1 Invoking linker Command line Arguments linker needs following arguments: [-no_overlap_error] <.OBJ file>[+<.OBJ file>.], [<.COD file>],[<lib>][+<lib>.] -no_overlap_error forces generation .cod executable even some segments overlap. arguments left command line, will prompted. example: STMicroelectronics Linker .OBJ files: begin .COD file [begin.cod]: begin Libraries: 3.00 .OBJ files simply list object files that form your program. .OBJ suffix left out, more than specified they should separated characters, example game+scores+keys would tell linker link game.obj, scores.obj key.obj. Object file path names should include characters. Character should avoided, except suffixes. .COD file default name formed first object file's name with forced suffix .COD. This will name file produced link session. contains information from link session special format: however, OBSEND must used .COD file before ready use. default filename what want, filename given prompt used instead. suffix will forced .COD left blank. default selected leaving this argument blank command line, pressing <ENTER> prompt. Libraries prompt asks list library files generated utility that should searched case finding unresolved external references. format giving multiple libraries same .OBJ list, except suffix .LIB assumed. 38/86 Assembler-Linker Some examples: Linker Linking together modules game.obj, scores.obj, key.obj, game1.obj, game2.obj game3.obj without using libraries generating .COD file named game.cod, requires following command line: Linking same modules same environment, generating .cod file named prog.cod requires following command line: 5.3.2 Response files Response files text files that replace command line generate arguments required. Although they used assembler linker, only really makes sense them linker. command line given with name program execute (here LYN) only take characters argument. most programs this fine, linker allows to128 modules linked run; their names have declared linker first argument. This where response files come they allow redirect command line parser file instead expecting arguments come from command line keyboard. response file invoked giving sign filename response first argument want come from response file. filename assumed have suffix '.RSP' none supplied. Repeating example used earlier, this time with response file called game.rsp: @game.rsp that needs typed, file game.rsp must contain: game+scores+keys+ game1+ game2+game3 prog Which echoes what would have been typed keyboard. response file ends prematurely, remaining arguments prompted keyboard. very large session, .OBJ files argument will line: continued next ending last .OBJ file first line with '+'. Note: When using response files, there must least carriage returns file. 39/86 Linker Assembler-Linker 5.4.1 Linking detail PUBLICs EXTERNs labels declared external modules being linked together must have corresponding PUBLIC definition another module. does not, error. Similarly, there must only PUBLIC definition given label. bulk linker's filling those relative external blanks left assembler .OBJ files; lesser extent, also handles special functions such DATE SKIP directives. Equally important, collate together allocate addresses segments. 5.4.2 Segments linker typical system look like diagram alongside: good candidate four different segments, perhaps named RAM0, RAM1, EPROM ROM. reset interrupt vectors live map, perhaps from FFEE-FFFF then might mark fifth segment called vectors those addresses truncate FFED; that linker will warn much code that overflows into where vectors live. These classes would introduced follows: segment segment segment segment segment byte byte byte byte byte 0-FF 100-027F 8000-BFFF C000-FFDF FFE0-FFFF 'RAM0' 'RAM1' 'EPROM' 'ROM' 'VECTORS' After their full introduction that needs only done once whole program, rest program refer classes just giving class names quotes, example: segment 'RAM0' xtemp time ds.w ds.b temp storage register timer count index segment 'ROM' A,#1 A,#10 this example followed immediately after class instruction 'xtemp' label would given value time would given C000. however, code several modules away from introduction with segments classes 'RAM0' 'ROM', then value allocated labels will depend much space used those modules. linker takes care this allocation. This linker handles problems relocatability; keep mind that this link system going have handle compiled code from high level languages will perhaps begin understand things have generalized much. segments have looked have <name> field, more accurately, they null <name> field. ensure that related segments same class, perhaps scattered over your modules with segments same class collated together contiguous area class memory giving them same name. 40/86 Assembler-Linker example: grafix cursor_buf segment byte 100-027F 'RAM1' ds.b buffer under cursor segment byte 8000-BFFF 'ROM' show_page segment 'RAM1' field-buf ds.b {{256 mult 256}/8} segment 'ROM' dump_buf A,field_buffer grafix segment 'RAM1' cursor_temp ds.b Linker This complex sequence segments shows instances class RAM1 being used with segment name grafix. Because first instance class RAM1 name grafix grafix RAM1 segments placed memory first followed null-name RAM1 segment (which defines field_buf). Note this order segments code, segments with same name collated together (even from separate .OBJ files), lumps segments same name into memory order that names found .OBJ files. explained page your file suffix when introducing class, code that code sent into cod-file named file_x.cod, where file name first file, cod-file suffix (1-9). 5.4.3 Symbol files successful link, more .OBJ files will have been combined into single .COD file. .MAP file will have been produced, containing textual information about segments, classes external labels used .OBJ module(s). Finally compact .SYM file generated, containing PUBLIC symbols found link with their final values. linker supports special feature, link .SYM files from other link sessions. This means that with programs, cannot only partition your code assembler level, divide code into 'lumps' which linked loaded separately, have access each other's label EXTERNs. 'link symbol table simply giving name with suffix .SYM. Always give symbol tables start object file list. file example: prog1.sym+prog2,vectors,irq; Once this done, PUBLIC symbols from prog1.sym available PUBLICs prog2.obj, vectors.obj irq.obj. Because changes link will automatically update references changed link code other links, necessary when using this technique 'fix' each link area memory, have 'jump table' each area. This means that 'function' addresses permanently fixed jump table offset, changes each link will result automatic redirection jump targets start each routine. another way, each link must have entry fixed points routine, otherwise re-linking 'lump' program could make references addresses other modules date. 41/86 Linker Assembler-Linker 5.5.1 linker more detail composition .OBJ files .OBJ files produced assembler contain enormous amount overhead, mostly coded expressions describing exactly what needs into 'blank spaces' assembler been liberal with. linker contains full arithmetic parser working complex expressions that include external labels: this means (unlike most other assemblers) there restrictions where external labels appear. assembler also includes line-number information with .OBJ file, connecting each piece generated object code with line number from given source file. .OBJ files also contain 'special' markers handling SKIP DATE type directive. 5.5.2 composition .COD files .COD files, other hand, contain very little overhead; there bytes segment that describe start address length that segment. Besides that, rest code final form. segment zero length marks file. only remains OBSEND take code segment segment send destination. 5.5.3 Reading mapfile listing linker also generates files with suffix .SYM .MAP addition .COD file have already discussed. .SYM file contains compact symbol table list suitable with debuggers simulators. .MAP file listing shows three important things: table segments with their absolute address, table classes program, list external labels with their true values, modules they were defined size. Here example MAPFILE, where class, ROM, gone past limit, overwriting more correctly, having part itself overwritten VECTORS. [void] some segments segment list says that these segments were used create object code, were used non-coding-creating tasks such allocating label values with ds.b etc. number straight brackets segment true address list shows many segments 'into' module this segment that 1st, etc. given module. first shows range addresses. (line) field external labels list shows source code file line number that this label defined number start each class list line cod-file that class contents were sent (default Segment address list: prog prog main prog main monitor monitor 10888282568844886 1456 01008000C000C509F579FFEE6 875B C508 F578 FFF9 FFFF `RAM0' [void] 'RAM1' [void] 'eprom' 'rom' 'rom' 'rom' 'vectors' 42/86 Assembler-Linker Class list: `RAM0' `RAM1' `eprom' `rom' `vectors' byte from (lim Linker byte from (lim 27F) byte from 8000 875B (lim BFFF) byte from C000 FFF9 (lim FFDF) C*Overrun* byte from FFEE FFFF (lim FFFF) 100% external label list only includes labels that were declared PUBLIC: labels used internally module included. This table most useful debugging purposes, since values labels likely relocated between assemblies. labels given first-character-alphabetic order. External label list: Symbol Name char char1 label labels Value ABCD Size BYTE BYTE WORD Def(line) game.obj(10) game.obj(11) game.obj(25) 43/86 OBSEND Assembler-Linker OBSEND What OBSEND does After your program been assembled linked form .COD file must sent place where will executed. Right now, your code just stored file disk where target system cannot OBSEND general purpose utility .COD files various ways using various formats. Invoking OBSEND OBSEND follows same standard formats rest assembler linker; arguments given from command line, keyboard response file. general syntax OBSEND where <file> name .COD file formatted (default extension .COD). filename given command line, prompted keyboard with: OBSEND STMicroelectronics Obsend rel. .2.00 File Send: test Destination Type (<f>ile,<v>ideo): Final Object code Filename [test.fin]: test.s19 Object Format <ENTER>=Straight Binary, <2>, <4>: 6.2.1 Destination type <destination> (file) (video). Only single character required. 6.2.2 Destination arguments When destination type (file) argument <filename> tells OBSEND where send code. default suffix .FIN assumed none given. example: OBSEND test,f,image.s19,s command generates file image.s19 containing code from test.cod, Srecord format. When destination code (video), this field void. 6.2.3 Format definitions <format> specifies output format. Output format options listed Table 44/86 Assembler-Linker Table Output formats Output format straight binary, that bit-for-bit image Intel Intel with bytes data line Intel extended Motorola S-record byte address, example ST7) Motorola S-record extended with symbol file S-record bytes address, example D950) OBSEND <format> <none> S-record bytes address, example ST18932 program space) 'Filled' straight binary format industrial binary format 6.2.4 Straight binary format <format>= <none> This simplest formats. nothing bit-for-bit copy original file. This usual mode sending EPROM emulators, etc., default format argument given. Note: When destination screen (the destination code "v"), this format; otherwise weird control codes. <format>= This `filled' straight binary format where gaps between adjacent segments filled with $FF. 6.2.5 Intel format <format>= This format very much more complex. Intel bears similarities S-record that look later. Let's look line Intel format detail: number data bytes decimal) 1900 address record type data bytes checksum first thing note that everything printable ASCII. Eight-bit numbers converted into two-character hexadecimal representation. Each line begins with ASCII ($3A) character. next characters form byte that declares many data bytes follow data byte section little further along. 45/86 OBSEND Assembler-Linker next four characters form 16-bit high-byte first number that specifies address first byte this data; rest follows sequentially. next characters record type this line: data line, signals EOF. following characters, until last two, data bytes this line, last checksum line, calculated starting with subtracting real value characters sent after until checksum itself. 'Real value' means that example, characters should subtract from checksum, Every line ends with CR-LF combination, $0D. last line sent must END-OF-FILE line, which denoted line with data bytes record type instead Giving instead intel argument uses same format, sends bytes data line. 6.2.6 Motorola S-record format <format>= This another complex method sending data. Again cuts data into 16-byte 'records' with overhead both sides. S-record come four types: known header record, data records with 24-bit address fields, records with 24-bit address fields. Note: convention close 16-bit data record with 16-bit record, close 24-bit data record with 24-bit record. S10D0010E0006285E000628562856D record type number bytes left,address,data checksum decimal) 0010 address data bytes checksum first characters define record type: next characters form hexadecimal representation numbers bytes left record (that numbers characters This count must include checksum addresses bytes that follow. address field four characters wide characters wide most significant character always comes first. OBSEND always uses type records wherever possible (that when address less than $10000) type data records where (that address $FFFF). data bytes then follow, with checksum appended end. checksum calculated starting with subtracting 'real value' bytes sent from including byte count field until checksum itself. this context, 'real value' means value byte before expanded into ASCII characters. record concluded CR-LF combination $0A, $0D. (that header EOF) records always same: S00600004844521B and: S804000000FB S9030000FC 46/86 Assembler-Linker complete example S-record transmission look like: S00600004844521B S20801C004FFC0000073 <format>= OBSEND extended S-record format, selected format sends code described above, except that after sends list records, after other, format: 0000 LABEL where 0000 four ASCII zeroes, LABEL five ASCII characters. There spaces after space after 0000. 0000 represents hexadecimal value label. LABEL extend characters, with carriage return. 6.2.7 S-record formats <format>= <format>= These industrial formats defined specific needs: specify 2-byte words address. specify 4-byte words address. 6.2.8 binary <format>= This format simple. 16-byte count beginning low-byte first, calculated starting adding value each byte until data reached. there 'gaps' your code, OBSEND fills them with $FF, adjusts checksum accordingly. After four bytes header information, data follows block. 47/86 Librarian Assembler-Linker Librarian Overview work similar boards especially those with same processor, makes great deal sense reuse lumps code have already written same task different program. simplest level, could just copy source code block text into program. This works fine, subtle disadvantage: update subroutine, have hunt around usages performing update each. around this problem, many people have source common routines place, link .OBJ module with each program needing routine. Then only need update source code once, reassemble .OBJ file, then link again users routine, will have .OBJ file. While this scheme works well, generates some problems own. example, each routine needs .OBJ file. nature, these common routines tend small, giving dozens extra .OBJ modules linker, having .OBJ modules scattered around your hard disk. base concept librarian combine these small, useful .OBJ modules into large .LIB library file. could then tell linker about library, takes care which .OBJ modules pull link. would know which ones pull fact that main code being linked would have undefined externals, example, call missing library routines. librarian simply takes each undefined external turn, checks against modules library. modules declares PUBLIC same name, knows need that .OBJ module includes automatically. Invoking librarian librarian called LIB, takes command line argument that name library operate given, prompted [library name] .LIB added suffix left off. library indicate does exist, asks library. example: LIB1 STMicroelectronics Librarian 1.00 Couldn't open Library file 'LIB1.LIB' file? (y/n): answer 'n', aborts. library exists, prints report library. Library LIB1.LIB long. 16/1024 Public labels used 2/128 modules. Next comes main prompt: LIB1.LIB: Operation (<ENTER> help): Pressing ENTER gives access options shown Table 48/86 Assembler-Linker Table Library file options Description Add/update object module to/in library Delete object module from library Update object module library Copy object module separate file from library List contents library Exit Librarian Operation +filename -filename !filename *filename Adding modules library Typing example: +user1\board would look file, called user1\board.obj, library. cannot find named file, reports fact returns operations prompt. Else issues following message: Adding board.obj labels added Done. library already contains file board.obj, prompts with: board.obj already library LIB1.LIB, replace with board.obj (Y/N): Responding with returns operations prompt, while first removes board.obj then continues above. Deleting modules from library This done example: -board cannot find board.obj current library, reports error aborts back operation prompt. find makes sure know what doing with: board.obj deleted from library LIB1.LIB:Are sure (Y/N): aborts operation prompt. continues, reporting: Removing board.obj Done. 49/86 Librarian Assembler-Linker Copying modules from library make copy .OBJ module located library back your hard disk, use, example: *board This checks existence board.obj current library, reports failure aborts operation prompt. does find invites give name hard disk file create contain copy .OBJ module. Copy into .obj file [board.obj]: type <ENTER>, selects original name object module copy's name. Otherwise, give path spec. file give already exists, says: File board.obj already exists; overwrite? (Y/N): Again, responding aborts operations prompt, while does copy with message: Copying board.obj disk. Done. Getting details your library last operation: causes print details current library. Library LIB1.LIB long 16/1024 Publics labels used 2/128 modules z1.obj (z1.asm) length board.obj (board.asm) length 7FFF name brackets source module from which named object module assembled. 50/86 Assembler-Linker Definitions Table Name Application board Definitions Acronyms terms used this document Definition This printed circuit board onto which wish connect target MCU. should include socket footprint that connect application board your emulator development using probe appropriate device adapter. This allows emulate behavior real application order debug your application program. Device adapters included your emulator allow connect emulator your application board. type device adapter depends target device's packaging. Many MCUs come least different packages, should therefore device adapter that corresponds type package have chosen your application. Dual line. Designates type device package with rows pins thru-hole mounting. Sometimes also called (dual in-line package). Extended capabilities port communication standard. Enhanced parallel port communication standard. Least significant byte 16-bit value. This main board emulator that common entire HDS2 family emulators. controls common functions such communication with your parallel port. Memory location. Mnemonic. Microcontroller unit. Otherwise referred target device throughout this manual. This core product family products) which Development designed emulator programming tool. general terms, complete computer system, including CPU, memory, clock oscillator single integrated circuit. printed card having connector pins that allow connect emulator socket user application board. Using active probe allows HDS2 emulator function were target device embedded your application. probe connected emulator flat cables. program counter register that holds address next instruction operand that will use. Stack pointer LSB. Uses short 8-bit addressing mode. Small outline. Designates type device package with rows pins socket mounting. example, SO34 designates 34-pin device this package type. source Device adapter Main board mnem ST7MDT6active probe short visual graphic debugger software package that allows debug applications destined debug (STVD7) family MCUs, either using built-in simulator function, Development HDS2 Emulator. Target device This that wish your application, which your emulator development will emulate you. User application Designates your application board. board 51/86 Assembler directives Assembler-Linker Appendix Assembler directives Each directive described table. name directive given table title (and always appears Format). Format shows arguments allowed any) this directive. Description describes action directive format nature argument specified Format. Example gives more example directive use. also lists possible cross references. directives must placed second, OPCODE, field, with arguments away argument field. Table Directive .BELL BYTE BYTES CEQU .CTRL DATE DC.B DC.W DC.L #DEFINE DS.B DS.W DS.L EXTERN #ELSE #ENDIF .FORM List directives Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Directive GROUP #IF1 Conditional #IF2 #IFB #IFIDN #IFDEF #IFLAB #INCLUDE INTEL INTERRUPT .LALL .LIST #LOAD LOCAL LONG LONGS MACRO MEND MOTOROLA NEAR Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Directive .NOCHANGE .NOLIST %OUT .PAGE PUBLIC REPEAT .SALL SEGMENT .SETDP SKIP STRING SUBTTL .TAB TEXAS TITLE UNTIL WORD WORDS .XALL ZILOG Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table 52/86 Assembler-Linker Assembler directives Directives Table Purpose Format .BELL Ring bell console. .BELL This directive simply rings bell console; used signal Description pass-1 pass-2 with #IF1 #IF2. This directive does generate assembly code data. Example also .BELL Table Purpose Format BYTE Define byte object code. BYTE <exp "string">,[,<exp "string">.] This directive forces byte(s) argument list into object code current address. argument composed complex expressions, which even include external labels. argument expression value greater Description than then lower bits expression used errors generated. String argument(s) must surrounded double quotes: theses translated into ASCII processed byte byte. generally used defining data tables. Synonymous with STRING DC.B. Example also BYTE 1,2,3 generates 01,02,03 BYTE "HELLO" generates 48,45,4C,4C,4F BYTE "HELLO",0 generates 48,45,4C,4C,4F,00 DC.B, STRING, WORD, LONG, DC.W, DC.L Table Purpose Format BYTES Label type definition where type byte. BYTES When label defined, separate attributes defined with scope (internally externally defined), value (actual numerical value label), relativity (absolute relative), length, (BYTE, WORD LONG). these attributes, except length, defined explicitly before definition. force label certain length giving suffix, 'label.b' forces Description byte length. also define default state label length: labels created this length unless otherwise forced with suffix. default WORD start assembly, changed BYTES, WORDS LONGS appropriate length. Example also BYTES lab1 byte length lab1 LONGS, WORDS 53/86 Assembler directives Table Purpose Format Description Example also Assembler-Linker CEQU Equate pre-existing label expression. label CEQU <exp> This directive similar EQU, allows change label's value. Used macros counter REPEAT UNTIL. lab1 CEQU {lab1+1} lab1 EQU, REPEAT, UNTIL Table Purpose Format .CTRL Send control codes printer. .CTRL <ctrl>[,<ctrl>]. This directive used send printing printing control codes selected listing device. It's intended sending control codes embolden underline, etc. Description areas listing printer. arguments sent listing device listing currently selected. This directive does generate assembly code data. Example also .CTRL 27,18 .LIST, .NOLIST, .BELL Table Purpose Format DATE Define 12-byte ASCII date into object code. DATE This directive leaves message linker place date link 12-byte block assembler leaves spare position DATE directive. This means that every link will leave date object code, allowing automatic version control. Description date takes form ASCII) DD_MMM_YYYY where character represents space; example JUL. 1988. date left linker fill instead assembler since source code module containing DATE directive reassembled after every editing session would possible lose track. Example also DATE Table Purpose Format DC.B Define byte(s) object code. DC.B <exp "string">,[,<exp "string">] This directive forces byte(s) argument list into object code current address. argument composed complex expressions, which even include external labels. argument expression value greater Description than then lower bits expression used errors generated. String argument(s) must surrounded double-quotes: these translated into ASCII processed byte byte. It's generally used defining data tables. Synonymous with BYTE STRING. Example also DC.B 1,2,3 generates 01,02,03 DC.B "HELLO" generates 48,45,4C,4C,4F DC.B "HELLO",0 generates 48,45,4C,4C,4F,00 54/86 Assembler-Linker Table Purpose Format Assembler directives DC.W Define word(s) object code. DC.W<exp>[, <exp>.] This directive forces word(s) argument list into object code current address. arguments composed complex expressions, which even include external labels. argument expression value greater Description than FFFF then lower bits expression used errors generated. DC.W sends words with most significant byte first. It's generally used defining data tables. Synonymous with WORD, except that DC.W places words High order. Example also DC.W 1,2,3,4,$1234 ;0001,0002,0003,0004,1234 DC.B, BYTE, STRING, WORD, LONG, DC.L Table Purpose Format DC.L Define long word(s) object code. DC.L <exp>[,<exp>.] This directive forces long word(s) argument list into object code current address. arguments composed complex expressions, which even include external labels. argument expression value greater Description than FFFFFFFF then bits expression used errors generated. DC.L sends words with most significant byte first. It's generally used defining data tables. Synonymous with LONG, except that DC.L stores long-words High order. Example also DC.L 1,$12345678 LONG 1,$12345678 0000,0001,1234,5678 0100,0000,7856,3421 DC.B, DC.W, BYTE, STRING, WORD, LONG Table Purpose Format #DEFINE Define manifest constant. #DEFINE <CONSTANT <real characters> benefits using labels assembler level programming obvious well known. Sometimes, though, values other than straight numerics allowed labels used repeatedly programs ideal candidates special labelling. #DEFINE directive allows define special labels called 'manifest constants'. These basically labels that contain strings instead numeric constants. During Description assembly, wherever manifest found source code, replaced real argument before assembly proceeds. #DEFINE definition label, space must precede declaration. number defines that Assembler manage limited 4096. However, this depends number characters statements. Depending their length, reach this limit sooner. Example also #define value a,#value a,#5 55/86 Assembler directives Table Purpose Format Assembler-Linker DS.B Define byte space object code. DS.B [optional number bytes] This directive used 'space out' label definitions. example let's need byte-sized temporary storage locations defined RAM, starting address $4000. could write: segment byte 4000 'RAM' temp1 $4000 temp2 $4001 which would work fine, however, recommend write: segment byte 4000 'RAM' Description temp1 DS.B temp2 DS.B which does same job. advantage that increments automatically. There other types instructions available doing WORD LONG length storage areas: DS.W DS.L. Note that areas question initialized value; it's merely allocating values labels. optional argument specifies many bytes allocate; default Because code generated fill space, allowed DS.B segments containing code, only segments with data definitions. Example also labl DS.W, DS.L DS.B Table Purpose Format DS.W Define word space object code. DS.W [optional number words] This directive used 'space out' label definitions. example let's need word-sized temporary storage locations defined RAM, starting address $4000. could write: segment byte 4000 'RAM' temp1 temp2 $4000 $4002 which would work fine, however, recommend write: segment byte 4000 'RAM' Description temp1 temp2 DS.W DS.W which does same job. advantage that increments automatically. There other types instructions available doing BYTE LONG length storage areas: DS.B DS.L. Note that areas question initialized value; it's merely allocating values labels. optional argument specifies many bytes allocate; default Because code generated fill space, allowed DS.W segments containing code, only segments with data definitions. Example also labl DS.B, DS.L DS.W 56/86 Assembler-Linker Table Purpose Format Assembler directives DS.L Define long space object code. DS.L [optional number long words] This directive used 'space out' label definitions. example let's need long-word-sized temporary storage locations defined RAM, starting address $4000. could write: segment byte 4000 'RAM' temp1 temp2 $4000 $4004 which would work fine, however, recommend write: Description temp1 temp2 segment byte 4000 'RAM' DS.L DS.L which does same job. advantage that increments automatically. There other types instructions available doing BYTE WORD length storage areas: DS.B DS.W. Note that areas question initialized value; it's merely allocating values labels. optional argument specifies many bytes allocate; default Because code generated fill space, allowed DS.L segments containing code, only segments with data definitions. Example also labl DS.L DS.B, DS.W Table Purpose Format source code. This directive marks assembly main source code file. Description directive supplied source-code file then illegal error will generated assembler. Include files require directive. Example also 57/86 Assembler directives Table Purpose Format Assembler-Linker Equate label expression. label <EXPRESSIONS> Most labels created program attached source code line that generates object code, used target jumps memory references. rest labels used 'constants', used example, hold port number system keyboard: number that will remain constant throughout program. Description directive allocates value, segment type length label field. value derived from result expression, relativity (absolute segmentrelative derived from most recent segment), length BYTE, WORD LONG, derived from size default (starts WORD changed directives BYTES, WORDS LONGS). Example also labl Table Purpose Format EXTERN Declare external labels. EXTERN When your program consists several modules, some modules need refer labels that defined other modules. Since modules assembled separately, until link stage that necessary label values going known. Whenever label appears EXTERN directive, note made linker resolve reference. Declaring label external telling assembler expect label Description defined this module, although will used. Obviously, external labels must defined other modules link stage, that gaps left assembler filled with right values. Because labels declared external actually defined, assembler knowing length, (byte, word long) label. Therefore, suffix must used each label EXTERN directive declaring type; type undefined, current default label scope (set BYTES, WORDS, LONGS directives) assumed. Example also PUBLIC EXTERN label.w, label1.b, label2.l 58/86 Assembler-Linker Table Purpose Format Assembler directives #ELSE Conditional ELSE. #ELSE Forces execution statements until next #ENDIF last statement found false disables execution statements until next #ENDIF last Description statement found true. #ELSE optional #ENDIF structures. case nested #ELSE statements, #ELSE refers last #IF. Example #ELSE block assembled #ENDIF also #IF, #ENDIF block assembled Table Purpose Format #ENDIF Conditional terminator. #ENDIF This optional terminator structure. there only level nesting force, then statements after this directive will never ignored, matter what result previous was. other words, #ENDIF ends Description capability previous suppress assembly. When used nested situation does same job, last #ENDIF structure block source suppressed previous still force, whole last #ENDIF structure will ignored matter what result previous was. Example also {count #ENDIF #IF, #ELSE Table Purpose Format (STM8 only) Specifies debuggers that return address stack functions using this directive written over three bytes. <"string"> This directive used with functions called CALLF, whose return stack address Description spans three bytes. Every function called CALLF must classified FAR. This directive with STM7 Assembler only. Example also PUBLIC func func func retf NEAR, INTERRUPT 59/86 Assembler directives Table Purpose Format Assembler-Linker Form constant string. <"string"> |<bytes> [<"string"> |<bytes>]. This directive works same common STRING directive, except that Description last character string argument (for example MSB) forced high. Numeric arguments same list left untouched. Example also STRING "ALLO" STRING "ALLO" 41,4C,4C,CF 41,4C,4C,4F Table Purpose Format .FORM form length listing device. .FORM <exp> assembler paginates listing (when selected) with default lines Description page. This directive changes page length from default. This directive does generate assembly code data. Example also .FORM TITLE, SUBTTL, %OUT, .LALL, .XALL, .SALL, .LIST,.NOLIST Table Purpose Format GROUP Name area source code. GROUP <exp> source code following GROUP directive until next GROUP directive Description file 'belongs' named group. Source code included inside group allocated special group called 'Default'. Example also GROUP mainloop 60/86 Assembler-Linker Table Purpose Format Assembler directives Start conditional assembly. <exp> Sometimes necessary have different versions program macro. This achieved completely SEPARATE programs macros, this solution associated problem that changes part program common versions requires them being changed, which tedious. Conditional assembly offers solution controlled 'switching off' assembly source code, depending value numeric expressions. structure known 'IF/ELSE/ENDIF': example format. Description #ELSE statement optional. expression resolves expression assumed have 'false' result: source code between false next #ENDIF #ELSE supplied) will assembled. #ELSE supplied, code following #ELSE will assembled only condition false. Conditionals nested levels: when nesting them, keep mind that each must have #ENDIF level, that #ENDIFs #ELSEs refer last unterminated #IF. %out true #FALSE %out false #ENDIF #ENDIF, #ELSE, #IF1, #IF2 Example also Table Purpose Format #IF1 Conditional Conditional being pass #IF1 This directive works just like except argument only evaluates itself Description true assembler first pass through source code. #ELSE requires #ENDIF. Example also #IF1 %OUT "Starting Assembly" #ENDIF #IF2, #ELSE, #IF, #ENDIF Table Purpose Format Description #IF2 Conditional being pass #IF2 This directive works just like except argument evaluates itself true only assembler second pass through source code. #IF2 %OUT "GONE through PASS-1 #ENDIF #IF1, #IF, #ENDIF, #ELSE Example also 61/86 Assembler directives Table Purpose Format Description Assembler-Linker #IFB Conditional argument being blank. #IFB <arg> This directive works just like except doesn't evaluate argument: simply checks empty blank. Spaces count blank. check MACRO param1 #IFB param1 %OUT param1" #ELSE %OUT param1 #ENDIF MEND check check Example also #IF2, #ELSE, #IF, #END Table Purpose Format Description #IFIDN Conditional arguments being identical. #IFIDN <arg-1> <arg-2> This directive works just like except compares strings separated space. identical, result true. check MACRO param1 #IFIDN param1 HELLO %OUT "Hello" #ELSE %OUT Hello" #ENDIF MEND Example also #IF2, #ELSE, #IF, #END Table Purpose Format #IFDEF Conditional argument being defined. #IFDEF <exp> Description This directive works just like except tests argument being defined. check MACRO param1 #IFDEF param1 %OUT "Arg #ELSE %OUT "Arg undefined" #ENDIF MEND Example also #IF2, #ELSE, #IF, #END 62/86 Assembler-Linker Table Purpose Format Description Assembler directives #IFLAB Conditional argument being label. #IFLAB <arg> This directive works just like except tests that argument valid, predefined label. check MACRO param1 #IFLAB param1 %OUT "LABEL" #ENDIF MEND Example also #IF2, #ELSE, #IF, #END Table Purpose Format #INCLUDE Insert external source code file. #INCLUDE "<filename>" INCLUDE files source code files same format normal modules with important differences: first line usually reserved processor name like other source line, they have directive. They used contain #DEFINE macro definitions that used many different modules your program. Instead having each module declare #DEFINE macro definitions, Description each module just includes contents same #INCLUDE file. assembler goes named INCLUDE file assembles this file before returning line after #INCLUDE directive former source code file. benefit that alterations made macro must done once, include file; you'll still have reassemble modules referring changed entry. NOTE that filename must inside double-quotes. st7/ Example #include "defst7.h" also Table Purpose Format INTEL Force Intel-style radix specifier. INTEL Intel style: 0ABh Hexadecimal Octal Description 100b Binary Decimal (default) Current program counter This directive forces Intel format required during assembly. Example also INTEL X,0FFFFh MOTOROLA, TEXAS, ZILOG 63/86 Assembler directives Table Purpose Format Description Assembler-Linker INTERRUPT Specifies debugger that routine interrupt rather than function. INTERRUPT <string> This directive used with interrupt handlers aids debugger correctly searching stack return address interrupted function. PUBLIC trap_handler INTERRUPT trap_handler trap_handler IRET NEAR, Example also Table Purpose Format Description Example also .LALL List whole body macro calls. .LALL This directive forces complete listing macro expansion each time macro invoked. This default. This directive does generate assembly code data. .LALL .XALL, .SALL Table Purpose Format .LIST Enable listing (default). .LIST This directive switches listing previous .NOLIST disabled -'pa' -'li' options must also have been from command line generate listing. This Description directive, conjunction with directive .NOLIST, used control listing macro definitions. This directive does generate assembly code data. Example also .NOLIST .LIST Table Purpose Format #LOAD Load named object file link time. #LOAD "pathname\filename[.ext]" This directive leaves message linker load contents named file current position current segment. file should 'straight binary' Description format, that direct image bytes want object code. should Motorola (.s19) Intel (.hex) format. Example also segment byte 8000-C000 'EPROM1' #LOAD "table.bin" 64/86 Assembler-Linker Table Purpose Format Assembler directives LOCAL Define labels local macro. LOCAL <arg> macro that generates loop code gives rise assembly problem since loop label would defined many times macro called. LOCAL directive enables overcome this difficulty. Consider following piece code: waiter MACRO loop A,ads jrne loop MEND this macro called twice, will creating labels called 'loop'. answer declare very early MACRO labels created macro LOCAL. This effect replacing actual name local label (here 'loop') with LOCXXXX where XXXX starts from increments each time local label used. This provides each occurrence labels created inside macro with unique identity. waiter MACRO LOCAL loop loop Aids drone loop MEND MACRO, MEND Description Example also Table Purpose Format LONG Define long word object code. LONG <exp>[,<exp>.] This directive forces long word(s) argument list into object code current address. arguments composed complex expressions, which even include external labels. argument expression value Description greater than FFFFFFFF then bits expression used errors generated. LONG sends long words with least significant byte first. It's generally used defining data tables. Synonymous with DC.L, except that LONG sends low-byte first. Example also DC.L 1,$12345678 LONG 1,$12345678 0000,0001,1234,5678 0100,0000,7856,3421 DC.B, DC.L, DC.W, BYTE, STRING, WORD 65/86 Assembler directives Table Purpose Format Assembler-Linker LONGS Default label length long. LONGS When label defined, four SEPARATE attributes defined with scope (internally externally defined), value (actual numerical value label), relativity (absolute relative), lastly, length (BYTE, WORD LONG). these attributes except length defined explicitly before definition: force label certain length giving suffix, Description example 'label.b' forces byte length. also define default state label length: labels created this length unless otherwise forced with suffix. default WORD start assembly, changed BYTES, WORDS LONGS appropriate length. Example also LONGS lab1 long length lab1 BYTES, WORDS Table Purpose Format MACRO Define macro template. <macro> MACRO [param-1][,param-2]. This directive defines macro template that invoked later program. label field holds name macro: this name used invoke rest macro whenever found opcode field. arguments dummy names Description parameters that will passed macro when used: these dummy names will replaced actual calling line's arguments. Note: don't want definition macro listed, insert directive .NOLIST before macro definition, append directive .LIST after macro definition. cmp16 MACRO first,second,result LOCAL trylow A,first A,second A,#0 jreq trylow result,A MEND Example trylow also MEND, .LALL, .SALL, .XAL 66/86 Assembler-Linker Table Purpose Format Assembler directives MEND macro definition. MEND Description macro definition. cmp16 MACRO first,second,result LOCAL trylow A,first A,second A,#0 jreq trylow result,A MEND Example trylow also MACRO Table Purpose Format MOTOROLA Force Motorola-style radix specifier. MOTOROLA Motorola style: Hexadecimal Octal %100 Binary Description Decimal (default) Current program counter This directive forces Motorola format required during assembly. default format MOTOROLA. Example also MOTOROLA X,$FFFF INTEL, TEXAS, ZILOG Table Purpose Format NEAR Specifies debuggers that return address stack functions using this directive written over bytes. NEAR <"string"> This directive used with functions called CALL CALLR, whose return stack Description address spans bytes. Every function called CALL CALLR must classified NEAR. Example also PUBLIC func NEAR func func FAR, INTERRUPT 67/86 Assembler directives Table Purpose Format Assembler-Linker .NOCHANGE List original #define strings. .NOCHANGE Strings named first argument #DEFINE directive will changed second argument #DEFINE: default that changed strings will listed. Description want original source code listed instead, place .NOCHANGE directive near start your source code. This directive does generate assembly code data. Example also #DEFINE .NOCHANGE Table Purpose Format .NOLIST Turn listing. .NOLIST Certain parts your modules required listing; this directive disables listing until next .LIST directive. default listing enabled. This Description directive, conjunction with directive .LIST, used control listing macro definitions. This directive does generate assembly code data. Example also LIST .NOLIST Table Purpose Format Description Example also %OUT Output string console. %OUT string This directive prints argument (which does need enclosed quotes) console. This directive does generate assembly code data. %OUT hello! Table Purpose Format .PAGE Perform form feed. .PAGE Description Forces page listing. This directive does generate assembly code data. Example also .PAGE 68/86 Assembler-Linker Table Purpose Format Assembler directives PUBLIC Make labels public. PUBLIC <arg> This directive marks given labels defined during assembly 'PUBLIC', accessible other modules. This directive related EXTERN; module wants label defined another, then other module must have that label Description declared PUBLIC. label also declared PUBLIC definition preceding label name with dot; won't need declared PUBLIC directive then. module1.asm EXTERN print.w, print1.w call print print1 module2.asm PUBLIC print print .print1 EXTERN Example also Table Purpose Format Description Example also REPEAT Assembly-time loop initiator. REPEAT Used together with UNTIL make assembly-time loops; useful making tables etc. This directive should used within macros. REPEAT CEQU, UNTIL Table Purpose Format .SALL Suppress body called macro. .SALL This directive forces complete suppression listing macro expansion Description each time macro invoked. This instruction never listed. Note:This directive produce confusing listings. Example also .SALL .LALL, .XALL 69/86 Assembler directives Table Purpose Format Assembler-Linker SEGMENT Start segment. [<name>] SEGMENT <align> <combine> '<class>' [cod] SEGMENT directive very important: every module your program will need least one. Description <name> field characters length, include underscores. <align> field following: byte alignment; start byte boundaries word aligned next word boundaries necessary, i.e., 8001=8002 para aligned next paragraph (=16 bytes) boundary, i.e., 8001=8010 aligned next 64-byte boundary, i.e., 8001=8040 aligned next 128-byte boundary, i.e., 8001=8080 page aligned next page (=256 bytes) boundary, i.e., 8001=8100 long aligned next long-word(=4 bytes) boundary, i.e., 8001=8004 aligned next boundaries, i.e., 8001=8400 aligned next boundaries, i.e., 8001=9000 X[-Y] Introduces class that starts from goes through address Address optional. <none> Tack this code last segment this class. common segment same address than other common segments that have same name, note longest length segment. optional [cod] suffix number from decides into which. file linker sends contents this class. default chosen suffix left off. suffix will cause linker open [cod] suffix, send contents this class into file instead default. This allows bank switching supported directly link level- different code areas same address separated into different .cod files. Example also Table Purpose Format .SETDP base address direct page. .SETDP <base address> have used processor, aware 'zero-page' 'direct' addressing modes. These addresses range 00.FF shorter, faster instructions than more general 0000.FFFF versions. Other processors same scheme, with twist: choose 'base page' where direct mode Description does have range 0000 00FF from nn00.nnFF where nn00 'base page', loaded into register run-time. Because assembler cannot track what's base page register run-time, need fill about current 'base page' with .SETDP directive. start assembly, SETDP defaults 0000. Example also .SETDP $400 A,$401 direct mode chosen 70/86 Assembler-Linker Table Purpose Format Assembler directives SKIP Inserts given number bytes with initialization value. SKIP <number bytes>,<value fill> This directive leaves message linker that want number bytes Description inserted into object code this point. Both arguments must absolute values rather than external relative values. Example also SKIP 100,$FF insert bytes Table Purpose Format STRING Define byte-level string. STRING <exp "string">,[,<exp "string">.] This directive forces byte(s) argument list into object code current address. arguments composed complex expressions, which even include external labels. argument expression value greater Description than lower bits expression used errors generated. String argument(s) must surrounded double-quotes: these translated into ASCII processed byte byte. It's generally used defining data tables. Synonymous BYTE DC.B. Example also STRING 1,2,3 generates 01,02,03 STRING "HELLO" generates 48,45,4C,4C,4F STRING "HELLO",0 generates 48,45,4C,4C,4F,00 DC.B, BYTE, WORD, LONG, DC.W, DC.L, Table Purpose Format SUBTTL Define subtitle listing heading. SUBTTL "<Subtitle string>" This directive related TITLE directive: argument used subtitle beginning each page listing. recommend that individual subtitles Description generated each module program, while TITLE defined once include file called modules. This directive does generate assembly code data. Example also TITLE SUBTTL "A/D control routines" Table Purpose Format .TAB listing field lengths. .TAB Sets size four source code fields listings. defaults 80-column printer; yours wider, need tell assembler using this Description directive. four fields width label field, opcode field, operand comment. This directive does generate assembly code data. Example also .tab 10,6,16,40 .LIST, .NOLIST 71/86 Assembler directives Table Purpose Format Assembler-Linker TEXAS Texas Instruments-style radix specifier. TEXAS Motorola style: Hexadecimal Octal Binary Decimal (default) Current program counter Description ?100 This directive forces Texas Instruments format required during assembly. Example also TEXAS X,>FFFF INTEL, MOTOROLA, ZILOG Table Purpose Format TITLE Define main title listing. TITLE "<Title string>" first fifty-nine characters argument (which must enclosed doublequotes) will included first line each page listing main title Description listing. suggest title include file called each module your program, give each module separate subtitle (see SUBTTL section). This directive does generate assembly code data. Example also SUBTTL TITLE "ST7 controller program" Table Purpose Format UNTIL Assembly time loop terminator. UNTIL <exp> Related REPEAT directive: expression argument resolves zero Description value then assembler returns line following last REPEAT directive. This directive cannot used inside macros. Example also CEQU REPEAT DC.L mult val} CEQU {val+1} UNTIL {val CEQU, REPEAT 72/86 Assembler-Linker Table Purpose Format Assembler directives WORD Define word object code. WORD <exp>[, <exp>.] This directive forces word(s) argument list into object code current address. arguments composed complex expressions that even include external labels. argument expression value greater Description than FFFF then lower bits expression used errors generated. WORD sends words with least significant byte first. It's generally used defining data tables. Synonymous with DC.W. Example also WORD 1,2,3,4,$1234 ;0001,0002,0003,0004,1234 DC.B, BYTE, STRING, DC.W, LONG, DC.L Table Purpose Format WORDS Default label length word. WORDS When label defined, four SEPARATE attributes defined with scope (internal external defined) value (actual numerical value label) relativity (the label ABSOLUTE RELATIVE), lastly length (BYTE, WORD, LONG). these attributes except length defined explicitly before definition: force label certain length giving suffix, example 'label.b' Description forces byte length. also define default state label length: label created this length unless otherwise forced with suffix. default WORD start assembly, CHANGED BYTES, WORDS LONGS appropriate length. Example also WORDS lab1 word length lab1 BYTES, WORDS Table Purpose Format .XALL List only code producing macro lines. .XALL This directive forces reduced listing macro expansion each time macro inDescription voked. Only those lines macro that generated object code listed. This instruction itself listed. This directive does generate assembly code data. Example also .XALL .LALL,.SALL 73/86 Assembler directives Table Purpose Format Assembler-Linker ZILOG Force Zilog-style radix specifiers. ZILOG Motorola style: %(8)17 Hexadecimal Octal Binary Decimal (default) Current program counter Description %(2)100 This directive forces Zilog format required during assembly. Example also ZILOG X,%FFFF INTEL, MOTOROLA, TEXAS 74/86 Assembler-Linker Error messages Appendix Error messages Format error messages There classes error trapped assembler fatal recoverable fatal error stops assembly there then, returning caller (which DOS; also invoke assembler) with message error number describing problem. format error messages follows: file.asm(line): as<pass> Error <errno> <message> '<text>' Figure Error message format example prog.asm(10): Error Doubly defined label 'fred' error number string describing error name program that handled error line number file name file where error found Note: name program that handled error (third field), depending pass progress when error found. error number (fourth field) used index find more complete description error next section (fatal errors read 'FATAL nn', instead 'ERROR nn'). File CBE.ERR Both fatal recoverable errors copied into file CBE.ERR they occur. Most link errors (described page also copied into CBE.ERR. this error file give automatic error finding. 75/86 Error messages Assembler-Linker Table Error Assembler errors Assembler errors Definition Empty file: assembler could read even first line given source code file. while Macro Definition: file ended while macro being defined; should last macro definition properly with MEND statement. Could return place source file 'X.asm': This error should never occur; implies have disk fault some kind. After #include, assembler returns line after #include itself. cannot return that line this error produced. Illegal source EOF: Main source code files must with directive carriage-return. before line terminator: directive must have least after example <TAB> <EOF> will generate this error while <TAB> <EOF> will work fine. Code produced outside segment: code produced assembler going have placed given address target system day. Since segments assemblers allocating addresses lumps code, code generated before first SEGMENT directive nonsense. Move line current window Move last line current window Undo changes last edited line Drop start black marker Drop black marker Find Source Code address Report value given label Report address current Editor line These functions mostly explain themselves; Alternate functions same original functions same name: having indexes same allows cursor keys control codes move cursor, whichever user prefers. Some indexes used default sequence matrix; these allow some WordStar-like commands implemented with more meaning. Multiple-key sequences, such those found WordStar format control codes need implemented follows: take sequence <^Y><L>, that CTRL-Y followed letter should coded ^Y+L where denotes that following character needs CTRL SHIFT. File capture error: #Include problems finding named file. Cannot find position source file: Again with #include, another 'impossible' error reporting that could find current position source file remember after #include. Cannot have more than 4096 #defines: Each #define checked each possible position each source line: having many them slows assembly noticeably. Although have 4096 #defines, there also limits storage space both arguments (error 23); average eight characters both arguments recommended. #define storage space (1): error #define second argument: #define requires space between parts argument delimit #define storage space (2): errors above; have reached limit storage space aside second argument #defines. strings DC.W: Strings only allowed parts BYTE, DC.B STRING directives. strings DC.L: Strings only allowed parts BYTE, DC.B STRING directives. 76/86 Assembler-Linker Table Error Error messages Assembler errors (continued) Definition Illegal external suffix: Only suffixes legal after external label external directive. suffix left then default label size used BYTES, WORDS LONGS; default WORDS). character public line. More than four characters single quotes: This assembler uses double-quotes surround string items single-quotes surround character constants. Section page Uneven single quotes: Single-quoted items must have closing quote delimit. Sequential operator error: does allow arithmetic operators hard against each other. lvalue expression: lvalue left-hand argument operator: lvalue. would cause this error. Divide zero: Attempt divide number zero, numeric expression. nested past levels: Exceeded maximum number nested statements. Spurious ELSE: ELSE discovered when active force. Spurious ENDIF: ENDIF discovered when active force. Only allowed inside Macros: LOCAL directive attempted outside Macro definition. strings word: Error string long: Error REPEAT this UNTIL: UNTIL directive found with matching REPEAT directive. Could return place source: Similar Error generated UNTIL instead #include. Syntax error SKIP arguments: SKIP expects numeric arguments, separated comma. First SKIP argument extern/relative; SKIP aborted: SKIP arguments must known assembler absolutely. Extern relative arguments allowed, although arithmetic need move page, example, SEGMENT same class with page align type. Second SKIP argument extern/relative; SKIP aborted: Error Undefined label: This error happens when reference made undefined label. label space: maximum 1024 labels allowed module, aside contain their names. either these limits exceeded, this error results. module into smaller ones; assembly will happen twice fast will only have reassemble half have made changes speeding things Label more than characters: Labels longer than characters allowed. Label defined PUBLIC twice: This warning occurs same label appears more than once PUBLIC statement. trapped because second appearance typographical error slightly different label wanted declared public. Doubly defined label: This happens when label defined twice more. 77/86 Error messages Table Error Assembler-Linker Assembler errors (continued) Definition Phase inconsistency (P1=X,P2=Y) 'label': Reports that named label allocated different values from pass-1 pass-2, implies awful things. It's generally caused when some reason assembler generated different lengths same instruction between pass-1 pass-2. Sometimes assembler problems identifying which addressing mode wanted particular instruction because typographical errors, labels that discovered undefined during second pass give error (see Error create object code that line. labels after that line will then allocated different values seeing object code that many bytes shorter, causing tons Phase Inconsistency errors. Because this mass Error sometimes hide real cause error, special assembler switch phase [errors]' used switch them off. strongly suggest that don't always your assemblies; only when need might miss critical phase errors. Public symbol undefined: defined symbol PUBLIC directive that defined module. Missing number: assembler expect number found zero length. Cannot match addressing mode: This error catchall assembler cannot anything wrong with your line cannot match known addressing mode either. There main causes errors: significant ordering numeric range errors. significant ordering error simple typographical error: what should have been (val),y coded (valy, whatever. components addressing mode properly formed; just that ordering wrong. numeric range errors harder detect. example, 8-bit relative branch branching range would trapped addressing mode error. diagnostics what went wrong assembler dumps model line screen just before error. Numerics printed value followed attribute string: INTernal, EXTernal, ABSolute, RELative Significands printed characters they represent, strings printed with their string. Numeric range errors also trapped link stage (See Section page 38). PSIG index: 'impossible' error that could only occur through corru Other recent searchesTDA9819 - TDA9819 TDA9819 Datasheet STA351A - STA351A STA351A Datasheet SRS680UF - SRS680UF SRS680UF Datasheet SN74LVC841 - SN74LVC841 SN74LVC841 Datasheet PD080SL3 - PD080SL3 PD080SL3 Datasheet NTD5806N - NTD5806N NTD5806N Datasheet LURFUG3692-PF - LURFUG3692-PF LURFUG3692-PF Datasheet 54F161A - 54F161A 54F161A Datasheet 54F163A - 54F163A 54F163A Datasheet 74F163A - 74F163A 74F163A Datasheet 74F161A - 74F161A 74F161A Datasheet 2SA1020 - 2SA1020 2SA1020 Datasheet
Privacy Policy | Disclaimer |