Pass Structure of Assembler Subject Systems Programming Hope

Pass Structure of Assembler Subject : Systems Programming Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Single Pass Assembler �Forward reference: reference to a label that is defined later in the program. START 200 What is Forward reference ? ? Eg. . ADD AREG . . A DS . . A 2 END �Table of Incomplete Instruction Address Symbol 200 A . . Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Single Pass Assembler �Forward reference: reference to a label that is defined later in the program. START 200 Symbol A Address ADD AREG . . A DS . . A 2 END �Table of Incomplete Instruction Address Symbol 200 A . . Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Single Pass Assembler Forward reference: reference to a label that is defined later in the program. Target Code START 200 ADD AREG . . A DS . . A 2 200 01 01 - … . . . 202 END Table of Incomplete Instruction Symbol Address 200 A A 202 . . . . Target Code 200 01 01 202 . . . . 202 Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Single pass Assembler Examples SOURCE PROGRAM AGAIN START 101 READ N MOVER BREG, MOVEM TARGET CODE 101 09 - ONE 102 04 02 - BREG, TERM 103 05 02 - MULT BREG, TERM 104 03 02 - MOVER CREG, TERM 105 04 03 - ADD CREG, ONE 106 01 03 - MOVEM CREG, TERM 107 05 03 - COMP CREG, TERM 108 06 03 - BC LE, AGAIN 109 07 02 104 MOVEM BREG, RESULT 110 05 02 - PRINT RESULT 111 10 - 112 00 STOP TII INSTRUCTI ON Address SYMBOL 101 N 102 ONE 103 TERM 104 TERM 105 TERM 106 ONE 107 TERM 108 TERM 110 RESULT 111 RESULT Symbol Table N DS 1 113 SYMBOL ADDRESS RESULT DS 1 114 N 113 ONE DC ‘ 1’ 115 ONE 115 TERM DS 1 116 TERM 116 RESULT 114 END Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Single pass Assembler Examples SOURCE PROGRAM AGAIN START 101 READ N MOVER BREG, MOVEM TARGET CODE 101 09 113 ONE 102 04 02 115 BREG, TERM 103 05 02 116 MULT BREG, TERM 104 03 02 116 MOVER CREG, TERM 105 04 03 116 ADD CREG, ONE 106 01 03 115 MOVEM CREG, TERM 107 05 03 116 COMP CREG, TERM 108 06 03 116 BC LE, AGAIN 109 07 02 104 MOVEM BREG, RESULT 110 05 02 114 PRINT RESULT 111 10 114 112 00 STOP TII INSTRUCTI ON Address SYMBOL 101 N 102 ONE 103 TERM 104 TERM 105 TERM 106 ONE 107 TERM 108 TERM 110 RESULT 111 RESULT Symbol Table N DS 1 113 SYMBOL ADDRESS RESULT DS 1 114 N 113 ONE DC ‘ 1’ 115 ONE 115 TERM DS 1 116 TERM 116 AGAIN 104 RESULT 114 END Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Design of Two Pass Assembler PASS I Ø Separate the symbol, mnemonic opcode, and operand fields. Ø Build the symbol table Ø Perform LC processing Ø Construct intermediate code PASS II Ø Synthesize the target code Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Required Data Structures for Two Pass Assembler Source Code Input PASS I ØMOT ØRegister Value Table ØConditional Value Table Prerequisite Output ØIntermediate Code ØSymbol Table ØLiteral Table ØPool Table Input PASS II Output Machine Code Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Assembler Pass I INTERMEDIATE CODE SOURCE PROGRAM LOOP (AD, 01) 200 MOVER AREG, =‘ 5’ 200 (IS, 04) 1 (L, 01) MOVEM AREG, A 201 (IS, 05) 1 (S, 01) MOVER AREG, A 202 (IS, 04) 1 (S, 01) MOVER CREG, B 203 (IS, 04) 3 (S, 03) ADD CREG, =‘ 1’ 204 (IS, 01) 3 (L, 02) (AD, 05) LTORG NEXT 1 (C, 200) START SUB AREG, ORIGIN LOOP+1 MULT CREG, A DS 2 BACK EQU LOOP B DC 1 ‘=1’ B 205 005 206 001 207 (IS, 02) 1 (AD, 03) (S, 02)+(C, 1) 203 (IS, 03) 3 204 (DL, 02) (C, 02) (AD, 04) (S, 02) (DL, 02) (C, 02) END 206 (L, 03) (S, 03) (AD, 02) 207 001 Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Assembler Pass I INTERMEDIATE CODE SOURCE PROGRAM LOOP (AD, 01) 200 MOVER AREG, =‘ 5’ 200 (IS, 04) 1 (L, 01) MOVEM ADD, A 201 (IS, 05) 1 (S, 01) MOVER AREG, A 202 (IS, 04) 1 (S, 01) MOVER CREG, B 203 (IS, 04) 3 (S, 03) ADD CREG, =‘ 1’ 204 (IS, 01) 3 (L, 02) LTORG NEXT 1 (C, 200) START (AD, 05) SUB AREG, ORIGIN LOOP+1 MULT CREG, A DS 1 BACK EQU LOOP B DS 1 ‘=1’ B 205 005 206 001 207 (IS, 02) 1 (AD, 03) (S, 02)+(C, 1) 203 (IS, 03) 3 204 (DL, 02) (C, 01) (AD, 04) (S, 02) (DL, 02) (C, 01) END 205 (L, 03) (S, 03) (AD, 02) 206 001 Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Assembler Pass I SYMBOL TABLE INTERMEDIATE CODE (AD, 01) (C, 200) INDEX SYMBOL ADDRESS LENGTH 200 (IS, 04) 1 (L, 01) 01 A 204 2 201 (IS, 05) 1 (S, 01) 02 LOOP 202 1 202 (IS, 04) 1 (S, 01) 03 B 205 1 203 (IS, 04) 3 (S, 03) 04 NEXT 1 207 1 204 (IS, 01) 3 (L, 02) 05 BACK 202 1 (AD, 05) LITERAL TABLE 205 005 206 001 INDEX LITERAL ADDRESS (L, 03) 01 =‘ 5’ 205 02 =‘ 1’ 206 03 =‘ 1’ 207 (IS, 02) 1 (AD, 03) (S, 02)+(C, 1) 203 (IS, 03) 3 204 (DL, 02) (C, 02) (AD, 04) (S, 02) (DL, 02) (C, 02) 206 (S, 03) POOL TABLE LIT_INDEX #01 (AD, 02) 207 001 #03 Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Assembler Examples Convert Source code into Pass I & Pass II L 1 START 100 MOVER AREG, =‘ 5’ ADD CREG, =‘ 1’ A DS 3 MOVER AREG, B ADD AREG, C MOPVEM AREG, D D EQU A+1 PRINT D ORIGIN A-1 SUB AREG, =‘ 1’ MULT CREG, B C DS ‘ 5’ ORIGIN L 2+1 LTORG L 2 STOP B DC ’ 19’ EXAMPLE 2 SIMPLE LOOP START 100 BALR 15, 0 USING *, 15 L R 1, TWO A R 1, FOUR ST R 1, FOUR CLI FOUR+3, 4 BNE LOOP BR 14 R 1 EQU 1 TWO DC F’ 2’ FOUR DS F END ASSUME: -BALR & BR are of two bytes…. L, A, ST, CLI, BNE are of four byte instructions… END Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Intermediate Code Forms Variant II SOURCE PROGRAM LOOP VARIANT –I VARIANT -II START 200 (AD, 01) (C, 200) READ A (IS, 09) (S, 01) (IS, 09) A MOVER AREG, (IS, 04) 1 (IS, 04) AREG, A AREG, (L, 01) A (S, 01) : : : SUB AREG, =‘ 1’ (IS, 02) 1 (L, 01) (IS, 02) Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Assembler Pass II INTERMEDIATE CODE (AD, 01) TARGET CODE (C, 200) 200 (IS, 04) 1 (L, 01) 200 04 1 205 201 (IS, 05) 1 (S, 01) 201 05 1 204 202 (IS, 04) 1 (S, 01) 202 04 1 204 203 (IS, 04) 3 (S, 03) 203 04 3 205 204 (IS, 01) 3 (L, 02) 204 01 3 206 205 005 206 001 (L, 03) 207 02 1 207 (S, 03) 203 03 3 205 (AD, 05) 207 (IS, 02) 1 (AD, 03) (S, 02)+(C, 1) 203 (IS, 03) 3 204 (DL, 02) (C, 02) (AD, 04) (S, 02) (DL, 02) (C, 02) 206 204 206 (AD, 02) 207 001 Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

Assembler Examples SOURCE PROGRAM AGAIN START 1000 READ N MOVER B, MOVEM INTERMEDIATE CODE (AD, 01) (C, 1000) 1000 (IS, 09) (S, 01) =‘ 1’ 1001 (IS, 04) 2 (L, 01) B, TERM 1002 (IS, 05) 2 (S, 02) MULT B, TERM 1003 (IS, 03) 3 (S, 02) MOVER C, TERM 1004 (IS, 05) 3 (S, 02) ADD C, =‘ 1’ 1005 (IS, 01) 3 (L, 01) MOVEM C, TERM 1006 (IS, 05) 3 (S, 02) COMP C, N 1007 (IS, 06) 3 (S, 01) BC LE, AGAIN 1008 (IS, 07) 2 (S, 03) MOVEM B, RESULT 1009 (IS, 05) 2 (S, 04) LTORG PRINT ()AD, 05) RESULT STOP 1010 (L, 01) 1011 (IS, 10) (S, 04) N DS 1 1012 (IS, 00) RESULT DS 20 1013 (DL, 02) (C, 01) TERM DS 1 1014 (DL, 02) (C, 20) 1034 (DL, 02) (C, 01) END (AD, 02) Hope Foundation’s , International Institute of Information Technology, I²IT, P-14 Rajiv Gandhi Infotech Park, Hinjawadi, Pune - 411 057 Tel - +91 20 22933441 / 2 / 3 | Website - www. isquareit. edu. in ; Email - info@isquareit. edu. in

THANK YOU For Details feel free to contact Prof. Sameer Mamadapure sameerm@isquareit. edu. in Department of Information Technology Hope Foundation’s International Institute of Information Technology, P-14 Rajiv Gandhi Infotech Park, MIDC Phase I Hinjawadi, Pune – 411 057 Phone - +91 20 22933441 www. isquareit. edu. in | info@isquareit. edu. in
- Slides: 16