G.Umamaheswari Lect/IT R.M.D.EC system software Assembler Assembler Definition Assembler functions Assembler Design Algorithms for two passes Example Program

  • View
    233

  • Download
    0

Embed Size (px)

Text of G.Umamaheswari Lect/IT R.M.D.EC system software Assembler Assembler Definition Assembler functions...

  • Assembler Assembler DefinitionAssembler functionsAssembler DesignAlgorithms for two passesExample Program with object codeMachine dependent FeaturesInstruction formats and Addressing modesPC relative and BASE relative

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Assembler DesignMachine Dependent FeaturesInstruction formats and addressing modesProgram relocationMachine independent featuresLiterals Symbol defining statementsExpressionsProgram blocksControl Sections and program linking

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Assembler DesignInstruction Formats: Single ByteTwo Byte: (Reg Reg )Format 3 type (12-bit displacement value)Format 4 type (20-bit displacement value)

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • PC-Relative Addressing ModesPC-relative100000FIRSTSTLRETADR17202D

    (14)16 1 1 0 0 1 0(02D) 16 displacement= RETADR - PC = 30-3 = 2D400017JCLOOP3F2FEC

    (3C)16 1 1 0 0 1 0(FEC) 16 displacement= CLOOP-PC= 6 - 1A= -14= FEC

    G.Umamaheswari Lect/IT R.M.D.EC system software

    Sheet1

    Format 3e=0

    op(6)nIxbpedisp(12)

    Sheet1

    Format 3e=0

    op(6)nIxbpedisp(12)

  • Immediate Address TranslationImmediate addressing550020LDA#3010003

    ( 00 )16 0 1 0 0 0 0( 003 ) 16

    133103C +LDT#409675101000

    ( 74 )16 0 1 0 0 0 1( 01000 ) 16

    G.Umamaheswari Lect/IT R.M.D.EC system software

    Sheet1

    Format 3e=0

    op(6)nIxbpedisp(12)

    Sheet1

    Format 3e=0

    op(6)nIxbpedisp(20)

  • Immediate Address Translation (Cont.)Immediate addressing120003LDB#LENGTH69202D

    ( 68)16 0 1 0 0 1 0( 02D ) 16 ( 68)16 0 1 0 0 0 0 ( 033)16 690033the immediate operand is the symbol LENGTHthe address of this symbol LENGTH is loaded into register BLENGTH=0033=PC + displacement=0006+02Dif immediate mode is specified, the target address becomes the operand

    G.Umamaheswari Lect/IT R.M.D.EC system software

    Sheet1

    Format 3e=0

    op(6)nIxbpedisp(12)

  • Indirect Address TranslationIndirect addressingtarget addressing is computed as usual (PC-relative or BASE-relative)only the n bit is set to 170 002A J @RETADR: :95 0030 RETADR RESW 1

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Program RelocationWhy Relocation It is desirable to load and run several programs at the same time The system must be able to load programs into memory wherever there is space The exact starting address of the program is not known until load time

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • G.Umamaheswari Lect/IT R.M.D.EC system software

  • Absolute Program Program with starting address specified at assembly timeThe address may be invalid if the program is loaded into somewhere else. Example: 55 101B LDA THREE 00102D

    Reload the program starting at 300055 101B LDA THREE 00302D

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Program relocation

    The only parts of the program that require modification at load time are those that specify direct addresses The rest of the instructions need not be modified Not a memory address (immediate addressing) PC-relative, Base-relativeFrom the object program, it is not possible to Distinguish the address and constantThe assembler must keep some information to tell the loader about this relocated address. The object program that contains the modification record is called a relocatable program

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Solving Relocation ProblemFor an address label, its address is assignedrelative to the start of the program (START 0)Produce a Modification record to store thestarting location and the length of the addressfield to be modified.The command for the loader must also be apart of the object program

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Modification RecordOne modification record for each address to be modifiedThe length is stored in half-bytes (4 bits)The starting location is the location of the byte containing the leftmost bits of the address field to be modified.If the field contains an odd number of half-bytes, the starting location begins in the middle of the first byte.

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Modification RecordModification RecordCol. 1MCol. 2-7Starting location of the address field to be modified, relative to the beginning of the program.Col. 8-9Length of the address field to be modified, in half-bytes (Hex)

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Object Program

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Machine Dependent Features-LiteralsA literal is identified with the prefix =, followed by a specification of the literal value Examples:

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Machine Dependent Features-LiteralsA literal is identified with the prefix =, followed by a specification of the literal value Examples:

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Literals vs. Immediate Operands

    LiteralsThe assembler generates the specified value as a constant at some other memory location

    Immediate Operands The operand value is assembled as part of the machine instruction55 0020 LDA #3 010003

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Literals PoolNormally literals are placed into a pool at the end of the program (after the END statement)In some cases, it is desirable to place literals into apool at some other location in the object programAssembler directive LTORGWhen the assembler encounters a LTORG statement, it generates a literal pool (containing all literal operands used since previous LTORG)Reason: keep the literal operand close to the instruction Otherwise PC- relative addressing may not be allowed

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Literals PoolNormally literals are placed into a pool at the end of the program (after the END statement)In some cases, it is desirable to place literals into apool at some other location in the object programAssembler directive LTORGWhen the assembler encounters a LTORG statement, it generates a literal pool (containing all literal operands used since previous LTORG)Reason: keep the literal operand close to the instruction Otherwise PC- relative addressing may not be allowed

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Literal TableLITTAB Content Literal name Operand value and length AddressLITTAB is often organized as a hash table, using the literal name or value as the key

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Literal ImplementationPass 1Build LITTAB with literal name, operand value and length, leaving the address unassigned

    When LTORG or END statement is encountered, assign an address to each literal not yet assigned an address

    The location counter is updated to reflect the number of bytes occupied by each literal

    G.Umamaheswari Lect/IT R.M.D.EC system software

  • Literal ImplementationPass 2Search LITTAB for each literal operand encounteredGenerate data values using BYTE or WORD statementsGenerate Modification record for literals that represent an address in the program

    G.Umamaheswari Lect/IT R.M.D.EC system software