assembler1

30
ASSEMBLER

Upload: jayashri-kolekar

Post on 14-Feb-2017

119 views

Category:

Education


0 download

TRANSCRIPT

ASSEMBLER

05/01/2023jaya

2

ASSEMBLERFUNCTION OF AN ASSEMBLER

ASSEMBLY LANG.

PROGRAM

DATABASE

ASSEMBLERMACHINE LANG. &

OTHER INFORMATION FOR LOADER

05/01/2023jaya

3

ASSEMBLER General format for assembly language statement

Example:JOHN START 0FOUR DC F’4’A 2,FOUR

Opcode ------- 1 digitRegister operand ---------- 1 digitMemory operand ---------- 3 digits

[Label *] [opcode] [operand1]*, [operand2]*

05/01/2023jaya

4

ASSEMBLER LABEL FIELD

when processed by assembler it will store this label and its information.

Example:JHONDATA

05/01/2023jaya

5

ASSEMBLER Mnemonic Opcode Field

instructions Types of assembly statements

Imperative statementsDeclarative statementsDirective statements

05/01/2023jaya

6

ASSEMBLER Imperative statementsSpecifies the operation to be performed

during the execution of programExample:MOVEM AREG , BMOVER AREG , CADD AREG , ONECOMP AREG , =‘1’SUB BREG , =‘2’

constant

memory

register

05/01/2023jaya

7

ASSEMBLER Declarative Statements

declare constant or storage variable

Types of declarative statements:-DS(Declare Storage)ex: AB DS 1

X DS 200

DC(Declare Constant)ex: ONE DC 1

name

1 word mem.

05/01/2023jaya

8

ASSEMBLER Assembler Directive statements or pseudo

opsIt specifies the operation to be performed during the process of assembly .

Types of pseudo opcodes START END LTORG ORIGIN EQU

05/01/2023jaya

9

ASSEMBLER START

Tells the start of program Gives name to program Sets LC ex:

TEST STARTJHON START 484

05/01/2023jaya

10

ASSEMBLER END

Tells end of program. Ex: END

LTORG Tells the assembler to place the literals at an

earlier location Used in very long programs Ex: LTORG

05/01/2023jaya

11

ASSEMBLER ORIGIN

used to reset location counterdefault value of reset is LC=0

Ex:ORIGIN <address space>

05/01/2023jaya

12

ASSEMBLER EQU

allows to define variable

Syntax: <symbol> EQU <address space>

Ex: BASE EQU 15

05/01/2023jaya

13

ASSEMBLER Operand Field

with this assembler perform actions

Types of operandsRegisterSymbolLiteral

05/01/2023jaya

14

ASSEMBLER Advantages of assembler

Unambiguous code and compact

As close to machine as possible

Extremely fast

Compiled assembly programs are small

Storage can be allocated and deallocated dynamically.

05/01/2023jaya

15

ASSEMBLER Advantages of assembly Language

Easy to memorize

Mnemonic opcodes are helpful for diagnostics

Program modification is easy

Manual conversion of constants into machine representation

05/01/2023jaya

16

ASSEMBLER General Design Procedure

Specify the problem

Specify data structure

Define format of data structure

Specify algorithm

Look for modularity

Repeat 1 through 5 on modules

05/01/2023jaya

17

ASSEMBLER Statement of problem

Processing of each assembly instruction varies depending upon types of instruction.

Processing of each assembly instruction assembler processes each field of instruction.

In this labels or symbols can appear before they are defined, so it is convenient to make two passes over the input.

Passes of assembler Pass 1 Pass2 Generate instructions (basic requirement)

Evaluate the mnemonic in the operation field to produce its machine code Evaluate the subfields-find the value of each symbol, process literals and

assign addresses. Process pseudo ops

05/01/2023jaya

18

ASSEMBLER Pass1: purpose - define symbol and literals

Determine length of machine instructions(MOTGET1) Keep track of Location Counter(LC) Remember values of symbols until pass 2(STSTO) Process some pseudo ops , e.g. EQU, DS (POTGET1) Remember literals(LITSTO)

Pass2: purpose - generate object program Look up value of symbols(STGET) Generate instructions(MOTGET2) Generate data(for DS, DC, and literals) Process pseudo ops(POTGET2)

05/01/2023jaya

19

ASSEMBLER DATA STRUCTURES

second step of design procedure for assembler Pass 1 data base:

Input source program A Location Counter(LC), The Machine Opcode Table(MOT) The Pseudo Opcode Table(POT) The Symbol Table(ST) The Literal Table(LT) A copy of input used b pass2

05/01/2023jaya

20

ASSEMBLER DATA STRUCTURES

second step of design procedure for assembler Pass 2 data base:

Copy of source program input to pass 1 A Location Counter(LC), The Machine Opcode Table(MOT)(mnemonic, length, binary m/c

opcode and format) The Pseudo Opcode Table(POT) The Symbol Table(ST) The Base Table(BT) A workspace , INST A workspace, PRINT LINE A workspace PUNCH CARD Output deck of assembled instruction

05/01/2023jaya

21

ASSEMBLER MOT(Machine Op-code Table)

Mnemonic opcode (4 bytes)(char)

Binary opcode(1 byte)(hexadecimal)

InstructionLength(2 bits)(binary)

InstructionFormat(3 bit)(binary)

Not used in this design(3 bits)

“Abbb” 5A 10 001

“AHbb” 4A 10 001

“ALbb” 5E 10 001

“ALRb” 1E 01 000

“ARbb” 1A 01 000

--------------

------------ -------------- --------------

“MVCb” D2 11 100

000 RR001 RX010 RS011 SI100 SS

Instruction format

01 1 half words 2 bytes10 2 half words 4 bytes11 3 half words 6 bytes

Instruction length

6 bytes

05/01/2023jaya

22

ASSEMBLER MOT example

NAME MNEMONIC BINARY OPCODE

FORMAT

OPERANDS

Add(c) AR 1A RR R1,R2Add (c ) A 5A RX R1,D2(X2,B2)

Branch & link

BALR 05 RR R1,R2

Start I/O SIO 9C SI D1(B1)Move MVC D2 SS D1(L,B1),D2(B2)

05/01/2023jaya

23

ASSEMBLER POT (pseudo opcode table)

PSEUDO OPCODE(5 BYTES CHAR)

ADDRESS OF ROUTINES TO PROCESS PSEUDO OP(3 BYTES=24 BIT ADDRESS

”DROPb” P1 DROP

“ENDbb” P1 END

“EQUbb” P1 EQU

“START” P1 START

“ORIGIN” P1 USING

05/01/2023jaya

24

ASSEMBLER ST(symbol table) 14 bytes per entry

SYMBOL(8 BYTES CHAR)

VALUE(4 BYTE)HEXADECIMAL

LENGTH(1 BYTE)HEXADECIMAL

RELOCATION(1 BYTE)CHAR

“SSSSbbbb” 0000 01 “R”

“FOURbbbb” 0000 04 “R”

“FIVEbbbb” 0010 04 “R”

“TEMPbbbb” 0014 04 “R”

14 bytes per entry

05/01/2023jaya

25

ASSEMBLER LT(Literal table) 14 bytes per entry

LITERAL(8 BYTES CHAR)

VALUE(4 BYTE)HEXADECIMAL

LENGTH(1 BYTE)HEXADECIMAL

RELOCATION(1 BYTE)CHAR

A(DATA1) 0048 04 “R”

F’800’ 0060 04 “R”

05/01/2023jaya

26

ASSEMBLER BT(Base Table) 15 entries

AVAILABILITYINDICATOR(1 BYTE)CHAR

DESIGNED RELATIVE ADDRESS CONTENTS OF BASE REGISTER(3 BYTES = 24 BIT ADDRESS)HEXADECIMAL

“N” ------------------

“N” -----------------

----------------------- -----------------

“N” ----------

“Y” 00 00 00

N =register specified in USINGY= never specified

05/01/2023jaya

27

Pass 1

LC 0

Read card from file copy

READ1

Assign value to symbol in label

fieldSTSTO

L length

Process any literals, enter into literal table

LTSTO

Write copy of card on file for use by pass2

WRITE1

Search pseudo-op tablePOTGET1

Which one ?

Adjust LC to proper alignment

L length of data field

DLENGTH

Assign current value of LC to symbol

STSTO

Evaluate operand field

EVAL

Search machine-op tableMOTGET1 Assign

storage locations to

literalsLITASS

Rewind and reset copy file

On to pass 2

found

DSDC

NO

EQU USING ,

DROP ENDNot found

YES

LC LC + L

Is there symbol in label

field

05/01/2023jaya

28

Pass 2

LC 0

Read card from file copy

READ2

Enter base reg. no. and value into

base tableBTSTO

Get op-code byte and format codeL length

Type of instruction

Evaluate both register expressions and insert into

2nd byteEVAL

“punch”Assembled instruction

PUNCH

“print” assembly listing linePRINT

LC LC + L

Search pseudo-op tablePOTGET2

Which one ?

Adjust LC to proper alignment

L length of data field

DLENGTH

DC or DS

Evaluate register and index expressions and insert into 2nd

byteEVAL

Calculate effective address(EA) of operand

EVAL

Determine appropriate displacement and base register

D +C(B) =CABTGET

Put B & D into bytes 3 and 4

From constant and insert in assembled programDCGEN

Evaluate operand

EVALSearch pseudo-op table

MOTGET2

Print listingPRINT

Indicate base reg. no.

unavailableBTDROP

Generate literals for

entries in literal tableLTGEN

STOP

a

b

a

b

found

DSDC

DC

DS

EQUSTART

USINGDROP ENDNot

found

RXRR

05/01/2023jaya

29

ASSEMBLER Look for modularity PASS1 FUNCTIO

NDESCRIPTION

READ1 Read the next assembly source card.POTGET1 Search the pass 1 pseudo-op table(POT) for a match with the

operation field of the current source card.MOTGET1 Search the machine –op table (MOT) for a match with the

operation of the current source card.STSTO Store a label and its associated value into the symbol table

(ST)LTSTO Store a literal into the literal table(LT)WRITE1 Write a copy of the assembly source card on a storage device

for use by pass 2DLENGTH Scan operand field of DS or DC pseudo-op to determine the

amount of storage required.EVAL Evaluate an arithmetic expression consisting of constants and

symbols.STGET Search the symbol table(ST) for the entry corresponding to a

specific symbol.

05/01/2023jaya

30

ASSEMBLER Look for modularity PASS2 FUNCTIO

NDESCRIPTION

READ2 Read the next assembly source card from the file copy.POTGET2 Search the pass 2 pseudo-op table(POT) for a match with the

operation field of the current source card.MOTGET2 Search the machine –op table (MOT) for a match with the

operation of the current source card.EVAL Evaluate an arithmetic expression consisting of constants and

symbols.

PUNCH Convert generated instruction to card format.PRINT Convert relative location and generated code to character

format; print the line along with copy of the source card.DCGEN Process the fields of the DC pseudo-op to generate object code.

DLENGTH Scan operand field of DS or DC pseudo-op to determine the amount of storage required.

BTSTO Insert data into appropriate entry of Base Table(BT).BTDROP Insert “unavailable” indicator into appropriate entry of BT.

BTGET Convert affective address into base and displacement by searching BASE Table (BT) for available base registers.

LTGEN Generate code for literals(uses DCGEN)