G.Umamaheswari Lect/IT R. M.D.EC Assembler Assembler Definition Assembler functions Assembler Design Algorithms for two passes Example Program with object code Machine dependent Features Instruction formats and Addressing modes PC –relative and BASE relative
23
Embed
G.Umamaheswari Lect/IT R.M.D.EC system software Assembler Assembler Definition Assembler functions Assembler Design Algorithms for two passes Example Program.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
G.Umamaheswari Lect/IT R.M.D.EC system software
Assembler
Assembler Definition Assembler functions Assembler Design Algorithms for two passes Example Program with object code Machine dependent Features
Instruction formats and Addressing modes PC –relative and BASE relative
G.Umamaheswari Lect/IT R.M.D.EC system software
Assembler Design
Machine Dependent Features Instruction formats and addressing modes Program relocation
Machine independent features Literals Symbol defining statements Expressions Program blocks Control Sections and program linking
G.Umamaheswari Lect/IT R.M.D.EC system software
Assembler Design
Instruction Formats: Single Byte Two Byte: (Reg –Reg ) Format 3 type – (12-bit displacement value) Format 4 type – (20-bit displacement value)
the immediate operand is the symbol LENGTH the address of this symbol LENGTH is loaded into
register B LENGTH=0033=PC + displacement=0006+02D if immediate mode is specified, the target address
becomes the operand
op(6) n I x b p e disp(12)
G.Umamaheswari Lect/IT R.M.D.EC system software
Indirect Address Translation Indirect addressing
target addressing is computed as usual (PC-relative or BASE-relative)
only the n bit is set to 1
70 002A J @RETADR
: :
95 0030 RETADR RESW 1
G.Umamaheswari Lect/IT R.M.D.EC system software
Program Relocation
Why 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
time The 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
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-relative
From the object program, it is not possible to Distinguish the address and constant
The 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
Program relocation
G.Umamaheswari Lect/IT R.M.D.EC system software
For an address label, its address is assigned
relative to the start of the program (START 0) Produce a Modification record to store the
starting location and the length of the address
field to be modified. The command for the loader must also be a
part of the object program
Solving Relocation Problem
G.Umamaheswari Lect/IT R.M.D.EC system software
Modification Record
One modification record for each address to be modified
The 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 Record
Modification Record Col. 1 M Col. 2-7 Starting location of the address
field to be modified, relative to the beginning of the program.
Col. 8-9 Length 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-Literals
A 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-Literals
A 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
Literals The 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 Pool
Normally 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 a pool
at some other location in the object program Assembler directive LTORG
When 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 Pool
Normally 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 a pool
at some other location in the object program Assembler directive LTORG
When 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 Table
LITTAB Content
Literal name Operand value and length Address
LITTAB 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 Implementation
Pass 1 Build 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 Implementation
Pass 2 Search LITTAB for each literal operand
encountered Generate data values using BYTE or WORD
statements Generate Modification record for literals that