3. ASSEMBLERS
• AN ASSEMBLER IS A PROGRAM THAT ACCEPTS AS INPUT AN ASSEMBLY
LANGUAGE PROGRAM (SOURCE) AND PRODUCES ITS MACHINE LANGUAGE
EQUIVALENT (OBJECT CODE) ALONG WITH THE INFORMATION FOR THE
LOADER.
Assembler
Object
Code
Loader
Executable
Linker Code
Fig. : Role of Assemblers
4. AN ASSEMBLER DOES THE FOLLOWING:
1. GENERATE MACHINE INSTRUCTIONS
• EVALUATE THE MNEMONICS TO PRODUCE THEIR MACHINE
CODE
• EVALUATE THE SYMBOLS, LITERALS, ADDRESSES TO
PRODUCE THEIR EQUIVALENT MACHINE ADDRESSES
• CONVERT THE DATA CONSTANTS INTO THEIR MACHINE
REPRESENTATIONS
5. ONE PASS ASSEMBLERS
• ONE-PASS ASSEMBLERS ARE USED WHEN
• IT IS NECESSARY OR DESIRABLE TO AVOID A SECOND PASS
OVER THE SOURCE PROGRAM
• THE EXTERNAL STORAGE FOR THE INTERMEDIATE FILE
BETWEEN TWO PASSES IS SLOW OR IS INCONVENIENT TO
USE
• MAIN PROBLEM
FORWARD REFERENCES
• DATA ITEMS
• LABELS ON INSTRUCTIONS
6. FORWARD REFERENCE
• FOR ANY SYMBOL THAT HAS NOT YET BEEN DEFINED
1. OMIT THE ADDRESS TRANSLATION
2. INSERT THE SYMBOL INTO SYMTAB, AND MARK THIS SYMBOL UNDEFINED
3. THE ADDRESS THAT REFERS TO THE UNDEFINED SYMBOL IS ADDED TO A
LIST OF FORWARD REFERENCES ASSOCIATED WITH THE SYMBOL TABLE
ENTRY
4. WHEN THE DEFINITION FOR A SYMBOL IS ENCOUNTERED, THE PROPER
ADDRESS FOR THE SYMBOL IS THEN INSERTED INTO ANY INSTRUCTIONS
PREVIOUS GENERATED ACCORDING TO THE FORWARD REFERENCE LIST
7. SOLUTIONS FOR ONE PASS ASSEMBLER
TWO METHODS CAN BE USED:
• ELIMINATING FORWARD REFERENCES:
EITHER ALL LABELS USED IN FORWARD REFERENCES ARE DEFINED IN THE SOURCE
PROGRAM BEFORE THEY ARE REFERENCED, OR FORWARD REFERENCES TO DATA ITEMS
ARE PROHIBITED.
• GENERATING THE OBJECT CODE IN MEMORY:
NO OBJECT PROGRAM IS WRITTEN OUT AND NO LOADER IS NEEDED. THE PROGRAM NEEDS
TO BE RE-ASSEMBLED EVERY TIME.
8. ALGORITHM
STEP 1 : START THE PROGRAM EXECUTION.
STEP 2 : ASSEMBLER SIMPLY GENERATE OBJECT CODE AS IT SCANS THE SOURCE CODE.
STEP 3 : IF THE INSTRUCTION OPERAND IS A SYMBOL TEXT, HAS NOT YET BEEN DEFINED, THE
OPERANDS ADDRESS IS OMITTED.
STEP 4 : WHEN NEARLY HALF THE PROGRAM TRANSLATION IS OVER, SOME OF THE FORWARD
REFERENCE PROBLEM ARE EXISTED.
STEP 5 : COMBINE THE PROCESS TO THE END OF THE PROGRAM TO FILL FORWARD REFERENCE
PROPERTY.
STEP 6 : AT THE END OF THE PROGRAM, THE SYMBOL TABLE ENTRIES WITH ‘X’ ARE
UNDEFINED.
STEP 7 : STOP THE PROGRAM EXECUTION.
10. TO WRITE A C PROGRAM TO IMPLEMENT SINGLE
PASS ASSEMBLER.
INPUT
ENTER YOUR ASSEMBLY INSTRUCTIONS
LDA 5000
SUB Z
STA 9988
HLT
*