
History
    98/08/28  First release
    99/10/16  English version


Title    Assembler Explanation

Table of Contents
1. Execution of Assembler
2. Format
3. Formula
4. Pseudo Instruction
5. C language---Machine language interface (Not completed)

Table of Contents (Details)
1. Execution of Assembler
 1.-1. Execution of Assembler
 1.-2. Assembler Options
    -a
    -as
    --help
    -I dir
    -J
    -L
    -o obj
    -R
    -v
    -version
    --version
    -W
2. Format
    1. Comment
    2. Symbol
    3. Constant
    4. Location Counter
    5. Source Statement
     5-1. Label Field
     5-2. Operation Code Field
     5-3. Argument Field
     5-4. Comment Field
3. Formula
    1. Empty Formula
    2. Integer Formula
    3. Unary Operator
    4. Binary Operator
4. Pseudo Instruction
    .abort
    .align formula 1, formula 2
    .ascii "str1","str2",..
    .asciz "str1","str2",..
    .byte formula 1, formula 2,..
    .comm smbl,length
    .data
    .double fnum1,fnum2,..
    .eject
    .else
    .endif
    .equ smbl, formula
    .extern
    .fill repeat,size,value
    .float fnum1,fnum2,..
    .global smbl
    .globl smbl
    .hword formula 1, formula 2,..
    .if formula
    .ifdef smbl
    .ifndef smbl
    .ifnotdef smbl
    .include "file"
    .int formula 1, formula 2,..
    .lcomm smbl,length
    .list
    .long
    .nolist
    .octa onum1,onum2,..
    .org locat
    .psize line,colm
    .quad qnum1,qnum2,..
    .sbttl "subhead"
    .section name
    .set smbl,ex
    .short formula 1, formula 2,..
    .single fnum1,fnum2,..
    .space size,fill
    .string "str1","str2",..
    .text
    .title "head"
    .word formula 1, formula 2,..
5. C language---Machine language interface (Not completed)

1. Execution of Assembler
 1.-1. Execution of Assembler
        gcc (compiler driver) can execute operations such as compile, assemble and link.  When you execute assemble only, you should specify the assembler source file as shown below.  In this example, sample.s of the assembler source file is assembled and the object file sample.o is generated.
        
            C>gcc -c sample.s
        
        When you specify the option in detail, please execute as (assembler) directly.  In this example, sample.s of the assembler source file is assembled and the object file sample.o is generated.  In addition, the list is displayed as the standard output. 
        
            C>as -a sample.s -o sample.o
        
        Type the following, when you want to output a list to a file (filename.txt).
        
            C>as -a sample.s -o sample.o > filename.txt
        
 1.-2. Assembler Options
    -a
        A list of assemble is displayed as the standard output.
    
    -as
        A list of symbols is displayed as the standard output.
    
    --help
        The overview of the command line options is displayed.
        Assemble is not executed.
    
    -I dir
        Specify the directory dir as the search directory of include file (.include "file").
    
    -J
        Sign overflow warning is not displayed.
    
    -L
        This is the specification to include local symbols started from L to the symbol table.
        If you want to display the symbol list by -as option, the local symbol is also displayed.
    
    -o obj
        Specify the file name of the object file that the assembler outputs to obj.
    
    -R
        Specify the data section that mixes it to the text section.
    
    -v
    -version
        Display the version of the assembler in command line.
        Execute the assembler.
    
    --version
        Display the version of the assembler as the standard output.
        The assembler is not executed.
    
    -W
        The warning message is no displayed in command line or list.

2. Format
    1. Comment
        There are two way of specifying the comment.
        The area between /* and */ is the comment.
            
            /*
                This line is the comment.
            */
            
        In addition, one line from the comment symbol (#) to the line feed is the comment.
        
            mov     0,d0        # This is comment line.
    
    2. Symbol
        Symbols should be represented by using alphanumerics and "_.$".  It cannot be used in the first letter.
        Upper case and small case are sensitive and are treated as different characters.
        There is no limitation number of character to be used.
    
    3. Constant
        Binary, octal, decimal, hexadecimal and character constant can be used.  In addition, the strings enclosed by double quotation (") are treated as the string constant. 
            
            .byte   74,O112,0x4A,0X4a,'J','\J'              # All values are the same.
            .ascii  "Ring the bell\7"                       # String constant
            .octa   0x123456789abcdef0123456789ABCDEF0      # 16 byte
            .float  0f-3.1415926535879323846264338327       # -circular constant (pi)
    
    4. Location Counter
        The current location counter value is represented by a period (.).
            
            .int    .       # The current location counter value is stored by 4 byte.
            .int    .+10    # The current location counter value +10 is stored by 4 byte.
    
    5. Source Statement
        The source statement of assembler is processed by single line.  However, if the final character is \, the next line is treated as the continuing line.
        In general, the source statement of assembler is as follows.
        
            Label:  Operation code  Argument    # Comment
        
     5-1. Label Field
        This is a symbol that starts from the beginning of the line with the exception of space and tab.
        Put a colon (:) at the end of the symbol name.  It starts with an upper case L and all other characters are numerics, it is treated as a local label (L123, L456 and etc.)
    
     5-2. Operation Code Field
        If there is a label field, put it to the next place.  If there is no label field, put it to the beginning of the line with the exception of space and tab.
        Operation code field is ended by using space, tab or line feed.
        CPU instruction or assembler pseudo instruction is written to the operation code field.
    
     5-3. Argument Field
        Depending on the operation codes, the argument is required for the instructions such as CPU instruction and assembler pseudo instruction).  In this case, you should separate between the operation code field and argument field by using a space or tab, then write the argument field next to the operation code field.
    
     5-4. Comment Field
        One line from the comment symbol (#) to the line feed is the comment. 

3. Formula
    An address and value can be specified by using a formula.  The results of the formula are two types such as absolute and relocatable.  For absolute, it is handled by the constant in the assembler.  For relocatable, its value is set when the value is passed to a linker and the link is established. 
    
    1. Empty Formula
        If you omit a formula where it is required, the value of the formula is assembled by using 0 value.
    
    2. Integer Formula
        Integer formula is written by using a value (symbol, numeric and formula) and operator.  In general, integer formula is handled by 32 bit.
        The following unary operator and binary operator can be used.
    
    3. Unary Operator 
        -   Negative(complement of 2)
        ~   negation (complement of 1)
    
    4. Binary Operator 
        Higher priority order group of operator
            *  	  Multiplication
            /     Division
            %     Remainder
            <,<<  Left shift
            >,>>  Right shift
        
        Middle priority order group of operator
            |     OR
            &     AND
            ^     Exclusive-OR
            !     NOT OR
        
        Low priority order group of operator
            +     Addition
            -     Subtraction

4. Pseudo Instruction
    .abort
        Stop assemble.
    
    .align formula 1, formula 2
        Align the location counter to the specified alignment in the formula 1.  For example, 
        When the .align is 4, the location counter will be the multiple of 16 (fourth power of 2).
        If the location counter is already set to the multiple of 16, it is not changed. 
        If there is the formula 2, the byte number of the formula 2 are padded.
    
    .ascii "str1","str2",..
        The specified strings are stored to the address of the current location counter. 
        Multiple strings can be specified after separating them by comma (,).
    
    .asciz "str1","str2",..
        The specified strings are stored to the address of the current location counter and one byte of Null(0) is added to the end of the strings.
        Multiple strings can be specified after separating them by comma (,).
        The operation is same as the .string pseudo instruction.
    
    .byte formula 1, formula 2,..
        Store the value of the formula to the address of the current location counter by single byte.  Multiple formulas can be specified after separating them by comma (,).
    
    .comm smbl,length
        Keep the area of the length bytes under the name of smbl in the common area of the BSS section.  Length is an absolute value.  BSS section is used as the uninitialized data storing area.
    
    .data
        When you keep the memory area after .data, it is kept as the data section. 
        The data section is used as the initialized data storing area.
    
    .double fnum1,fnum2,..
        Store the floating point value to the address of the current location counter by 8 byte.  Multiple floating points can be specified after separating them by comma (,).
    
    .eject
        Insert a line feed in the list.
    
    .else
        .else pseudo instruction is used as a pair of .if pseudo instruction and .endif pseudo instruction.
        You should write an assemble instruction after .else if the condition is not fulfilled (False).
        Refer to .if pseudo instruction.
    
    .endif
        .endif pseudo instruction is used as a pair of .if pseudo instruction.
        The termination of assemble with condition is shown.
        Refer to .if pseudo instruction.
    
    .equ smbl, formula
        Define the value that is specified in the formula to the symbol for the name of smbl. 
        The operation is same as the .set pseudo instruction.
    
    .extern
        .extern pseudo instruction is prepared only for the compatibility to other assemblers.  An assembler ignores it. 
        All undefined symbols are treated as the external symbol even if you declare it as .extern.
    
    .fill repeat,size,value
        Store the value from the address of the current location counter by repeating the number of the repeat number by size byte.  Size is less than 8.
        In addition, repeat, size and value are absolute values.
    
    .float fnum1,fnum2,..
        Store the floating point value to the address of the current location counter by 4 byte.  Multiple floating points can be specified after separating them by comma (,).
        The operation is same as the .single pseudo instruction.
    
    .global smbl
    .globl smbl
        Define the symbol name of smbl as a global symbol that can be referred from other modules. 
    
    .hword formula 1, formula 2,..
        Store the value of the formula to the address of the current location counter by 4 byte.  Multiple formulas can be specified after separating them by comma (,).
        The operation is same as the .short and .word pseudo instruction.
    
    .if formula
        From .if pseudo instruction to .endif pseudo instruction is the condition assemble. 
        If the value of the formula is other than 0, the block after .if pseudo instruction is assembled but the block after .else pseudo instruction is not assembled.
        Conversely, if the value of the formula is 0, the block after .if pseudo instruction is not assembled but the block after .else pseudo instruction is assembled.
        .else pseudo instruction and the block after .else can be omitted.
        
        .if formula
            /* If the formula<>0, it is assembled. */
            
        .else
            /* If the formula=0, it is assembled. */
            
        .endif
    
    .ifdef smbl
        If smbl symbol is defined, the following blocks are assembled.
    
    .ifndef smbl
    .ifnotdef smbl
        If smbl symbol is not defined, the following blocks are assembled.
    
    .include "file"
        Import the contents of the file that has "file" name as the source file of the assembler.  This is the same function of #include "file" of C language.
        A search directory of the include file can be specified by using -l option of the assemble.
    
    .int formula 1, formula 2,..
        Store the value of the formula to the address of the current location counter by 4 byte.  Multiple formulas can be specified after separating them by comma (,).
        The operation is same as the .long pseudo instruction.
    
    .lcomm smbl,length
        Keep the area for length byte under the name of smbl in the common area of the BSS section.  The length is an absolute value.  smbl cannot be referred from other modules.  In general, the BSS section is used as the stored area to keep the uninitialized data.
    
    .list
        Output a list of the contents after .list pseudo instruction.
        The contents after .nolist pseudo instruction is not output as a list.
    
    .long
        The operation is same as the .int pseudo instruction.
    
    .nolist
        The contents after .nolist pseudo instruction is not output as a list. 
        Output a list of the contents after .list pseudo instruction.
    
    .octa onum1,onum2,..
        Store the value of integer to the address of the current location counter by 16 byte.  Multiple integers can be specified after separating them by comma (,).
    
    .org locat
        Change the value of the location counter to the value of locat.
        Locat is an absolute value.
    
    .psize line,colm
        Specify the number of lines and characters per page for the list output.
        Specify the number of line in line and number of characters in colm, respectively.
    
    .quad qnum1,qnum2,..
        Store the value of integer to the address of the current location counter by 8 byte.  Multiple integers can be specified after separating them by comma (,).
    
    .sbttl "subhead"
        Set a subtitle that displays in the third line of the list output.
    
    .section name
        Start the section specified in name. 
        .section and .text are same functions of .text.
        .section and .data are same functions of .data.
    
    .set smbl,ex
        Set the value of ex to the symbol name of smbl.  .set pseudo instruction is used when the value of the identical symbol name is changed repeatedly.
    
    .short formula 1, formula 2,..
        Store the formula value to the address of the current location counter by 2 byte.  Multiple integers can be specified after separating them by comma (,).
        The operation is same as the .hword and .word pseudo instruction.
    
    .single fnum1,fnum2,..
        Store the floating point value to the address of the current location counter by 4 byte.  Multiple floating points can be specified after separating them by comma (,).
        The operation is same as the .float pseudo instruction.
    
    .space size,fill
        Keep the area for size byte.  All the area to be kept should be the value of "fill".  If fill is omitted, the area to be kept should be 0.
    
    .string "str1","str2",..
        The specified strings are stored to the address of the current location counter and one byte of Null(0) is added to the end of the strings.
        Multiple strings can be specified after separating them by comma (,).
        The operation is same as the .asciz pseudo instruction.
    
    .text
        The following memory area by the assembler should be kept as the text section.  In general, write an instruction code to the text section.
    
    .title "head"
        Specify the title that is displayed in the second line of the list output as "head".
    
    .word formula 1, formula 2,..
        Store the formula value to the address of the current location counter by 2 byte.  Multiple integers can be specified after separating them by comma (,).
        The operation is same as the .hword and .short pseudo instruction.

5. C language---Machine language interface (Not completed)
    The following is an explanation on how an argument is passed when the machine language is called from C.
    
    (Structure of the Table)
    When you call the following function that contains four arguments from C,
        
        func(void *p0,int i,long l,int *p1)
        
    When the process is passed to the function that is written in the assembler, each function is stored to the address that a register points as follows.
        
        The first argument *p0 is stored to D0 register.
        The second argument i is stored to D1 register.
        The last digit of the third argument is stored to the RAM of the address+4 that (A3+4) A3 register points.
        The first digit of the third argument is stored to the RAM of the address+6 that (A3+6) A3 register points.
        The fourth argument *p1 is stored to A0 register.
        
                                                            (a3+n)
    1st 2nd 3rd 4th 5th 6th 7th 8th |   d0  d1  d2  d3  a0  +4  +6  +8  +10 +12
    *p0 i   l   *p1 -   -   -   -   |   *p0 i   -   -   *p1 lL  lH  -   -   -
    
    
    (Table)
                                                            (a2+n)
    1st 2nd 3rd 4th 5th 6th 7th 8th |   d0  d1  d2  d3  a0  +4  +6  +8  +10 +12
    *p0 i   l   *p1 -   -   -   -   |   *p0 i   -   -   *p1 lL  lH  -   -   -
    i0  i1  i2  i3  i4  i5  i6  *p  |   i0  i1  -   -   *p  i2  i3  i4  i5  i6
    
    We are sorry.  This section is not completed.


===============================================================================
 Copyright (c) 1998-1999.  Seiko Instruments Inc.  All rights reserved. 
===============================================================================
