23
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

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

Embed Size (px)

Citation preview

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

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

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

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

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

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)

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

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

PC-Relative Addressing Modes

PC-relative 10 0000 FIRST STL RETADR

17202D

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

40 0017 J CLOOP 3F2FEC

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

op(6) n I x b p e disp(12)

op(6) n I x b p e disp(12)

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

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

Immediate Address Translation

Immediate addressing 55 0020 LDA #3

010003

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

133 103C +LDT #409675101000

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

op(6) n I x b p e disp(12)

op(6) n I x b p e disp(20)

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

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

Immediate Address Translation (Cont.) Immediate addressing

12 0003 LDB #LENGTH69202D

( 68)16 0 1 0 0 1 0 ( 02D ) 16

( 68)16 0 1 0 0 0 0 ( 033)16 690033

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)

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

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

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)

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

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

Object Program

Page 16: G.Umamaheswari Lect/IT R.M.D.EC system software Assembler Assembler Definition Assembler functions Assembler Design Algorithms for two passes Example 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:

Page 17: G.Umamaheswari Lect/IT R.M.D.EC system software Assembler Assembler Definition Assembler functions Assembler Design Algorithms for two passes Example 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:

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

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

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

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

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

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

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

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

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

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

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

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

represent an address in the program