SlideShare una empresa de Scribd logo
1 de 66
Assemblers

System Software
by Leland L. Beck
Chapter 2
Role of Assembler


Source                Object
          Assembler             Linker
Program               Code


                               Executable
                                 Code


                                 Loader


                                            Chap 2
Chapter 2 -- Outline
s   Basic Assembler Functions
s   Machine-dependent Assembler Features
s   Machine-independent Assembler Features
s   Assembler Design Options




                                        Chap 2
Introduction to Assemblers
s   Fundamental functions
    x translating mnemonic operation codes to their
      machine language equivalents
    x assigning machine addresses to symbolic
      labels

s   Machine dependency
    x   different machine instruction formats and codes




                                                    Chap 2
Example Program (Fig. 2.1)

s   Purpose
    x reads records from input device (code F1)
    x copies them to output device (code 05)
    x at the end of the file, writes EOF on the output
      device, then RSUB to the operating system
    x program




                                                         Chap 2
Example Program (Fig. 2.1)
s   Data transfer (RD, WD)
     x a buffer is used to store record
     x buffering is necessary for different I/O rates
     x the end of each record is marked with a null
       character (0016)
     x   the end of the file is indicated by a zero-length
         record
s   Subroutines (JSUB, RSUB)
     x RDREC, WRREC
     x save link register first before nested jump


                                                             Chap 2
Assembler Directives
s   Pseudo-Instructions
    x   Not translated into machine instructions
    x   Providing information to the assembler
s   Basic assembler directives
    x START
    x END
    x BYTE
    x WORD
    x RESB
    x RESW


                                                   Chap 2
Object Program
s   Header
    Col. 1     H
    Col. 2~7 Program name
    Col. 8~13 Starting address (hex)
    Col. 14-19 Length of object program in bytes (hex)
s   Text
    Col.1     T
    Col.2~7 Starting address in this record (hex)
    Col. 8~9 Length of object code in this record in bytes (hex)
    Col. 10~69Object code (69-10+1)/6=10 instructions
s   End
    Col.1     E
    Col.2~7   Address of first executable instruction (hex)
              (END program_name)
                                                              Chap 2
Fig. 2.3
H COPY 001000 00107A
T 001000 1E 141033 482039 001036 281030 301015 482061 ...
T 00101E 15 0C1036 482061 081044 4C0000 454F46 000003 000000
T 002039 1E 041030 001030 E0205D 30203F D8205D 281030 …
T 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064 …
T 002073 07 382064 4C0000 05
E 001000




                                                               Chap 2
Figure 2.1 (Pseudo code)
Program copy {
       save return address;
 cloop: call subroutine RDREC to read one record;
        if length(record)=0 {
            call subroutine WRREC to write EOF;
       } else {
            call subroutine WRREC to write one record;
            goto cloop;
        }
        load return address
        return to caller
  }




                                                         Chap 2
An Example (Figure 2.1, Cont.)
                                       EOR:
Subroutine RDREC {                     character x‘00’
        clear A, X register to 0;
 rloop: read character from input device to A register
        if not EOR {
               store character into buffer[X];
               X++;
               if X < maximum length
                   goto rloop;
        }
        store X to length(record);
        return
}




                                                         Chap 2
An Example (Figure 2.1, Cont.)
Subroutine WDREC {
        clear X register to 0;
 wloop: get character from buffer[X]
         write character from X to output device
         X++;
         if X < length(record)
              goto wloop;
         return
 }




                                             Chap 2
Assembler’s functions
s   Convert mnemonic operation codes to
    their machine language equivalents
s   Convert symbolic operands to their
    equivalent machine addresses 
s   Build the machine instructions in the
    proper format
s   Convert the data constants to internal
    machine representations
s   Write the object program and the
    assembly listing
                                             Chap 2
Example of Instruction Assemble

    STCH        BUFFER,X                  549039
        8             1           15
       opcode         x         address
                                  m
       (54)16        1 (001)2        (039)16

s   Forward reference




                                                   Chap 2
Difficulties: Forward Reference
s   Forward reference: reference to a label that
    is defined later in the program.

       Loc    Label    Operator   Operand

       1000   FIRST    STL        RETADR

       1003   CLOOP    JSUB       RDREC
       …       …       …          …          …
       1012            J          CLOOP
       …      …        …          …          …
       1033   RETADR   RESW       1



                                             Chap 2
Two Pass Assembler
s   Pass 1
    x   Assign addresses to all statements in the program
    x   Save the values assigned to all labels for use in Pass 2
    x   Perform some processing of assembler directives
s   Pass 2
    x   Assemble instructions
    x   Generate data values defined by BYTE, WORD
    x   Perform processing of assembler directives not done in
        Pass 1
    x   Write the object program and the assembly listing



                                                             Chap 2
Two Pass Assembler
  s     Read from input line
        x   LABEL, OPCODE, OPERAND


        Source
        program

                           Intermediate               Object
         Pass 1                           Pass 2
                                file                  codes

OPTAB             SYMTAB                     SYMTAB




                                                               Chap 2
Data Structures

s   Operation Code Table (OPTAB)
s   Symbol Table (SYMTAB)
s   Location Counter(LOCCTR)




                                   Chap 2
OPTAB (operation code table)
s   Content
    x   menmonic, machine code (instruction format,
        length) etc.
s   Characteristic
    x   static table
s   Implementation
    x   array or hash table, easy for search




                                                      Chap 2
SYMTAB (symbol table)
s   Content                          COPY          1000
     x label name, value, flag, (type, length) etc.1000
                                     FIRST
                                     CLOOP         1003
s   Characteristic                   ENDFIL        1015
                                     EOF           1024
     x dynamic table (insert, delete, search)
                                     THREE         102D
s   Implementation                   ZERO          1030
                                     RETADR        1033
     x hash table, non-random keys, hashing function
                                     LENGTH        1036
                                     BUFFER        1039
                                     RDREC         2039




                                                    Chap 2
Homework #3
SUM     START   4000
FIRST   LDX     ZERO
        LDA     ZERO
LOOP    ADD     TABLE,X
        TIX     COUNT
        JLT     LOOP
        STA     TOTAL
        RSUB
TABLE   RESW    2000
COUNT   RESW    1
ZERO    WORD    0
TOTAL   RESW    1
        END     FIRST

                          Chap 2
Assembler Design
s   Machine Dependent Assembler Features
    x   instruction formats and addressing modes
    x   program relocation
s   Machine Independent Assembler Features
    x   literals
    x   symbol-defining statements
    x   expressions
    x   program blocks
    x   control sections and program linking




                                                   Chap 2
Machine-dependent
Assembler Features
Sec. 2-2
s   Instruction formats and addressing modes
s   Program relocation
Instruction Format and Addressing Mode

s   SIC/XE
    x   PC-relative or Base-relative addressing:   op m
    x   Indirect addressing:                       op @m
    x   Immediate addressing:                      op #c
    x   Extended format:                           +op m
    x   Index addressing:                          op m,x
    x   register-to-register instructions
    x   larger memory -> multi-programming (program allocation)
s   Example program



                                                             Chap 2
Translation
s   Register translation
    x   register name (A, X, L, B, S, T, F, PC, SW) and their
        values (0,1, 2, 3, 4, 5, 6, 8, 9)
    x   preloaded in SYMTAB
s   Address translation
    x   Most register-memory instructions use program
        counter relative or base relative addressing
    x   Format 3: 12-bit address field
         3   base-relative: 0~4095
         3   pc-relative: -2048~2047
    x   Format 4: 20-bit address field


                                                                Chap 2
PC-Relative Addressing Modes

s   PC-relative
    x   10        0000   FIRST STL    RETADR            17202D

               op(6)     n I xbp e          disp(12)

             (14)16      110010       (02D) 16
         3   displacement= RETADR - PC = 30-3 = 2D
    x   40        0017         J      CLOOP             3F2FEC

                 op(6)    n I xbp e              disp(12)

              (3C)16     110010       (FEC) 16
         3   displacement= CLOOP-PC= 6 - 1A= -14= FEC
                                                                 Chap 2
Base-Relative Addressing Modes
s   Base-relative
    x   base register is under the control of the programmer
    x   12                      LDB #LENGTH
    x   13                      BASE LENGTH
    x   160     104E            STCH BUFFER, X 57C003

                op(6)    n I xbp e            disp(12)
             ( 54 )16   111100         ( 003 ) 16
              (54)        111010        0036-1051= -101B16
         3   displacement= BUFFER - B = 0036 - 0033 = 3
    x   NOBASE is used to inform the assembler that the contents
        of the base register no longer be relied upon for addressing
                                                                Chap 2
Immediate Address Translation

s   Immediate addressing
    x   55        0020         LDA    #3                010003
                 op(6)    n I xbp e          disp(12)
              ( 00 )16   010000       ( 003 ) 16

    x   133       103C         +LDT #4096          75101000
                 op(6)    n I xbp e       disp(20)
              ( 74 )16   010001       ( 01000 ) 16




                                                                 Chap 2
Immediate Address Translation (Cont.)

s   Immediate addressing
      x    12      0003          LDB #LENGTH          69202D
              op(6)     n I xbp e          disp(12)
           ( 68)16    010010        ( 02D ) 16
           ( 68)16     010000           ( 033)16      690033

       3 the immediate operand is the symbol LENGTH
       3 the address of this symbol LENGTH is loaded into

         register B
       3 LENGTH=0033=PC+displacement=0006+02D

       3 if immediate mode is specified, the target address

         becomes the operand                              Chap 2
Indirect Address Translation
s   Indirect addressing
    x   target addressing is computed as usual (PC-
        relative or BASE-relative)
    x   only the n bit is set to 1
    x   70         002A         J     @RETADR           3E2003

                 op(6)    n I xbp e          disp(12)

             ( 3C )16     100010      ( 003 ) 16
         3 TA=RETADR=0030
         3 TA=(PC)+disp=002D+0003




                                                             Chap 2
Program Relocation
s   Example Fig. 2.1
    x   Absolute program, starting address 1000
        e.g. 55 101B             LDA    THREE          00102D
    x   Relocate the program to 2000
        e.g. 55 101B             LDA    THREE          00202D
    x   Each Absolute address should be modified
s   Example Fig. 2.5:
    x   Except for absolute address, the rest of the instructions need
        not be modified
         3   not a memory address (immediate addressing)
         3   PC-relative, Base-relative
    x   The only parts of the program that require modification at
        load time are those that specify direct addresses        Chap 2
Example




          Chap 2
Relocatable Program

s   Modification record
    x Col 1 M
    x Col 2-7 Starting location of the address field to be
                 modified, relative to the beginning of the program
    x   Col 8-9 length of the address field to be modified, in half-
                 bytes




                                                                  Chap 2
Object Code




              Chap 2
Machine-Independent Assembler
Features
Literals
Symbol Defining Statement
Expressions
Program Blocks
Control Sections and Program
Linking
Literals
s   Design idea
    x Let programmers to be able to write the value
      of a constant operand as a part of the
      instruction that uses it.
    x This avoids having to define the constant
      elsewhere in the program and make up a label
      for it.
s   Example
    x   e.g. 45   001A   ENDFIL   LDA   =C’EOF’   032010
    x       93                    LTORG
    x       002D         *        =C’EOF’         454F46
    x   e.g. 215 1062    WLOOP    TD    =X’05’    E32011
                                                           Chap 2
Literals vs. Immediate Operands
s   Immediate Operands
    x   The operand value is assembled as part of the
        machine instruction
    x   e.g. 55 0020                 LDA   #3   010003
s   Literals
    x   The assembler generates the specified value
        as a constant at some other memory location
    x   e.g. 45   001A   ENDFILLDA   =C’EOF’    032010
s   Compare (Fig. 2.6)
    x   e.g. 45 001A ENDFIL          LDA EOF 032010
    x        80 002D EOF             BYTE C’EOF’454F46
                                                         Chap 2
Literal - Implementation (1/3)
s   Literal pools
    x   Normally literals are placed into a pool at the
        end of the program
         3   see Fig. 2.10 (END statement)
    x   In some cases, it is desirable to place literals
        into a pool at some other location in the object
        program
         3 assembler directive LTORG
         3 reason: keep the literal operand close to the

           instruction


                                                           Chap 2
Literal - Implementation (2/3)
s   Duplicate literals
    x e.g. 215       1062 WLOOP        TD =X’05’
    x e.g. 230       106B              WD =X’05’
    x The assemblers should recognize duplicate
      literals and store only one copy of the specified
      data value
        3   Comparison of the defining expression
             • Same literal name with different value, e.g.
               LOCCTR=*
        3   Comparison of the generated data value
             • The benefits of using generate data value are usually
               not great enough to justify the additional complexity in
               the assembler
                                                                   Chap 2
Literal - Implementation (3/3)
s   LITTAB
    x   literal name, the operand value and length, the address
        assigned to the operand
s   Pass 1
    x   build LITTAB with literal name, operand value and length,
        leaving the address unassigned
    x   when LTORG statement is encountered, assign an address to
        each literal not yet assigned an address
s   Pass 2
    x   search LITTAB for each literal operand encountered
    x   generate data values using BYTE or WORD statements
    x   generate modification record for literals that represent an
        address in the program
                                                                      Chap 2
Symbol-Defining Statements
s   Labels on instructions or data areas
    x   the value of such a label is the address
        assigned to the statement
s   Defining symbols
    x symbol EQU value
    x value can be: x constant, y other symbol, z
      expression
    x making the source program easier to
      understand
    x no forward reference


                                                    Chap 2
Symbol-Defining Statements
s   Example 1
    x   MAXLEN      EQU 4096
    x               +LDT #MAXLEN          +LDT   #4096
s   Example 2 (Many general purpose registers)
    x   BASE EQU    R1
    x   COUNT EQU   R2
    x   INDEX EQU   R3
s   Example 3
    x   MAXLEN      EQU   BUFEND-BUFFER




                                                  Chap 2
ORG (origin)
s   Indirectly assign values to symbols
s   Reset the location counter to the specified value
        3   ORG value
s   Value can be: x constant, y other symbol, z
    expression
s   No forward reference
s   Example
    x SYMBOL: 6bytes
                                    SYMBOL     VALUE FLAGS
    x VALUE: 1word     STAB
    x FLAGS: 2bytes (100 entries)
    x   LDA     VALUE, X
                                       .         .      .
                                       .         .      .
                                       .         .      .
                                                     Chap 2
ORG Example
s   Using EQU statements
    x   STAB     RESB   1100
    x   SYMBOL   EQU    STAB
    x   VALUE    EQU    STAB+6
    x   FLAG     EQU    STAB+9
s   Using ORG statements
    x   STAB     RESB 1100
    x            ORG STAB
    x   SYMBOL   RESB 6
    x   VALUE    RESW 1
    x   FLAGS    RESB 2
    x            ORG STAB+1100
                                 Chap 2
Expressions
s   Expressions can be classified as absolute
    expressions or relative expressions
    x   MAXLEN                EQU BUFEND-BUFFER
    x   BUFEND and BUFFER both are relative terms,
        representing addresses within the program
    x   However the expression BUFEND-BUFFER represents
        an absolute value
s   When relative terms are paired with opposite
    signs, the dependency on the program starting
    address is canceled out; the result is an absolute
    value


                                                     Chap 2
SYMTAB
s   None of the relative terms may enter into a
    multiplication or division operation
s   Errors:
    x   BUFEND+BUFFER
    x   100-BUFFER
    x   3*BUFFER
s   The type of an expression
    x   keep track of the types of all symbols defined in
        the program Symbol Type         Value
                      RETADR    R         30
                      BUFFER    R         36
                      BUFEND    R       1036
                      MAXLEN    A       1000
                                                      Chap 2
Example 2.9

SYMTAB     Name   Value    LITTAB
         COPY          0   C'EOF'   454F46   3   002D
         FIRST         0   X'05'        05   1   1076
         CLOOP         6
         ENDFIL       1A
         RETADR       30
         LENGTH       33
         BUFFER       36
         BUFEND     1036
         MAXLEN     1000
         RDREC      1036
         RLOOP      1040
         EXIT       1056
         INPUT      105C
         WREC       105D
         WLOOP      1062
                                                        Chap 2
Program Blocks
s   Program blocks
    x refer to segments of code that are rearranged
      within a single object program unit
    x USE     [blockname]
    x Default block
    x Example: Figure 2.11
    x Each program block may actually contain
      several separate segments of the source
      program



                                                  Chap 2
Program Blocks - Implementation
s   Pass 1
    x   each program block has a separate location counter
    x   each label is assigned an address that is relative to the
        start of the block that contains it
    x   at the end of Pass 1, the latest value of the location
        counter for each block indicates the length of that block
    x   the assembler can then assign to each block a starting
        address in the object program
s   Pass 2
    x   The address of each symbol can be computed by
        adding the assigned block starting address and the
        relative address of the symbol to that block

                                                                    Chap 2
Figure 2.12
s   Each source line is given a relative address
    assigned and a block number
          Block name Block number   Address   Length
            (default)      0         0000      0066
           CDATA           1         0066      000B
            CBLKS          2         0071      1000


s   For absolute symbol, there is no block number
    x   line 107
s   Example
    x   20    0006 0       LDA LENGTH         032060
    x   LENGTH=(Block 1)+0003= 0066+0003= 0069
    x   LOCCTR=(Block 0)+0009= 0009
                                                       Chap 2
Program Readability
s   Program readability
    x   No extended format instructions on lines 15, 35, 65
    x   No needs for base relative addressing (line 13, 14)
    x   LTORG is used to make sure the literals are placed
        ahead of any large data areas (line 253)
s   Object code
    x It is not necessary to physically rearrange the
      generated code in the object program
    x see Fig. 2.13, Fig. 2.14




                                                              Chap 2
Chap 2
Control Sections and Program Linking
s   Control Sections
    x are most often used for subroutines or other
      logical subdivisions of a program
    x the programmer can assemble, load, and
      manipulate each of these control sections
      separately
    x instruction in one control section may need to
      refer to instructions or data located in another
      section
    x because of this, there should be some means
      for linking control sections together
    x Fig. 2.15, 2.16
                                                     Chap 2
External Definition and References
s   External definition
    x EXTDEF         name [, name]
    x EXTDEF names symbols that are defined in this
      control section and may be used by other sections
s   External reference
    x EXTREF name [,name]
    x EXTREF names symbols that are used in this
      control section and are defined elsewhere
s   Example
    x   15 0003 CLOOP      +JSUB RDREC      4B100000
    x   160 0017           +STCH BUFFER,X   57900000
    x   190 0028 MAXLEN   WORD BUFEND-BUFFER 0000002
                                                 Chap
Implementation
s   The assembler must include information in the object
    program that will cause the loader to insert proper values
    where they are required
s   Define record
    x   Col. 1 D
    x   Col. 2-7 Name of external symbol defined in this control section
    x   Col. 8-13 Relative address within this control section (hexadeccimal)
    x   Col.14-73 Repeat information in Col. 2-13 for other external symbols
s   Refer record
    x   Col. 1 D
    x   Col. 2-7 Name of external symbol referred to in this control section
    x   Col. 8-73 Name of other external reference symbols

                                                                       Chap 2
Modification Record
s   Modification record
    x   Col. 1 M
    x   Col. 2-7 Starting address of the field to be modified
        (hexiadecimal)
    x   Col. 8-9 Length of the field to be modified, in half-bytes
        (hexadeccimal)
    x   Col.11-16 External symbol whose value is to be added to or
        subtracted from the indicated field
    x   Note: control section name is automatically an external symbol,
        i.e. it is available for use in Modification records.
s   Example
    x   Figure 2.17
    x   M00000405+RDREC
    x   M00000705+COPY                                                Chap 2
External References in Expression
s   Earlier definitions
    x   required all of the relative terms be paired in an
        expression (an absolute expression), or that all
        except one be paired (a relative expression)
s   New restriction
    x   Both terms in each pair must be relative within
        the same control section
    x   Ex: BUFEND-BUFFER
    x   Ex: RDREC-COPY
s
    In general, the assembler cannot determine
    whether or not the expression is legal at
    assembly time. This work will be handled by a
                                                             Chap 2
    linking loader.
Assembler Design Options




     One-pass assemblers
     Multi-pass assemblers
     Two-pass assembler with overlay
     structure
Two-Pass Assembler with Overlay
Structure
s   For small memory
    x pass 1 and pass 2 are never required at the
      same time
    x three segments
        3 root: driver program and shared tables and
          subroutines
        3 pass 1

        3 pass 2

    x tree structure
    x overlay program


                                                       Chap 2
One-Pass Assemblers
s   Main problem
    x   forward references
         3 data items
         3 labels on instructions

s   Solution
    x data items: require all such areas be defined
      before they are referenced
    x labels on instructions: no good solution




                                                      Chap 2
One-Pass Assemblers
s   Main Problem
    x   forward reference
         3 data items
         3 labels on instructions

s   Two types of one-pass assembler
    x   load-and-go
         3   produces object code directly in memory for
             immediate execution
    x   the other
         3   produces usual kind of object code for later
             execution
                                                            Chap 2
Load-and-go Assembler
s   Characteristics
    x Useful for program development and testing
    x Avoids the overhead of writing the object
      program out and reading it back
    x Both one-pass and two-pass assemblers can
      be designed as load-and-go.
    x However one-pass also avoids the over head
      of an additional pass over the source program
    x For a load-and-go assembler, the actual
      address must be known at assembly time, we
      can use an absolute program
                                                 Chap 2
Forward Reference in One-pass Assembler
s   For any symbol that has not yet been defined
    1. omit the address translation
    2. insert the symbol into SYMTAB, and mark this
      symbol undefined
    3. the address that refers to the undefined symbol is
      added to a list of forward references associated
      with the symbol table entry
    4. when the definition for a symbol is encountered,
      the proper address for the symbol is then inserted
      into any instructions previous generated
      according to the forward reference list
                                                      Chap 2
Load-and-go Assembler (Cont.)
s   At the end of the program
    x any SYMTAB entries that are still marked with *
      indicate undefined symbols
    x search SYMTAB for the symbol named in the
      END statement and jump to this location to
      begin execution
s   The actual starting address must be
    specified at assembly time
s   Example
    x   Figure 2.18, 2.19


                                                  Chap 2
Producing Object Code
s   When external working-storage devices are not
    available or too slow (for the intermediate file
    between the two passes
s   Solution:
    x   When definition of a symbol is encountered, the assembler
        must generate another Tex record with the correct
        operand address
    x   The loader is used to complete forward references that
        could not be handled by the assembler
    x   The object program records must be kept in their original
        order when they are presented to the loader
s   Example: Figure 2.20

                                                             Chap 2
Multi-Pass Assemblers
s   Restriction on EQU and ORG
    x   no forward reference, since symbols’ value
        can’t be defined during the first pass
s   Example
    x   Use link list to keep track of whose value
        depend on an undefined symbol
s   Figure 2.21




                                                     Chap 2

Más contenido relacionado

La actualidad más candente

Data Encryption Standard (DES)
Data Encryption Standard (DES)Data Encryption Standard (DES)
Data Encryption Standard (DES)Haris Ahmed
 
System Programming- Unit I
System Programming- Unit ISystem Programming- Unit I
System Programming- Unit ISaranya1702
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generationrawan_z
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design) Tasif Tanzim
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler DesignKuppusamy P
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)Hareem Aslam
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler designKuppusamy P
 
Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03desta_gebre
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1Manoj Patil
 
Types of Instruction Format
Types of Instruction FormatTypes of Instruction Format
Types of Instruction FormatDhrumil Panchal
 
Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Bhatt Balkrishna
 

La actualidad más candente (20)

Macro Processor
Macro ProcessorMacro Processor
Macro Processor
 
Data Encryption Standard (DES)
Data Encryption Standard (DES)Data Encryption Standard (DES)
Data Encryption Standard (DES)
 
System Programming- Unit I
System Programming- Unit ISystem Programming- Unit I
System Programming- Unit I
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
Unit 3 sp assembler
Unit 3 sp assemblerUnit 3 sp assembler
Unit 3 sp assembler
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Compiler Design Unit 2
Compiler Design Unit 2Compiler Design Unit 2
Compiler Design Unit 2
 
Code Generation
Code GenerationCode Generation
Code Generation
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Macro-processor
Macro-processorMacro-processor
Macro-processor
 
Types of Instruction Format
Types of Instruction FormatTypes of Instruction Format
Types of Instruction Format
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 
Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming
 
Programming
ProgrammingProgramming
Programming
 

Destacado

Job Opportunities for a Computer Science Student
Job Opportunities for a Computer Science StudentJob Opportunities for a Computer Science Student
Job Opportunities for a Computer Science StudentSyed Areeb Jafri
 
computer science JAVA ppt
computer science JAVA pptcomputer science JAVA ppt
computer science JAVA pptbrijesh kumar
 
Computer Careers
Computer CareersComputer Careers
Computer Careerscfoster3541
 
Computer Science Engineering - Better Career Opportunities
Computer Science Engineering - Better Career OpportunitiesComputer Science Engineering - Better Career Opportunities
Computer Science Engineering - Better Career Opportunitiesachaljain11
 
Career in computer science
Career in computer scienceCareer in computer science
Career in computer scienceAri Banerjee
 
Computer science ppt
Computer science pptComputer science ppt
Computer science pptbrijesh kumar
 

Destacado (6)

Job Opportunities for a Computer Science Student
Job Opportunities for a Computer Science StudentJob Opportunities for a Computer Science Student
Job Opportunities for a Computer Science Student
 
computer science JAVA ppt
computer science JAVA pptcomputer science JAVA ppt
computer science JAVA ppt
 
Computer Careers
Computer CareersComputer Careers
Computer Careers
 
Computer Science Engineering - Better Career Opportunities
Computer Science Engineering - Better Career OpportunitiesComputer Science Engineering - Better Career Opportunities
Computer Science Engineering - Better Career Opportunities
 
Career in computer science
Career in computer scienceCareer in computer science
Career in computer science
 
Computer science ppt
Computer science pptComputer science ppt
Computer science ppt
 

Similar a Assembler (2)

assembler_full_slides.ppt
assembler_full_slides.pptassembler_full_slides.ppt
assembler_full_slides.pptAshwini864432
 
Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2Khaja Dileef
 
Swug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainathSwug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainathDennis Chung
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assemblyAbdul Khan
 
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler ProgrammingOmar Sanchez
 
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHackito Ergo Sum
 
RIO Application Programming
RIO  Application ProgrammingRIO  Application Programming
RIO Application Programmingrayhsu
 
Ebc7fc8ba9801f03982acec158fa751744ca copie
Ebc7fc8ba9801f03982acec158fa751744ca   copieEbc7fc8ba9801f03982acec158fa751744ca   copie
Ebc7fc8ba9801f03982acec158fa751744ca copieSourour Kanzari
 
Lect05 Prog Model
Lect05 Prog ModelLect05 Prog Model
Lect05 Prog Modelanoosdomain
 
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)Simen Li
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 

Similar a Assembler (2) (20)

Assembler
AssemblerAssembler
Assembler
 
Assembler
AssemblerAssembler
Assembler
 
Assembler
AssemblerAssembler
Assembler
 
Assembler
AssemblerAssembler
Assembler
 
Assembler
AssemblerAssembler
Assembler
 
assembler_full_slides.ppt
assembler_full_slides.pptassembler_full_slides.ppt
assembler_full_slides.ppt
 
Sp chap2
Sp chap2Sp chap2
Sp chap2
 
Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2
 
Swug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainathSwug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainath
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
 
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
 
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
 
Data race
Data raceData race
Data race
 
System Software
System SoftwareSystem Software
System Software
 
RIO Application Programming
RIO  Application ProgrammingRIO  Application Programming
RIO Application Programming
 
Ebc7fc8ba9801f03982acec158fa751744ca copie
Ebc7fc8ba9801f03982acec158fa751744ca   copieEbc7fc8ba9801f03982acec158fa751744ca   copie
Ebc7fc8ba9801f03982acec158fa751744ca copie
 
Lect05 Prog Model
Lect05 Prog ModelLect05 Prog Model
Lect05 Prog Model
 
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (3)
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Alp 05
Alp 05Alp 05
Alp 05
 

Más de Vaibhav Bajaj (20)

Stroustrup c++0x overview
Stroustrup c++0x overviewStroustrup c++0x overview
Stroustrup c++0x overview
 
P smile
P smileP smile
P smile
 
Ppt history-of-apple2203 (1)
Ppt history-of-apple2203 (1)Ppt history-of-apple2203 (1)
Ppt history-of-apple2203 (1)
 
Os
OsOs
Os
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
 
Oop1
Oop1Oop1
Oop1
 
Mem hierarchy
Mem hierarchyMem hierarchy
Mem hierarchy
 
Database
DatabaseDatabase
Database
 
C++0x
C++0xC++0x
C++0x
 
Blu ray disc slides
Blu ray disc slidesBlu ray disc slides
Blu ray disc slides
 
Assembler
AssemblerAssembler
Assembler
 
Projection of solids
Projection of solidsProjection of solids
Projection of solids
 
Projection of planes
Projection of planesProjection of planes
Projection of planes
 
Ortographic projection
Ortographic projectionOrtographic projection
Ortographic projection
 
Isometric
IsometricIsometric
Isometric
 
Intersection 1
Intersection 1Intersection 1
Intersection 1
 
Important q
Important qImportant q
Important q
 
Eg o31
Eg o31Eg o31
Eg o31
 
Development of surfaces of solids
Development of surfaces of solidsDevelopment of surfaces of solids
Development of surfaces of solids
 
Development of surfaces of solids copy
Development of surfaces of solids   copyDevelopment of surfaces of solids   copy
Development of surfaces of solids copy
 

Último

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

Assembler (2)

  • 2. Role of Assembler Source Object Assembler Linker Program Code Executable Code Loader Chap 2
  • 3. Chapter 2 -- Outline s Basic Assembler Functions s Machine-dependent Assembler Features s Machine-independent Assembler Features s Assembler Design Options Chap 2
  • 4. Introduction to Assemblers s Fundamental functions x translating mnemonic operation codes to their machine language equivalents x assigning machine addresses to symbolic labels s Machine dependency x different machine instruction formats and codes Chap 2
  • 5. Example Program (Fig. 2.1) s Purpose x reads records from input device (code F1) x copies them to output device (code 05) x at the end of the file, writes EOF on the output device, then RSUB to the operating system x program Chap 2
  • 6. Example Program (Fig. 2.1) s Data transfer (RD, WD) x a buffer is used to store record x buffering is necessary for different I/O rates x the end of each record is marked with a null character (0016) x the end of the file is indicated by a zero-length record s Subroutines (JSUB, RSUB) x RDREC, WRREC x save link register first before nested jump Chap 2
  • 7. Assembler Directives s Pseudo-Instructions x Not translated into machine instructions x Providing information to the assembler s Basic assembler directives x START x END x BYTE x WORD x RESB x RESW Chap 2
  • 8. Object Program s Header Col. 1 H Col. 2~7 Program name Col. 8~13 Starting address (hex) Col. 14-19 Length of object program in bytes (hex) s Text Col.1 T Col.2~7 Starting address in this record (hex) Col. 8~9 Length of object code in this record in bytes (hex) Col. 10~69Object code (69-10+1)/6=10 instructions s End Col.1 E Col.2~7 Address of first executable instruction (hex) (END program_name) Chap 2
  • 9. Fig. 2.3 H COPY 001000 00107A T 001000 1E 141033 482039 001036 281030 301015 482061 ... T 00101E 15 0C1036 482061 081044 4C0000 454F46 000003 000000 T 002039 1E 041030 001030 E0205D 30203F D8205D 281030 … T 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064 … T 002073 07 382064 4C0000 05 E 001000 Chap 2
  • 10. Figure 2.1 (Pseudo code) Program copy { save return address; cloop: call subroutine RDREC to read one record; if length(record)=0 { call subroutine WRREC to write EOF; } else { call subroutine WRREC to write one record; goto cloop; } load return address return to caller } Chap 2
  • 11. An Example (Figure 2.1, Cont.) EOR: Subroutine RDREC { character x‘00’ clear A, X register to 0; rloop: read character from input device to A register if not EOR { store character into buffer[X]; X++; if X < maximum length goto rloop; } store X to length(record); return } Chap 2
  • 12. An Example (Figure 2.1, Cont.) Subroutine WDREC { clear X register to 0; wloop: get character from buffer[X] write character from X to output device X++; if X < length(record) goto wloop; return } Chap 2
  • 13. Assembler’s functions s Convert mnemonic operation codes to their machine language equivalents s Convert symbolic operands to their equivalent machine addresses  s Build the machine instructions in the proper format s Convert the data constants to internal machine representations s Write the object program and the assembly listing Chap 2
  • 14. Example of Instruction Assemble STCH BUFFER,X 549039 8 1 15 opcode x address m (54)16 1 (001)2 (039)16 s Forward reference Chap 2
  • 15. Difficulties: Forward Reference s Forward reference: reference to a label that is defined later in the program. Loc Label Operator Operand 1000 FIRST STL RETADR 1003 CLOOP JSUB RDREC … … … … … 1012 J CLOOP … … … … … 1033 RETADR RESW 1 Chap 2
  • 16. Two Pass Assembler s Pass 1 x Assign addresses to all statements in the program x Save the values assigned to all labels for use in Pass 2 x Perform some processing of assembler directives s Pass 2 x Assemble instructions x Generate data values defined by BYTE, WORD x Perform processing of assembler directives not done in Pass 1 x Write the object program and the assembly listing Chap 2
  • 17. Two Pass Assembler s Read from input line x LABEL, OPCODE, OPERAND Source program Intermediate Object Pass 1 Pass 2 file codes OPTAB SYMTAB SYMTAB Chap 2
  • 18. Data Structures s Operation Code Table (OPTAB) s Symbol Table (SYMTAB) s Location Counter(LOCCTR) Chap 2
  • 19. OPTAB (operation code table) s Content x menmonic, machine code (instruction format, length) etc. s Characteristic x static table s Implementation x array or hash table, easy for search Chap 2
  • 20. SYMTAB (symbol table) s Content COPY 1000 x label name, value, flag, (type, length) etc.1000 FIRST CLOOP 1003 s Characteristic ENDFIL 1015 EOF 1024 x dynamic table (insert, delete, search) THREE 102D s Implementation ZERO 1030 RETADR 1033 x hash table, non-random keys, hashing function LENGTH 1036 BUFFER 1039 RDREC 2039 Chap 2
  • 21. Homework #3 SUM START 4000 FIRST LDX ZERO LDA ZERO LOOP ADD TABLE,X TIX COUNT JLT LOOP STA TOTAL RSUB TABLE RESW 2000 COUNT RESW 1 ZERO WORD 0 TOTAL RESW 1 END FIRST Chap 2
  • 22. Assembler Design s Machine Dependent Assembler Features x instruction formats and addressing modes x program relocation s Machine Independent Assembler Features x literals x symbol-defining statements x expressions x program blocks x control sections and program linking Chap 2
  • 23. Machine-dependent Assembler Features Sec. 2-2 s Instruction formats and addressing modes s Program relocation
  • 24. Instruction Format and Addressing Mode s SIC/XE x PC-relative or Base-relative addressing: op m x Indirect addressing: op @m x Immediate addressing: op #c x Extended format: +op m x Index addressing: op m,x x register-to-register instructions x larger memory -> multi-programming (program allocation) s Example program Chap 2
  • 25. Translation s Register translation x register name (A, X, L, B, S, T, F, PC, SW) and their values (0,1, 2, 3, 4, 5, 6, 8, 9) x preloaded in SYMTAB s Address translation x Most register-memory instructions use program counter relative or base relative addressing x Format 3: 12-bit address field 3 base-relative: 0~4095 3 pc-relative: -2048~2047 x Format 4: 20-bit address field Chap 2
  • 26. PC-Relative Addressing Modes s PC-relative x 10 0000 FIRST STL RETADR 17202D op(6) n I xbp e disp(12) (14)16 110010 (02D) 16 3 displacement= RETADR - PC = 30-3 = 2D x 40 0017 J CLOOP 3F2FEC op(6) n I xbp e disp(12) (3C)16 110010 (FEC) 16 3 displacement= CLOOP-PC= 6 - 1A= -14= FEC Chap 2
  • 27. Base-Relative Addressing Modes s Base-relative x base register is under the control of the programmer x 12 LDB #LENGTH x 13 BASE LENGTH x 160 104E STCH BUFFER, X 57C003 op(6) n I xbp e disp(12) ( 54 )16 111100 ( 003 ) 16 (54) 111010 0036-1051= -101B16 3 displacement= BUFFER - B = 0036 - 0033 = 3 x NOBASE is used to inform the assembler that the contents of the base register no longer be relied upon for addressing Chap 2
  • 28. Immediate Address Translation s Immediate addressing x 55 0020 LDA #3 010003 op(6) n I xbp e disp(12) ( 00 )16 010000 ( 003 ) 16 x 133 103C +LDT #4096 75101000 op(6) n I xbp e disp(20) ( 74 )16 010001 ( 01000 ) 16 Chap 2
  • 29. Immediate Address Translation (Cont.) s Immediate addressing x 12 0003 LDB #LENGTH 69202D op(6) n I xbp e disp(12) ( 68)16 010010 ( 02D ) 16 ( 68)16 010000 ( 033)16 690033 3 the immediate operand is the symbol LENGTH 3 the address of this symbol LENGTH is loaded into register B 3 LENGTH=0033=PC+displacement=0006+02D 3 if immediate mode is specified, the target address becomes the operand Chap 2
  • 30. Indirect Address Translation s Indirect addressing x target addressing is computed as usual (PC- relative or BASE-relative) x only the n bit is set to 1 x 70 002A J @RETADR 3E2003 op(6) n I xbp e disp(12) ( 3C )16 100010 ( 003 ) 16 3 TA=RETADR=0030 3 TA=(PC)+disp=002D+0003 Chap 2
  • 31. Program Relocation s Example Fig. 2.1 x Absolute program, starting address 1000 e.g. 55 101B LDA THREE 00102D x Relocate the program to 2000 e.g. 55 101B LDA THREE 00202D x Each Absolute address should be modified s Example Fig. 2.5: x Except for absolute address, the rest of the instructions need not be modified 3 not a memory address (immediate addressing) 3 PC-relative, Base-relative x The only parts of the program that require modification at load time are those that specify direct addresses Chap 2
  • 32. Example Chap 2
  • 33. Relocatable Program s Modification record x Col 1 M x Col 2-7 Starting location of the address field to be modified, relative to the beginning of the program x Col 8-9 length of the address field to be modified, in half- bytes Chap 2
  • 34. Object Code Chap 2
  • 35. Machine-Independent Assembler Features Literals Symbol Defining Statement Expressions Program Blocks Control Sections and Program Linking
  • 36. Literals s Design idea x Let programmers to be able to write the value of a constant operand as a part of the instruction that uses it. x This avoids having to define the constant elsewhere in the program and make up a label for it. s Example x e.g. 45 001A ENDFIL LDA =C’EOF’ 032010 x 93 LTORG x 002D * =C’EOF’ 454F46 x e.g. 215 1062 WLOOP TD =X’05’ E32011 Chap 2
  • 37. Literals vs. Immediate Operands s Immediate Operands x The operand value is assembled as part of the machine instruction x e.g. 55 0020 LDA #3 010003 s Literals x The assembler generates the specified value as a constant at some other memory location x e.g. 45 001A ENDFILLDA =C’EOF’ 032010 s Compare (Fig. 2.6) x e.g. 45 001A ENDFIL LDA EOF 032010 x 80 002D EOF BYTE C’EOF’454F46 Chap 2
  • 38. Literal - Implementation (1/3) s Literal pools x Normally literals are placed into a pool at the end of the program 3 see Fig. 2.10 (END statement) x In some cases, it is desirable to place literals into a pool at some other location in the object program 3 assembler directive LTORG 3 reason: keep the literal operand close to the instruction Chap 2
  • 39. Literal - Implementation (2/3) s Duplicate literals x e.g. 215 1062 WLOOP TD =X’05’ x e.g. 230 106B WD =X’05’ x The assemblers should recognize duplicate literals and store only one copy of the specified data value 3 Comparison of the defining expression • Same literal name with different value, e.g. LOCCTR=* 3 Comparison of the generated data value • The benefits of using generate data value are usually not great enough to justify the additional complexity in the assembler Chap 2
  • 40. Literal - Implementation (3/3) s LITTAB x literal name, the operand value and length, the address assigned to the operand s Pass 1 x build LITTAB with literal name, operand value and length, leaving the address unassigned x when LTORG statement is encountered, assign an address to each literal not yet assigned an address s Pass 2 x search LITTAB for each literal operand encountered x generate data values using BYTE or WORD statements x generate modification record for literals that represent an address in the program Chap 2
  • 41. Symbol-Defining Statements s Labels on instructions or data areas x the value of such a label is the address assigned to the statement s Defining symbols x symbol EQU value x value can be: x constant, y other symbol, z expression x making the source program easier to understand x no forward reference Chap 2
  • 42. Symbol-Defining Statements s Example 1 x MAXLEN EQU 4096 x +LDT #MAXLEN +LDT #4096 s Example 2 (Many general purpose registers) x BASE EQU R1 x COUNT EQU R2 x INDEX EQU R3 s Example 3 x MAXLEN EQU BUFEND-BUFFER Chap 2
  • 43. ORG (origin) s Indirectly assign values to symbols s Reset the location counter to the specified value 3 ORG value s Value can be: x constant, y other symbol, z expression s No forward reference s Example x SYMBOL: 6bytes SYMBOL VALUE FLAGS x VALUE: 1word STAB x FLAGS: 2bytes (100 entries) x LDA VALUE, X . . . . . . . . . Chap 2
  • 44. ORG Example s Using EQU statements x STAB RESB 1100 x SYMBOL EQU STAB x VALUE EQU STAB+6 x FLAG EQU STAB+9 s Using ORG statements x STAB RESB 1100 x ORG STAB x SYMBOL RESB 6 x VALUE RESW 1 x FLAGS RESB 2 x ORG STAB+1100 Chap 2
  • 45. Expressions s Expressions can be classified as absolute expressions or relative expressions x MAXLEN EQU BUFEND-BUFFER x BUFEND and BUFFER both are relative terms, representing addresses within the program x However the expression BUFEND-BUFFER represents an absolute value s When relative terms are paired with opposite signs, the dependency on the program starting address is canceled out; the result is an absolute value Chap 2
  • 46. SYMTAB s None of the relative terms may enter into a multiplication or division operation s Errors: x BUFEND+BUFFER x 100-BUFFER x 3*BUFFER s The type of an expression x keep track of the types of all symbols defined in the program Symbol Type Value RETADR R 30 BUFFER R 36 BUFEND R 1036 MAXLEN A 1000 Chap 2
  • 47. Example 2.9 SYMTAB Name Value LITTAB COPY 0 C'EOF' 454F46 3 002D FIRST 0 X'05' 05 1 1076 CLOOP 6 ENDFIL 1A RETADR 30 LENGTH 33 BUFFER 36 BUFEND 1036 MAXLEN 1000 RDREC 1036 RLOOP 1040 EXIT 1056 INPUT 105C WREC 105D WLOOP 1062 Chap 2
  • 48. Program Blocks s Program blocks x refer to segments of code that are rearranged within a single object program unit x USE [blockname] x Default block x Example: Figure 2.11 x Each program block may actually contain several separate segments of the source program Chap 2
  • 49. Program Blocks - Implementation s Pass 1 x each program block has a separate location counter x each label is assigned an address that is relative to the start of the block that contains it x at the end of Pass 1, the latest value of the location counter for each block indicates the length of that block x the assembler can then assign to each block a starting address in the object program s Pass 2 x The address of each symbol can be computed by adding the assigned block starting address and the relative address of the symbol to that block Chap 2
  • 50. Figure 2.12 s Each source line is given a relative address assigned and a block number Block name Block number Address Length (default) 0 0000 0066 CDATA 1 0066 000B CBLKS 2 0071 1000 s For absolute symbol, there is no block number x line 107 s Example x 20 0006 0 LDA LENGTH 032060 x LENGTH=(Block 1)+0003= 0066+0003= 0069 x LOCCTR=(Block 0)+0009= 0009 Chap 2
  • 51. Program Readability s Program readability x No extended format instructions on lines 15, 35, 65 x No needs for base relative addressing (line 13, 14) x LTORG is used to make sure the literals are placed ahead of any large data areas (line 253) s Object code x It is not necessary to physically rearrange the generated code in the object program x see Fig. 2.13, Fig. 2.14 Chap 2
  • 53. Control Sections and Program Linking s Control Sections x are most often used for subroutines or other logical subdivisions of a program x the programmer can assemble, load, and manipulate each of these control sections separately x instruction in one control section may need to refer to instructions or data located in another section x because of this, there should be some means for linking control sections together x Fig. 2.15, 2.16 Chap 2
  • 54. External Definition and References s External definition x EXTDEF name [, name] x EXTDEF names symbols that are defined in this control section and may be used by other sections s External reference x EXTREF name [,name] x EXTREF names symbols that are used in this control section and are defined elsewhere s Example x 15 0003 CLOOP +JSUB RDREC 4B100000 x 160 0017 +STCH BUFFER,X 57900000 x 190 0028 MAXLEN WORD BUFEND-BUFFER 0000002 Chap
  • 55. Implementation s The assembler must include information in the object program that will cause the loader to insert proper values where they are required s Define record x Col. 1 D x Col. 2-7 Name of external symbol defined in this control section x Col. 8-13 Relative address within this control section (hexadeccimal) x Col.14-73 Repeat information in Col. 2-13 for other external symbols s Refer record x Col. 1 D x Col. 2-7 Name of external symbol referred to in this control section x Col. 8-73 Name of other external reference symbols Chap 2
  • 56. Modification Record s Modification record x Col. 1 M x Col. 2-7 Starting address of the field to be modified (hexiadecimal) x Col. 8-9 Length of the field to be modified, in half-bytes (hexadeccimal) x Col.11-16 External symbol whose value is to be added to or subtracted from the indicated field x Note: control section name is automatically an external symbol, i.e. it is available for use in Modification records. s Example x Figure 2.17 x M00000405+RDREC x M00000705+COPY Chap 2
  • 57. External References in Expression s Earlier definitions x required all of the relative terms be paired in an expression (an absolute expression), or that all except one be paired (a relative expression) s New restriction x Both terms in each pair must be relative within the same control section x Ex: BUFEND-BUFFER x Ex: RDREC-COPY s In general, the assembler cannot determine whether or not the expression is legal at assembly time. This work will be handled by a Chap 2 linking loader.
  • 58. Assembler Design Options One-pass assemblers Multi-pass assemblers Two-pass assembler with overlay structure
  • 59. Two-Pass Assembler with Overlay Structure s For small memory x pass 1 and pass 2 are never required at the same time x three segments 3 root: driver program and shared tables and subroutines 3 pass 1 3 pass 2 x tree structure x overlay program Chap 2
  • 60. One-Pass Assemblers s Main problem x forward references 3 data items 3 labels on instructions s Solution x data items: require all such areas be defined before they are referenced x labels on instructions: no good solution Chap 2
  • 61. One-Pass Assemblers s Main Problem x forward reference 3 data items 3 labels on instructions s Two types of one-pass assembler x load-and-go 3 produces object code directly in memory for immediate execution x the other 3 produces usual kind of object code for later execution Chap 2
  • 62. Load-and-go Assembler s Characteristics x Useful for program development and testing x Avoids the overhead of writing the object program out and reading it back x Both one-pass and two-pass assemblers can be designed as load-and-go. x However one-pass also avoids the over head of an additional pass over the source program x For a load-and-go assembler, the actual address must be known at assembly time, we can use an absolute program Chap 2
  • 63. Forward Reference in One-pass Assembler s For any symbol that has not yet been defined 1. omit the address translation 2. insert the symbol into SYMTAB, and mark this symbol undefined 3. the address that refers to the undefined symbol is added to a list of forward references associated with the symbol table entry 4. when the definition for a symbol is encountered, the proper address for the symbol is then inserted into any instructions previous generated according to the forward reference list Chap 2
  • 64. Load-and-go Assembler (Cont.) s At the end of the program x any SYMTAB entries that are still marked with * indicate undefined symbols x search SYMTAB for the symbol named in the END statement and jump to this location to begin execution s The actual starting address must be specified at assembly time s Example x Figure 2.18, 2.19 Chap 2
  • 65. Producing Object Code s When external working-storage devices are not available or too slow (for the intermediate file between the two passes s Solution: x When definition of a symbol is encountered, the assembler must generate another Tex record with the correct operand address x The loader is used to complete forward references that could not be handled by the assembler x The object program records must be kept in their original order when they are presented to the loader s Example: Figure 2.20 Chap 2
  • 66. Multi-Pass Assemblers s Restriction on EQU and ORG x no forward reference, since symbols’ value can’t be defined during the first pass s Example x Use link list to keep track of whose value depend on an undefined symbol s Figure 2.21 Chap 2