+ All Categories
Home > Documents > Asmblr-dmdhamdhare

Asmblr-dmdhamdhare

Date post: 27-Oct-2014
Category:
Upload: jagdish-bhanushali
View: 14 times
Download: 1 times
Share this document with a friend
Description:
assembler
Popular Tags:
21
ASSEMBLER First Pass
Transcript
Page 1: Asmblr-dmdhamdhare

ASSEMBLER

First Pass

Page 2: Asmblr-dmdhamdhare

START 200

MOVER AREG,=‘5’

LOOP MOVEM AREG,AN

----------

ADD CREG,=‘1’

---------

LTORG

=‘5’

=‘1’

NEXT SUB AREG,=’10’

--------

LAST STOP

ORIGIN LAST+2

AN DS 1

END

=’10’

Page 3: Asmblr-dmdhamdhare

START 200

MOVER AREG, =‘5’

LOOP MOVEM AREG,AN

----------

ADD CREG, =‘1’

---------

LTORG

=‘5’

=‘1’

NEXT SUB AREG,=’10’

--------

LAST STOP

ORIGIN LAST+2

AN DS 1

END

=’10’

200)

201)

202)

203)

204)

205)

206)

207)

208)

209)

(ORIGIN indicates LC should be set to address 211) given in operand)

212)

Page 4: Asmblr-dmdhamdhare

SYMBOL ADDRESS LENGTH

LOOP

NEXT

LAST

A

SYMTABliteral address

=‘5’

=‘1’

=’10’

LITTAB

LITERAL NO.

#1

#3

POOLTABMnemonic opcode

class Mnemonic info

MOVER IS (04,1)

DS DL R#7

START AD R#11

OPTAB

Page 5: Asmblr-dmdhamdhare

SYMBOL ADDRESS LENGTH

LOOP 201

NEXT 207

LAST 209

A 211

SYMTAB LITTAB

LITERAL NO.

#1

#3

POOLTABMnemonic opcode

class Mnemonic info

MOVER IS (04,1)

DS DL R#7

START AD R#11

OPTAB

literal address

=‘5’ 205

=‘1’ 206

=’10’ 212

Page 6: Asmblr-dmdhamdhare

Start

Initialize Data Structures

Read Next Statement

Label Present

Enter(Label, LC) into Symbol Table

Separate Label, Mnemonic and operand Fields

Type of Instruction

Yes

No

IS AD

DL

LC LC + Length

A

B C

D

Page 7: Asmblr-dmdhamdhare

Literal used

C A B

Pass II

No

YesEnter Into LITTAB

Calculate Storage

Size

Type of Directive

LTORGEND

ORIGIN

Allocate Literals, Update LITTAB,

POOLTAB

Evaluate Operand address

Correct SYMTAB

Entry

END

No

Yes

Update LC

Generate Intermediate

Code

D

Page 8: Asmblr-dmdhamdhare

1. Initialize Loc_cntr=0;

Pooltab_ptr=1;pooltab[1]=1;

Litttabptr=1;

2. While next statement is not END statement

(a) if label is present then

this_label=symbol in label field ;

Enter(this_label,loc_cntr) in SYMTAB

(b) if START or ORIGIN statement then

loc_cntr=value specified in operand field

(c) if a declaration statement then

code=code of declaration statement

Size=size of memory area required by DC/DS

Page 9: Asmblr-dmdhamdhare

loc_cntr=loc_cntr+size

generate IC (Intermediate Code)

d) If an EQU statement then

this_addr= value of <address spec>

correct the SYMTAB entry for this_label to (this_label,this_addr)

e) if an LTORG statement then

(i) Process literals of current pool. (repeat process for all the literals in the pool)

LITTAB[POOLTAB[pooltab_ptr]]=1st literal in pool

update loc_cntr accordingly.

(ii) pooltab_ptr=pooltab_ptr+1

(iii) POOLTAB[pooltab_ptr]=littab_ptr

LITTAB[POOLTAB[pooltab_ptr]]=LITTAB[POOLTAB[1]]=LITTAB[1]

Page 10: Asmblr-dmdhamdhare

(f) If an Imperative Statement then

(i) code=machine opcode from OPTAB

(ii) loc_cntr=loc_cntr+ instruction length from OPTAB

(iii) if operand is a literal then

this_literal = literal in operand field

LITTAB[litttab_ptr] = this_literal

littab_ptr=littab_ptr+1

else

this_entry=SYMTAB entry number of operand

generate IC

3) Generate IC

go to Pass II

Page 11: Asmblr-dmdhamdhare

Intermediate CodeVariant I Method

The intermediate code consists of a set of IC units.

Each IC unit consists of following three fields

1) Address

2) Representation of mnemonic opcode

3) Representation of operands

Address Mnemonic Opcode

Operands

210) ADD AREG, VAR

Page 12: Asmblr-dmdhamdhare

Mnemonic opcode field:-

it contains a pair of

( statement class, code)

where statement class can be one of

(i) Imperative Stmt (IS)

(ii) Declaration Stmt (DL)

(iii) Assembler Directive (AD)

For imperative Stmt code=instruction opcode

For DL Stmt code = 1 for DC and 2 for DS

For AD Stmt code = 1 for START

2 for END

3 for ORIGIN

4 for EQU

5 for LTORG

Page 13: Asmblr-dmdhamdhare

Intermediate Code (operand field)The first operand is represented by a single digit number.

It can be (i) code for register (1-4 for AREG-DREG)

(ii) condition code (1-6 for LT-ANY)

The second operand, which is a memory operand, is represented by a pair

( operand class , code)

Where operand class may be (i) C for constant

(ii) S for Symbol

(iii) L for literal

An code may be

(i) Internal representation of constant for constant

(ii) ordinal number of operand’s entry in SYMTAB or LITTAB

Page 14: Asmblr-dmdhamdhare

Example of IC

START 200 (AD,01) (C,200)

LOOP MOVER AREG, A (IS, 09) (1) (S,01)

{ HERE (IS,09 ) REPRESENT IMPERATIVE STMT AND IT’S OPCODE 09 AND (S,01) REPRESENT SYMBOL A AND ITS ENTRY NUMBER IN SYMTAB)

--------

--------

SUB AREG, =‘1’

Page 15: Asmblr-dmdhamdhare

If we are processing a forward reference , It is necessary to enter Symbol in SYMTAB (entry no). At this point address and length field of symbol can not be filled.

So we can use VARIANT II method

Page 16: Asmblr-dmdhamdhare

Intermediate CodeVariant II Method

LOOP MOVER AREG, A (IS,04) AREG,A

So Symbolic references are not processed during pass I in variant II method

Page 17: Asmblr-dmdhamdhare

PASS2 OF ASSEMBLER

Page 18: Asmblr-dmdhamdhare

MACHINE CODE BUFFER

it is an area for temporary storage.

CODE AREA

it is an memory area used for target code area.

Page 19: Asmblr-dmdhamdhare

It has been assumed that the target code is to be assembled in the area named code_area.

1. code_area_address : = address of code_area;pooltab_ptr : = 1;loc_cntr : = 0 ;

2. While next statement is not an END statementa) Clear machine_code_buffer;b) If an LTORG statement

(i) Process literals in LITTAB [POOLTAB[pooltab_ptr]]… assemble the literals in machine_code_buffer.

(ii) size : = size of memory area required for literals; (iii) pooltab_ptr : = Pooltab_ptr+1;

c) If a START or ORIGIN statement then (i) loc_cntr : = value specified in operand field;

(ii) size : = 0;d) If a declaration statement

(i) If a DC statement thenAssemble the constant in machine_code_buffer.

(ii) size : = size of memory area required by DC/DS;

Page 20: Asmblr-dmdhamdhare

e) If an imperative statement(i) Get operand address from SYMTAB or

LITTAB.(ii) Assemble instruction in

machine_code_buffer.(iii) Size : = size of instruction ;

f) If size != 0 then(i) Move contents of machine_code_buffer to the address

code_area_address + size(ii) Loc_cntr : = loc_cntr + size;

3) (Processing of END Statement) Perform steps 2(b) and 2(f) Write code_area into output file.

Page 21: Asmblr-dmdhamdhare

Explanation of pass 2

Suppose we are using starting address of code area =500

If START stmt is present then it shows that we have to load operand (address) into the loc_cntr. And the size of instruction is =0

If DC/DS is present than size = size of memory area required.

Now the condition of F) is true

So code area 500 + size will be executed.

And then we loc_cntr + size will be executed


Recommended