chapter 2b assembler-pass 1 of two pass assembler

86
Chapter 2: Assemblers Mrs. Sunita M Dol (Aher), Assistant Professor, Computer Science and Engineering Department, Walchand Institute of Technology, Solapur, Maharashtra

Upload: sunita-aher

Post on 14-Apr-2017

429 views

Category:

Engineering


9 download

TRANSCRIPT

Page 1: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

Chapter 2: Assemblers

Mrs. Sunita M Dol (Aher),Assistant Professor,

Computer Science and Engineering Department,Walchand Institute of Technology, Solapur, Maharashtra

Page 2: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 2

• Elements of Assembly Language Programming• A Simple Assembly Scheme• Pass Structure of Assemblers• Design of a Two Pass Assembler• A Single Pass Assembler for IBM PC

2. Assemblers

Page 3: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 3

1) Loc_cntr:=0;(default value) Pooltab_ptr:=;POOLTAB[1]:=1; Littab_ptr:=1;

2) While next statement is not an END statement a) If label is present

This_label :=symbol in label field: Enter(this_label,loc_cntr)in SYMTAB

Algorithm for PASS-I

Page 4: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 4

b) If an LTORG statement then i) Process literals LITTAB[POOLTAB[pooltab_ptr]]

…LITTAB[littab_ptr-1] to allocate memory and put the address in the address field. Update loc_cntr accordingly.

ii)Pooltab_ptr:=pooltab_ptr+1; iii)POOLTAB[pooltab_ptr]:=littab_ptr;

Page 5: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 5

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

d) If an EQU statement then i) This _addr:=value of <address spec>; ii) Correct the SYMTAB entry for this_label to

(this_label,this_addr).

e)If a declaration statement then i)Code :=code of the declaration statement; ii)Size:=size of memory area required by DC/DS. iii)Loc_cntr:=loc_cntr+size: iv)(Generate IC ‘(DL,code)….’.

Page 6: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 6

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 literal then

this_literal:=lliteral in operand field;LITTAB[littab_ptr]:=this_literal;littab_ptr:=littab_ptr+1;

Else (i.e. operand is a symbol)this_entry := SYMTAB entry number of operand;

Generate IC ‘(IS,code)(S,this_entry)’;

Page 7: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 7

3) (Processing of END statement)a)Perform step 2(b).b)Generate IC ‘(AD,02)’.c)Go to Pass 2.

Page 8: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

s

Page 9: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 9

a

This_Label = Symbolic name in label field

Enter (This_Label, Location_Counter) in

Symbol Table

s

Label?

Page 10: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

s

Page 11: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 11

b

Process literals LITERAL_TABLE[POOL_TABLE[POOL_Table_Pointer]]…

LITERAL_TABLE[Literal_Table_Pointer – 1]] to allocate memory and put addresses in address field

Update Location_Counter

POOL_Table_Pointer = POOL_Table_Pointer + 1

POOL_TABLE [POOL_Table_Pointer ] = Literal_Table_Pointer

s

LTORG?

Page 12: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

s

Page 13: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 13

c

Location_Counter = Value specified in Operand Field

START or ORGIN?

s

Generate Intermediate Code ‘(IS, Code)(S, This_Entry)’

Page 14: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

s

Page 15: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 15

d

This_Address = Value specified in operand field

Correct the Symbol Table Entry for This_Label to (This_Label,

This_Address)

s

EQU?

Page 16: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

s

Page 17: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 17

e

Code = Code of the declaration statement

Size = Size of memory area required by DC/DS

Location_Counter = Location_Counter + Size

s

Generate Intermediate Code ‘(DL, Code)….’

Declaration Statement?

Page 18: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

s

Page 19: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 19

f

Code = Machine Opcode from OPTAB

Location_Counter = Location_Counter + Instruction Length from OPTAB

Is Operand Literal?

This_Literal = Literal in Operand Field

LITERAL_TABLE[Literal_Table_Pointer] = This_Literal

Literal_Table_Pointer = Literal_Table_Pointer + 1

This_Entry = SYMBOL_TABLE entry number of Operand

s

Generate Intermediate Code ‘(IS, Code) Register_Operand

(S, This_Entry)’

Imperative Statement?

Yes No

Generate Intermediate Code ‘(IS, Code) Register_Operand

(L, This_Literal)’

Page 20: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 20

a b c d e f

Perform Step b

Go to Pass-II

Generate Intermediate Code ‘(AD, 02)’

Processing of END

statement

g

Page 21: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 21

Mnemonic Opcode Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 22: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 22

START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 23: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 23

(AD, 01) (C, 100) (IS, 04) AREG, A (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 5) (DL, 01) (C, 8) (DL, 02) (C, 1)

LC

100101102103104105106

Intermediate RepresentationSource Program

Symbol Address Length

A 104 1

B 105 1

C 106 1

Symbol Table

START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 24: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 24

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

s

Location_ Counter = 0

Page 25: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 25

c

Location_Counter = Value specified in Operand Field

s

START or ORGIN?

Location_ Counter = 100

Generate Intermediate Code ‘(AD, Code)(C, Constant)’ (AD, 01)(C, 100)

Location_Counter =100

START 100

Page 26: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 26

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 100

Intermediate Code(AD, 01)(C, 100)

s

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 27: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 27

f

Code = Machine Opcode from OPTAB

Location_Counter = Location_Counter + Instruction Length from OPTAB

Is Operand Literal?

This_Entry = SYMBOL_TABLE entry number of Operand

s

Generate Intermediate Code ‘(IS, Code) Register_Operand,

(S, This_Entry)’

Imperative Statement?

Location_ Counter = 100

Location_Counter = 100+1

=101

START 100 MOVER AREG, A

No

(IS, 04) AREG, A

Code = 04

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 28: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 28

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 101

Intermediate Code(AD, 01)(C, 100)

(IS, 04) AREG, A

s

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 29: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 29

f

Code = Machine Opcode from OPTAB

Location_Counter = Location_Counter + Instruction Length from OPTAB

Is Operand Literal?

This_Entry = SYMBOL_TABLE entry number of Operand

s

Generate Intermediate Code ‘(IS, Code) Register_Operand,

(S, This_Entry)’

Imperative Statement?

Location_ Counter = 101

Location_Counter = 101+1

=102

START 100 MOVER AREG, A ADD AREG, B

No

(IS, 01) AREG, B

Code = 01

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 30: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 30

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 102

Intermediate Code(AD, 01)(C, 100)

(IS, 04) AREG, A (IS, 01) AREG, B

s

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 31: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 31

f

Code = Machine Opcode from OPTAB

Location_Counter = Location_Counter + Instruction Length from OPTAB

Is Operand Literal?

This_Entry = SYMBOL_TABLE entry number of Operand

s

Generate Intermediate Code ‘(IS, Code) Register_Operand,

(S, This_Entry)’

Imperative Statement?

Location_ Counter = 102

Location_Counter = 102+1

=103

START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C

No

(IS, 05) AREG, C

Code = 05

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 32: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 32

START

Location_Counter =0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 103

Intermediate Code(AD, 01)(C, 100)

(IS, 04) AREG, A (IS, 01) AREG, B (IS, 05) AREG, C

s

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 33: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 33

f

Code = Machine Opcode from OPTAB

Location_Counter = Location_Counter + Instruction Length from OPTAB

Is Operand Literal?

This_Entry = SYMBOL_TABLE entry number of Operand

s

Generate Intermediate Code ‘(IS, Code) Register_Operand,

(S, This_Entry)’

Imperative Statement?

Location_ Counter = 103

Location_Counter = 103+1

=104

START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP

No

(IS, 00)

Code = 01

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 34: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 34

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 104

Intermediate Code(AD, 01)(C, 100)

(IS, 04) AREG, A (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00)

s

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 35: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 35

a

This_Label = Symbolic name in label field

Enter (This_Label, Location_Counter) in

Symbol Table

s

Label?

Symbol Address Length

A 104 1

Symbol Table

Location_ Counter = 104

This_Label = A

START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOPA DC ‘5’

Page 36: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 36

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 104

Intermediate Code(AD, 01)(C, 100)

(IS, 04) AREG, A (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00)

s

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 37: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 37

e

Code = Code of the declaration statement

Size = Size of memory area required by DC/DS

Location_Counter = Location_Counter + Size

s

Generate Intermediate Code ‘(DL, Code)….’

Declaration Statement?

Location_ Counter = 104

Code = 01

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOPA DC ‘5’

Size = 1Location_Counter

= 104+1=105

(DL, 01) (C, 5)

Page 38: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 38

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 105

Intermediate Code(AD, 01)(C, 100)

(IS, 04) AREG, A (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 5)

s

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 39: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 39

a

This_Label = Symbolic name in label field

Enter (This_Label, Location_Counter) in

Symbol Table

s

Label?

Symbol Address Length

A 104 1

B 105 1

Symbol Table

Location_ Counter = 105

This_Label = B

START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOPA DC ‘5’B DC ‘8’

Page 40: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 40

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 105

Intermediate Code(AD, 01)(C, 100)

(IS, 04) AREG, A (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 5)

s

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 41: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 41

e

Code = Code of the declaration statement

Size = Size of memory area required by DC/DS

Location_Counter = Location_Counter + Size

s

Generate Intermediate Code ‘(DL, Code)….’

Declaration Statement?

Location_ Counter = 105

Code = 01

START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOPA DC ‘5’B DC ‘8’

Size = 1Location_Counter

= 105+1=106

(DL, 01) (C, 8)

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 42: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 42

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 106

Intermediate Code(AD, 01)(C, 100)

(IS, 04) AREG, A (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 5) (DL, 01) (C, 8)

s

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 43: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 43

a

This_Label = Symbolic name in label field

Enter (This_Label, Location_Counter) in

Symbol Table

s

Label?

Symbol Address Length

A 104 1

B 105 1

C 106 1

Symbol Table

Location_ Counter = 106

This_Label = C

START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOPA DC ‘5’B DC ‘8’C DS 1

Page 44: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 44

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 106

Intermediate Code(AD, 01)(C, 100)

(IS, 04) AREG, A (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 5) (DL, 01) (C, 8)

s

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 45: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 45

e

Code = Code of the declaration statement

Size = Size of memory area required by DC/DS

Location_Counter = Location_Counter + Size

s

Generate Intermediate Code ‘(DL, Code)….’

Declaration Statement?

Location_ Counter = 105

Code = 01

START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOPA DC ‘5’B DC ‘8’C DS 1

Size = 1Location_Counter

= 106+1=107

(DL, 02) (C, 1)

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 46: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 46

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 107

Intermediate Code(AD, 01)(C, 100)

(IS, 04) AREG, A (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 5) (DL, 01) (C, 8) (DL, 02) (C, 1)

s

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Page 47: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 47

a b c d e f

Perform Step b

Go to Pass-II

Generate Intermediate Code ‘(AD, 02)’

Processing of END

statement

(AD, 02)

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOPA DC ‘5’B DC ‘8’C DS 1 END

Location_ Counter = 107

Intermediate Code(AD, 01)(C, 100)

(IS, 04) AREG, A (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 5) (DL, 01) (C, 8) (DL, 02) (C, 1)

g

Page 48: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 48

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOPA DC ‘5’B DC ‘8’C DS 1 END

Intermediate Code (AD, 01) (C, 100) (IS, 04) AREG, A (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 5) (DL, 01) (C, 8) (DL, 02) (C, 1) (AD, 02)

Symbol Address Length

A 104 1

B 105 1

C 106

Symbol Table

Page 49: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 49

Mnemonic Opcode Class .Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

Page 50: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 50

START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOP B DC ‘8’ C DS 1 END

Page 51: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 51

(AD, 01) (C, 100) (IS, 04) AREG, (L,01) (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 8) (DL, 02) (C, 1)

LC

100101102103104105106

Intermediate RepresentationSource Program

START 100 MOVER AREG,=‘5’ ADD AREG, B MOVEM AREG, C STOP A DC ‘5’ B DC ‘8’ C DS 1 END

Symbol Address Length

B 104 1

C 105 1

Symbol Table

Literal_Table_Pointer

Literal Address

1 =‘5’ 106

2

POOL_Table_Pointer

Literal_Table_Pointer

1 1

2 2

Literal Table POOL Table

Page 52: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 52

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOP B DC ‘8’ C DS 1 END

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

s

Location_ Counter = 0

Page 53: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 53

c

Location_Counter = Value specified in Operand Field

s

START or ORGIN?

Location_ Counter = 100

Generate Intermediate Code ‘(AD, Code)(C, Constant)’ (AD, 01)(C, 100)

Location_Counter =100

START 100

Page 54: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 54

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 100

Intermediate Code(AD, 01)(C, 100)

s

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOP B DC ‘8’ C DS 1 END

Page 55: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 55

START 100 MOVER AREG, =‘5’

Location_ Counter = 100Literal_Table_Pointer = 1POOL_Table_Pointer = 1

Location_Counter = 100+1

=101Code = 04

f

Code = Machine Opcode from OPTAB

Location_Counter = Location_Counter + Instruction Length from OPTAB

Is Operand Literal?

This_Literal = Literal in Operand Field

LITERAL_TABLE[Literal_Table_Pointer] = This_Literal

Literal_Table_Pointer = Literal_Table_Pointer + 1

s

Imperative Statement?

Yes

Generate Intermediate Code ‘(IS, Code) Register_Operand

(L, This_Literal)’

Code = “=‘5’”

LITERAL_TABLE[1] = “=‘5’”

Literal_Table_Pointer = 1+1 = 2

Literal_Table_Pointer

Literal Address

1 =‘5’

2

(IS, 04) AREG, (L,01)

Literal Table

POOL_Table_Pointer

Literal_Table_Pointer

1 1

POOL Table

Page 56: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 56

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 101Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Intermediate Code (AD, 01)(C, 100) (IS, 04) AREG, (L,01)

s

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOP B DC ‘8’ C DS 1 END

Page 57: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 57

f

Code = Machine Opcode from OPTAB

Location_Counter = Location_Counter + Instruction Length from OPTAB

Is Operand Literal?

This_Entry = SYMBOL_TABLE entry number of Operand

s

Generate Intermediate Code ‘(IS, Code) Register_Operand,

(S, This_Entry)’

Imperative Statement?

Location_ Counter = 101Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Location_Counter = 101+1

=102

START 100 MOVER AREG, =‘5’ ADD AREG, B

No

(IS, 01) AREG, B

Code = 01

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 58: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 58

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 102Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Intermediate Code (AD, 01)(C, 100) (IS, 04) AREG, (L,01) (IS, 01) AREG, B

s

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOP B DC ‘8’ C DS 1 END

Page 59: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 59

f

Code = Machine Opcode from OPTAB

Location_Counter = Location_Counter + Instruction Length from OPTAB

Is Operand Literal?

This_Entry = SYMBOL_TABLE entry number of Operand

s

Generate Intermediate Code ‘(IS, Code) Register_Operand,

(S, This_Entry)’

Imperative Statement?

Location_ Counter = 102Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Location_Counter = 102+1

=103

START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C

No

(IS, 05) AREG, C

Code = 05

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 60: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 60

START

Location_Counter =0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 103Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Intermediate Code (AD, 01)(C, 100) (IS, 04) AREG, (L,01) (IS, 01) AREG, B (IS, 05) AREG, C

s

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOP B DC ‘8’ C DS 1 END

Page 61: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 61

f

Code = Machine Opcode from OPTAB

Location_Counter = Location_Counter + Instruction Length from OPTAB

Is Operand Literal?

This_Entry = SYMBOL_TABLE entry number of Operand

s

Generate Intermediate Code ‘(IS, Code) Register_Operand,

(S, This_Entry)’

Imperative Statement?

Location_ Counter = 103Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Location_Counter = 103+1

=104

START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOP

No

(IS, 00)

Code = 01

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 62: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 62

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 104Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Intermediate Code (AD, 01)(C, 100) (IS, 04) AREG, (L,01) (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00)

s

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOP B DC ‘8’ C DS 1 END

Page 63: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 63

a

This_Label = Symbolic name in label field

Enter (This_Label, Location_Counter) in

Symbol Table

s

Label?

Symbol Address Length

B 104 1

Symbol Table

Location_ Counter = 104Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

This_Label = B

START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOPB DC ‘8’

Page 64: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 64

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 104Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Intermediate Code (AD, 01)(C, 100) (IS, 04) AREG, A (IS, 04) AREG, (L,01) (IS, 05) AREG, C (IS, 00)

s

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOP B DC ‘8’ C DS 1 END

Page 65: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 65

e

Code = Code of the declaration statement

Size = Size of memory area required by DC/DS

Location_Counter = Location_Counter + Size

s

Generate Intermediate Code ‘(DL, Code)….’

Declaration Statement?

Location_ Counter = 104Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Code = 01

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOPB DC ‘8’

Size = 1Location_Counter

= 104+1=105

(DL, 01) (C, 8)

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 66: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 66

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 105Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Intermediate Code (AD, 01)(C, 100) (IS, 04) AREG, (L,01) (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (B, 8)

s

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOP B DC ‘8’ C DS 1 END

Page 67: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 67

a

This_Label = Symbolic name in label field

Enter (This_Label, Location_Counter) in

Symbol Table

s

Label?

Symbol Address Length

B 104 1

C 105 1

Symbol Table

Location_ Counter = 105Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

This_Label = C

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOPB DC ‘8’C DS 1

Page 68: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 68

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Location_ Counter = 105Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Intermediate Code (AD, 01)(C, 100) (IS, 04) AREG, (L,01) (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (B, 8)

s

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOP B DC ‘8’ C DS 1 END

Page 69: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 69

e

Code = Code of the declaration statement

Size = Size of memory area required by DC/DS

Location_Counter = Location_Counter + Size

s

Generate Intermediate Code ‘(DL, Code)….’

Declaration Statement?

Location_ Counter = 105Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Code = 01

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOPB DC ‘8’C DS 1

Size = 1Location_Counter

= 105+1=106

(DL, 02) (C, 1)

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

Page 70: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 70

START

Location_Counter = 0POOL_Table_Pointer = 1

POOL_TABLE[1]=1Literal_Table_Pointer = 1

While next statement is not end statement

Read Assembly program

Label?

LTORG?

START or ORGIN?

EQU?

Declaration Statement?

Imperative Statement?

a b c d e f

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOPB DC ‘8’C DS 1 END

Location_ Counter = 106Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Intermediate Code (AD, 01)(C, 100) (IS, 04) AREG, (L,01) (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 8) (DL, 02) (C, 1)

s

Page 71: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 71

a b c d e f

Perform Step b

Processing of END

statement

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOPB DC ‘8’C DS 1 END

Location_ Counter = 106Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Intermediate Code (AD, 01)(C, 100) (IS, 04) AREG, (L,01) (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 8) (DL, 02) (C, 1)

Page 72: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 72

b

Process literals LITERAL_TABLE[POOL_TABLE[POOL_Table_Pointer]]…

LITERAL_TABLE[Literal_Table_Pointer – 1]] to allocate memory and put addresses in address field

Update Location_Counter

POOL_Table_Pointer = POOL_Table_Pointer + 1

POOL_TABLE [POOL_Table_Pointer ] = Literal_Table_Pointer

b

LTORG?

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOPB DC ‘8’C DS 1 END

Location_ Counter = 106Literal_Table_Pointer = 1Literal_Table_Pointer = 2POOL_Table_Pointer = 1

Intermediate Code (AD, 01)(C, 100) (IS, 04) AREG, (L,01) (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 8) (DL, 02) (C, 1)

Literal_Table_Pointer

Literal Address

1 =‘5’ 106

2

Literal Table

POOL_Table_Pointer

Literal_Table_Pointer

1 1

2 2

POOL Table

Location_Counter = 106+1 =107

POOL_Table_Pointer = 1+1 = 2

POOL_TABLE[POOL_Table_Pointer]

=2

Page 73: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 73

a b c d e f

Perform Step b

Go to Pass-II

Generate Intermediate Code ‘(AD, 02)’

Processing of END

statement

(AD, 02)

g

Page 74: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 74

Source Program START 100 MOVER AREG, =‘5’ ADD AREG, B MOVEM AREG, C STOPB DC ‘8’C DS 1 END

Intermediate Code (AD, 01) (C, 100) (IS, 04) AREG, (L,01) (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 8) (DL, 02) (C, 1) (AD, 02)

Symbol Address Length

B 104 1

C 105

Symbol Table

Literal_Table_Pointer

Literal Address

1 =‘5’ 106

2

Literal Table

POOL_Table_Pointer

Literal_Table_Pointer

1 1

2 2

POOL Table

Page 75: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 75

Intermediate Code Forms

• The intermediate code consist of a set of IC unit, each IC unit consisting of following three fields– Address– Representation of the mnemonic opcode– Representation of operands

Address Opcode Operands

Page 76: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 76

Intermediate Code Forms

• Mnemonic field– Mnemonic field contains a pair of the form

(statement class, code)where statement class can be one of the following

IS – Imperative statementDL – Declaration statementAD – Assembler directives

and code is the instruction opcode in the machine language.

Page 77: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 77

Intermediate Code Forms

• Mnemonic field

Declaration statementDC 01DS 02

Assembler DirectivesSTART 01END 02

ORGIN 03EQU 04

LTORG 05

Page 78: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 78

Intermediate Code Forms

• Intermediate code for Imperative statement– The first operand is represented by a single digit

• 1-4 for AREG-DREG• 1-6 for LT-ANY

– The second operand which is a memory operand is represented by (operand class, code)where operand class is one of C, S, L.

Page 79: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 79

Intermediate Code Forms

• Intermediate code for Imperative statement– For constant, the code field contains the internal

representation of the constant itself. – For symbol or literals, code field contain the ordinal

number of the operand’s entry in SYMTAB or LITTAB

Page 80: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 80

Intermediate Code Forms

• Variant-I

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOPB DC ‘8’C DS 1

END

Intermediate Code (AD, 01) (C, 100) (IS, 04) (1), (L,01) (IS, 01) (1), (S, 01) (IS, 05) (1), (S, 02) (IS, 00) (DL, 01) (C, 8) (DL, 02) (C, 1) (DL, 01) (C, 5) (AD, 02)

Page 81: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 81

Intermediate Code Forms

• Variant-I– In Variant-I, two kinds of entries may exists in

SYMTAB at any time for defined symbol and for forward references.

Page 82: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 82

Intermediate Code Forms

• Variant-II– For declarative statements and assembler directives,

processing of the operand fields is essential to support LC processing.

– For imperative statements, the operand field is processed only to identify literal references.

– Symbolic references in the source statement are not processed at all during Pass-I

Page 83: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 83

Intermediate Code Forms

• Variant-II

Source Program START 100 MOVER AREG, A ADD AREG, B MOVEM AREG, C STOPB DC ‘8’C DS 1

END

Intermediate Code (AD, 01) (C, 100) (IS, 04) AREG, (L,01) (IS, 01) AREG, B (IS, 05) AREG, C (IS, 00) (DL, 01) (C, 8) (DL, 02) (C, 1) (DL, 01) (C, 5) (AD, 02)

Page 84: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 84

Intermediate Code Forms

• Comparison of Variant-I and Variant-II– Variant-I of the intermediate code appears to require

extra work in Pass-I.– IC is quite compact in Variant-I– Variant-II reduces the work of pass-I by transferring

the burden of operand processing from Pass-I to Pass-II of the assembler.

– IC is less compact in Variant-II.

Page 85: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 85

Intermediate Code Forms

• Comparison of Variant-I and Variant-II– Memory requirement using Variant-I and Variant-II.

Pass-IPass-II Pass-I Pass-II

Data Structure

Data Structure

Data Structure

Data Structure

Work area

Work area

Work area

Work area

Page 86: Chapter 2b Assembler-Pass 1 of Two Pass Assembler

05/02/2023 Mrs. Sunita M Dol, CSE Dept 86

Intermediate Code Forms

• Processing of Declaration & Assembler Directives– DC: A DC statement must be represented in IC– START or ORIGIN: It is not necessary to retain START

and ORIGIN statement in IC if the IC contains an address field.

– LTORG: The IC for a literal can be made identical to the IC for a DC statement so that no special processing is required in Pass-II.