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

Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Embed Size (px)

Citation preview

Page 1: Chapter 2c Assembler-Pass 2 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 2c Assembler-Pass 2 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 2c Assembler-Pass 2 of Two Pass Assembler

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

Algorithm for PASS-II1. code_area_address := address of code_area; pooltab_ptr := 1; loc_cntr := 0;2. While next statement is not an END statement a) clear machine_code_buffer;

b) If an LTORG statement i)Process literals in LITTAB[POOLTAB[pooltab_ptr]] ...LITTAB[POOLTAB[pooltab_ptr+1]]-1 similar to processing of constants in a DC statement i.e. assemble the literals in machine_code_buffer; ii) size := size of memory area required for literals; iii) pooltab_ptr := pooltab_ptr + 1;

Page 4: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

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 then Assemble the constatnt in machine_code_buffer ii) size := size of memory area required by DC/DS;

e) If an imperative statement i) Get the operand address from SYMTAB or LITTAB. ii) Assemble instruction in machine_code_buffer. iii) size := size of instruction.

Page 5: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

f) If size <> 0 then i) Move the contents of machine_code_buffer to the address code_area_address + loc_cntr; ii) loc_cntr := loc_cntr + size;

3. (Processing of an END statement) a) Perform steps 2(b) & 2(f). b) Write code_area into output file.

Page 6: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Page 7: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

b

Process literals LITERAL_TABLE[POOL_TABLE[POOL_Table_Pointer]]…LITERAL_TABLE[Literal_Table_Pointer – 1]] similar to

processing of constants in a DC statement i.e. assemble the literals' in Machine_Code_Buffer

Size = size of memory area required for literals

POOL_Table_Pointer = POOL_Table_Pointer + 1

m

LTORG?

Page 8: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Page 9: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

c

Location_Counter = Value specified in Operand Field

START or ORGIN?

m

Size=0

Page 10: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Page 11: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Assemble the constant in Machine_Code_Buffer for DC

Statement

Size = Size of memory area required by DC/DS

m

Declaration Statement?

Page 12: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Page 13: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Get the operand address from Symbol Table or LITERAL TABLE

Assemble the instruction in Machine_Code_Buffer

Imperative Statement?

Size = size of instruction

m

Page 14: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Page 15: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

Page 16: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Page 17: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

a b c d e f

Perform Step b

Write Code_Area into output file

Processing of END

statement

Perform Step f

STOP

Page 18: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

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

Source Program

Page 19: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

(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 20: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

(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

Target Code

100) + 04 1 104 101) + 01 1 105 102) + 05 1 106 103) + 00 0 000 104) + 00 0 005 105) + 00 0 008 106)

Page 21: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

Code_Area_Address = 0Location_Counter = 0

POOL_Table_Pointer = 1

m

Page 22: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

c

Location_Counter = Value specified in Operand Field

START or ORGIN?

c

Size=0

Code_Area_Address = 0Location_Counter = 0

POOL_Table_Pointer = 1

Location_Counter =100

Size=0

(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)

Page 23: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

Code_Area_Address = 0Location_Counter = 100POOL_Table_Pointer = 1

Size=0

m

Page 24: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Get the operand address from Symbol Table or LITERAL TABLE

Assemble the instruction in Machine_Code_Buffer (MCB)

Imperative Statement?

Size = size of instruction

m

Code_Area_Address = 0Location_Counter = 100POOL_Table_Pointer = 1

Size=0

Symbol Address Length

A 104 1

B 105 1

C 106 1

Symbol Table

Address of A = 104

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

100) + 04 1 104

Size = 1

Register CodeAREG 1

BREG 2

CREG 3

DREG 4

100) + 04 1 104

(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)

MCB

Page 25: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

Code_Area_Address = 0Location_Counter = 100POOL_Table_Pointer = 1

Size=1

m

100) + 04 1 104 MCB

Page 26: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address (CAA) + Location_Counter

Location_Counter = Location_Counter + Size

m

(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)

Code_Area_Address = 0Location_Counter = 100POOL_Table_Pointer = 1

Size=1

100) + 04 1 104

100) + 04 1 104

Location_Counter= 100+1

100) + 04 1 104

MCB

CAA

Page 27: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

Code_Area_Address = 0Location_Counter = 101POOL_Table_Pointer = 1

Size=1

m

100) + 04 1 104

MCB

CAA

Page 28: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Get the operand address from Symbol Table or LITERAL TABLE

Assemble the instruction in Machine_Code_Buffer

Imperative Statement?

Size = size of instruction

m

Code_Area_Address = 0Location_Counter = 101POOL_Table_Pointer = 1

Size=1

Symbol Address Length

A 104 1

B 105 1

C 106 1

Symbol Table

Address of B = 105

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

101) + 01 1 105

Size = 1

Register CodeAREG 1

BREG 2

CREG 3

DREG 4

101) + 01 1 105

100) + 04 1 104

(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)

MCB

CAA

Page 29: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter =0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

Code_Area_Address = 0Location_Counter = 101POOL_Table_Pointer = 1

Size=1

m

101) + 01 1 105

100) + 04 1 104

MCB

CAA

Page 30: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

(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)

Code_Area_Address = 0Location_Counter = 101POOL_Table_Pointer = 1

Size=1

101) + 01 1 105

100) + 01 1 105

Location_Counter= 101+1 = 102

100) + 04 1 104101) + 01 1 105

MCB

CAA

Page 31: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter =0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

Code_Area_Address = 0Location_Counter = 102POOL_Table_Pointer = 1

Size=1

m

100) + 04 1 104101) + 01 1 105

CAA

MCB

Page 32: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Get the operand address from Symbol Table or LITERAL TABLE

Assemble the instruction in Machine_Code_Buffer

Imperative Statement?

Size = size of instruction

m

Symbol Address Length

A 104 1

B 105 1

C 106 1

Symbol Table

Address of B = 106

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

102) + 05 1 106

Size = 1

Register CodeAREG 1

BREG 2

CREG 3

DREG 4

(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)

Code_Area_Address = 0Location_Counter = 102POOL_Table_Pointer = 1

Size=1

102) + 05 1 106

100) + 04 1 104101) + 01 1 105

CAA

MCB

Page 33: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

m

Code_Area_Address = 0Location_Counter = 102POOL_Table_Pointer = 1

Size=1

102) + 05 1 106

100) + 04 1 104101) + 01 1 105

CAA

MCB

Page 34: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

(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)

Code_Area_Address = 0Location_Counter = 102POOL_Table_Pointer = 1

Size=1

102) + 05 1 106

102) + 05 1 106

Location_Counter= 102+1 = 103

100) + 04 1 104101) + 01 1 105102) + 05 1 106

MCB

CAA

Page 35: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

m

Code_Area_Address = 0Location_Counter = 103POOL_Table_Pointer = 1

Size=1

100) + 04 1 104101) + 01 1 105102) + 05 1 106

MCB

CAA

Page 36: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Get the operand address from Symbol Table or LITERAL TABLE

Assemble the instruction in Machine_Code_Buffer

Imperative Statement?

Size = size of instruction

m

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

103) + 00 0 000

Size = 1

(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)

Code_Area_Address = 0Location_Counter = 103POOL_Table_Pointer = 1

Size=1

103) + 00 0 000

100) + 04 1 104101) + 01 1 105102) + 05 1 106

MCB

CAA

Page 37: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

m

Code_Area_Address = 0Location_Counter = 103POOL_Table_Pointer = 1

Size=1

103) + 00 0 000 MCB

100) + 04 1 104101) + 01 1 105102) + 05 1 106

CAA

Page 38: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

(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)

Code_Area_Address = 0Location_Counter = 103POOL_Table_Pointer = 1

Size=1

103) + 00 0 000

103) + 00 0 000

Location_Counter= 103+1 = 104

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000

MCB

CAA

Page 39: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

m

Code_Area_Address = 0Location_Counter = 104POOL_Table_Pointer = 1

Size=1

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000

MCB

CAA

Page 40: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Assemble the constant in Machine_Code_Buffer for DC

Statement

Size = Size of memory area required by DC/DS

m

Declaration Statement?

(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)

Code_Area_Address = 0Location_Counter = 104POOL_Table_Pointer = 1

Size=1

104) + 00 0 005

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000

MCB

CAA

104) + 00 0 005

Size = 1

Page 41: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not

end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

m

Code_Area_Address = 0Location_Counter = 104POOL_Table_Pointer = 1

Size=1

104) + 00 0 005

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000

MCB

CAA

Page 42: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

(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)

Code_Area_Address = 0Location_Counter = 104POOL_Table_Pointer = 1

Size=1

104) + 00 0 005

104) + 00 0 005

Location_Counter= 104+1 = 105

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005

MCB

CAA

Page 43: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

m

Code_Area_Address = 0Location_Counter = 105POOL_Table_Pointer = 1

Size=1

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005

MCB

CAA

Page 44: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Assemble the constant in Machine_Code_Buffer for DC

Statement

Size = Size of memory area required by DC/DS

m

Declaration Statement?

(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)

Code_Area_Address = 0Location_Counter = 105POOL_Table_Pointer = 1

Size=1

105) + 00 0 008

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005

MCB

CAA

105) + 00 0 008

Size = 1

Page 45: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not

end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

m

Code_Area_Address = 0Location_Counter = 105POOL_Table_Pointer = 1

Size=1

105) + 00 0 008

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005

MCB

CAA

Page 46: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

(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)

Code_Area_Address = 0Location_Counter = 105POOL_Table_Pointer = 1

Size=1

105) + 00 0 008

105) + 00 0 008

Location_Counter= 105+1 = 106

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005105) + 00 0 008

MCB

CAA

Page 47: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

m

Code_Area_Address = 0Location_Counter = 106POOL_Table_Pointer = 1

Size=1

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005105) + 00 0 008

MCB

CAA

Page 48: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Assemble the constant in Machine_Code_Buffer for DC

Statement

Size = Size of memory area required by DC/DS

m

Declaration Statement?

(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)

Code_Area_Address = 0Location_Counter = 106POOL_Table_Pointer = 1

Size=1

106)

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005105) + 00 0 008

MCB

CAA

106)

Size = 1

Page 49: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not

end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

m

Code_Area_Address = 0Location_Counter = 106POOL_Table_Pointer = 1

Size=1

106)

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005105) + 00 0 008

MCB

CAA

Page 50: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

(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)

Code_Area_Address = 0Location_Counter = 105POOL_Table_Pointer = 1

Size=1

106)

106)

Location_Counter= 106+1 = 107

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005105) + 00 0 008106)

MCB

CAA

Page 51: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not

end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

m

Code_Area_Address = 0Location_Counter = 107POOL_Table_Pointer = 1

Size=1

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005105) + 00 0 008106)

MCB

CAA

Page 52: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

a b c d e f

Perform Step b

Write Code_Area into output file

Processing of END

statement

Perform Step f

(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)

Code_Area_Address = 0Location_Counter = 107POOL_Table_Pointer = 1

Size=1

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005105) + 00 0 008106)

CAA

MCB Output File100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 005105) + 00 0 008106)

STOP

Page 53: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

(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

Target Code

100) + 04 1 104 101) + 01 1 105 102) + 05 1 106 103) + 00 0 000 104) + 00 0 005 105) + 00 0 008 106)

Page 54: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Mnemonic Opcode Class .Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

Page 55: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

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

Page 56: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

(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 B DC ‘8’ C DS 1 END

Symbol Address Length

B 105 1

C 106 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 57: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

(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 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

Target Code

100) + 04 1 106 101) + 01 1 104 102) + 05 1 105 103) + 00 0 000 104) + 00 0 008 105) 106) + 00 0 005

Page 58: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

Code_Area_Address = 0Location_Counter = 0

POOL_Table_Pointer = 1

m

Page 59: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

c

Location_Counter = Value specified in Operand Field

START or ORGIN?

c

Size=0

Code_Area_Address = 0Location_Counter = 0

POOL_Table_Pointer = 1

Location_Counter =100

Size=0

(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 60: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

gCode_Area_Address = 0Location_Counter = 100POOL_Table_Pointer = 1

Size=0

m

(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 61: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Get the operand address from Symbol Table or LITERAL TABLE

Assemble the instruction in Machine_Code_Buffer (MCB)

Imperative Statement?

Size = size of instruction

m

Code_Area_Address = 0Location_Counter = 100POOL_Table_Pointer = 1

Size=0

Address of Literal “=‘5’”=

106

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

100) + 04 1 106

Size = 1

Register CodeAREG 1

BREG 2

CREG 3

DREG 4

100) + 04 1 106 MCB

(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

POOL_Table_Pointer

Literal_Table_Pointer

1 1

2 2

Literal Table

POOL Table

Page 62: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

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

Code_Area_Address = 0Location_Counter = 100POOL_Table_Pointer = 1

Size=1

m

100) + 04 1 106 MCB

Page 63: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address (CAA) + Location_Counter

Location_Counter = Location_Counter + Size

m

Code_Area_Address = 0Location_Counter = 100POOL_Table_Pointer = 1

Size=1

100) + 04 1 106

100) + 04 1 106

Location_Counter= 100+1

100) + 04 1 106

MCB

CAA

(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 64: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

gCode_Area_Address = 0Location_Counter = 101POOL_Table_Pointer = 1

Size=1

m

100) + 04 1 106

MCB

CAA

(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 65: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Get the operand address from Symbol Table or LITERAL TABLE

Assemble the instruction in Machine_Code_Buffer

Imperative Statement?

Size = size of instruction

m

Code_Area_Address = 0Location_Counter = 101POOL_Table_Pointer = 1

Size=1

Symbol Address Length

B 104 1

C 105 1

Symbol Table

Address of B = 105

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

101) + 01 1 104

Size = 1

Register CodeAREG 1

BREG 2

CREG 3

DREG 4

101) + 01 1 104

100) + 04 1 106

MCB

CAA

(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 66: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter =0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

gCode_Area_Address = 0Location_Counter = 101POOL_Table_Pointer = 1

Size=1

m

101) + 01 1 104

100) + 04 1 106

MCB

CAA

(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 67: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

Code_Area_Address = 0Location_Counter = 101POOL_Table_Pointer = 1

Size=1

101) + 01 1 104

100) + 01 1 104

Location_Counter= 101+1 = 102

100) + 04 1 106101) + 01 1 104

MCB

CAA

(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 68: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter =0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

gCode_Area_Address = 0Location_Counter = 102POOL_Table_Pointer = 1

Size=1

m

100) + 04 1 106101) + 01 1 104

CAA

MCB

(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 69: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Get the operand address from Symbol Table or LITERAL TABLE

Assemble the instruction in Machine_Code_Buffer

Imperative Statement?

Size = size of instruction

m

Symbol Address Length

B 104 1

C 105 1

Symbol Table

Address of B = 105

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

102) + 05 1 105

Size = 1

Register CodeAREG 1

BREG 2

CREG 3

DREG 4

Code_Area_Address = 0Location_Counter = 102POOL_Table_Pointer = 1

Size=1

102) + 05 1 105

100) + 04 1 106101) + 01 1 104

CAA

MCB

(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 70: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Code_Area_Address = 0Location_Counter = 102POOL_Table_Pointer = 1

Size=1

102) + 05 1 105

100) + 04 1 106101) + 01 1 104

CAA

MCB

(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 71: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer (MCB) to the

address Code_Area_Address (CAA) + Location_Counter

Location_Counter = Location_Counter + Size

m

Code_Area_Address = 0Location_Counter = 102POOL_Table_Pointer = 1

Size=1

102) + 05 1 105

102) + 05 1 105

Location_Counter= 102+1 = 103

100) + 04 1 106101) + 01 1 104102) + 05 1 105

MCB

CAA

(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 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Code_Area_Address = 0Location_Counter = 103POOL_Table_Pointer = 1

Size=1

100) + 04 1 106101) + 01 1 104102) + 05 1 105

MCB

CAA

(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 73: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Get the operand address from Symbol Table or LITERAL TABLE

Assemble the instruction in Machine_Code_Buffer

Imperative Statement?

Size = size of instruction

m

Mnemonic Opcode

Class Mnemonic Info

MOVER IS (04,1)

DS DL R#7

START AD R#11

.

.

OP Table

103) + 00 0 000

Size = 1

Code_Area_Address = 0Location_Counter = 103POOL_Table_Pointer = 1

Size=1

103) + 00 0 000

100) + 04 1 106101) + 01 1 104102) + 05 1 105

MCB

CAA

(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 74: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Code_Area_Address = 0Location_Counter = 103POOL_Table_Pointer = 1

Size=1

103) + 00 0 000 MCB

100) + 04 1 106101) + 01 1 104102) + 05 1 105

CAA

(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 75: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

Code_Area_Address = 0Location_Counter = 103POOL_Table_Pointer = 1

Size=1

103) + 00 0 000

103) + 00 0 000

Location_Counter= 103+1 = 104

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000

MCB

CAA

(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 76: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Code_Area_Address = 0Location_Counter = 104POOL_Table_Pointer = 1

Size=1

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000

MCB

CAA

(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 77: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Assemble the constant in Machine_Code_Buffer for DC

Statement

Size = Size of memory area required by DC/DS

m

Declaration Statement?

Code_Area_Address = 0Location_Counter = 104POOL_Table_Pointer = 1

Size=1

104) + 00 0 008

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000

MCB

CAA

104) + 00 0 008

Size = 1

(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 78: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not

end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Code_Area_Address = 0Location_Counter = 104POOL_Table_Pointer = 1

Size=1

104) + 00 0 008

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000

MCB

CAA

(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 79: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

Code_Area_Address = 0Location_Counter = 104POOL_Table_Pointer = 1

Size=1

104) + 00 0 008

104) + 00 0 008

Location_Counter= 104+1 = 105

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000104) + 00 0 008

MCB

CAA

(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 80: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Code_Area_Address = 0Location_Counter = 105POOL_Table_Pointer = 1

Size=1

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000104) + 00 0 008

MCB

CAA

(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 81: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

e

Assemble the constant in Machine_Code_Buffer for DC

Statement

Size = Size of memory area required by DC/DS

m

Declaration Statement?

Code_Area_Address = 0Location_Counter = 105POOL_Table_Pointer = 1

Size=1

105)

100) + 04 1 104101) + 01 1 105102) + 05 1 106103) + 00 0 000104) + 00 0 008

MCB

CAA

105)

Size = 1

(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 82: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not

end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

m

Code_Area_Address = 0Location_Counter = 106POOL_Table_Pointer = 1

Size=1

105)

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000104) + 00 0 008

MCB

CAA

(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 83: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

(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)

Code_Area_Address = 0Location_Counter = 105POOL_Table_Pointer = 1

Size=1

105)

105)

Location_Counter= 105+1 = 106

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000104) + 00 0 008105)

MCB

CAA

Page 84: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

Code_Area_Address = Address of Code AreaLocation_Counter = 0

POOL_Table_Pointer = 1

While next statement is not

end statement

LTORG?

START or ORGIN?

Declaration Statement?

Imperative Statement?

b c d e

Size not equal to 0?

Clear Machine_Code_Buffer

fa

g

(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)

m

Code_Area_Address = 0Location_Counter = 106POOL_Table_Pointer = 1

Size=1

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000104) + 00 0 008105)

MCB

CAA

Page 85: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

a b c d e f

Perform Step b

Processing of END

statement

Code_Area_Address = 0Location_Counter = 106POOL_Table_Pointer = 1

Size=1

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000104) + 00 0 008105)

CAA

MCB

(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 86: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

b

Process literals LITERAL_TABLE[POOL_TABLE[POOL_Table_Pointer]]…LITERAL_TABLE[Literal_Table_Pointer – 1]] similar to

processing of constants in a DC statement i.e. assemble the literals' in Machine_Code_Buffer

Size = size of memory area required for literals

POOL_Table_Pointer = POOL_Table_Pointer + 1

m

LTORG?

Code_Area_Address = 0Location_Counter = 106POOL_Table_Pointer = 1

Size=1

106) + 00 0 005

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000104) + 00 0 008105)

CAA

MCB

(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

POOL_Table_Pointer

Literal_Table_Pointer

1 1

2 2

Literal Table

POOL Table

106) + 00 0 005

Size = 1

POOL_Table_Pointer = 1+1 =2

Page 87: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

a b c d e f

Perform Step b

Processing of END

statement

Code_Area_Address = 0Location_Counter = 106POOL_Table_Pointer = 2

Size=1

106) + 00 0 005

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000104) + 00 0 008105)

CAA

MCB

(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)

Perform Step f

Page 88: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Size not equal to 0?

f

Move content of Machine_Code_Buffer to the address

Code_Area_Address + Location_Counter

Location_Counter = Location_Counter + Size

m

(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)

Code_Area_Address = 0Location_Counter = 105POOL_Table_Pointer = 1

Size=1

106) + 00 0 005

106) + 00 0 005

Location_Counter= 106+1 = 107

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000104) + 00 0 008105)106) + 00 0 005

MCB

CAA

Page 89: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

a b c d e f

Perform Step b

Processing of END

statement

Code_Area_Address = 0Location_Counter = 106POOL_Table_Pointer = 2

Size=1

100) + 04 1 106101) + 01 1 104102) + 05 1 105103) + 00 0 000104) + 00 0 008105)106) + 00 0 005

CAA

MCB

(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)

Perform Step f

Write Code_Area into output file

END

100) + 04 1 104 101) + 01 1 105 102) + 05 1 106 103) + 00 0 000 104) + 00 0 005 105) + 00 0 008 106)107) + 00 0 005 Output File

Page 90: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

(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 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

Target Code

100) + 04 1 106 101) + 01 1 104 102) + 05 1 105 103) + 00 0 000 104) + 00 0 008 105) 106) + 00 0 005

Page 91: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Sr. No. Statement Address1 START 2002 MOVER AREG,A 200

3:

9 MVER BREG,A 207**ERROR**INVALID OPCODE

10 ADD BREG,B 20814 A DS 1 209

15:

21 A DC '5' 227 **ERROR**DUPLICATE DEFINATION OF SYMBOL A

22 :

35 END**ERROR**UNDEFINED SYMBOL B IN STATEMENT 10

Listing and Error Reporting

Page 92: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Sr. No. Statement Address INSTRUCTION1 START 2002 MOVER AREG,A 200 +04 1 2093 :

9 MVER BREG,A 207 + -- 2 209**ERROR**INVALID OPCODE

10 ADD BREG,B 208 +01 2 --- **ERROR**UNDEFINED SYMBOL B IN OPERAND FIELD

14 A DS 1 20915 :

21 A DC '5' 227 +00 0 005**ERROR**DUPLICATE DEFINATION OF SYMBOL A

22 :

35 END

Listing and Error Reporting

Page 93: Chapter 2c Assembler-Pass 2 of Two Pass Assembler

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

Some Organizational Issues

Source Program

Source Program

Intermediate Code

Target Program

Program Listing

OPTAB SYMTAB LITTAB

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