SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Linda Null ,julia Lobur
Chapter:
System Software
Exercise:
Exercises
Question:10 | ISBN:9780763704445 | Edition: 3

Question

10. What problems does an assembler have to overcome in order to produce complete binary code in one pass over the source file? How would code written for a one-pass assembler be different from code written for a two-pass assembler?

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

An assembler is a program that translates assembly language code into machine code or binary code. When producing complete binary code in one pass over the source file, an assembler has to overcome a few challenges. Here are some of the problems it needs to address:

  • Forward References: One-pass assemblers face difficulties when encountering symbols (e.g., labels or variables) that are referenced before they are defined in the source code. In a two-pass assembler, the first pass collects symbol definitions, and the second pass resolves the references. In a one-pass assembler, forward references must be handled carefully to ensure correct code generation.

  • Address Calculation: Assemblers need to calculate the correct memory addresses for instructions and data items. In a two-pass assembler, the first pass can collect the necessary information about labels and their corresponding addresses, which can be used in the second pass for proper address calculation. In a one-pass assembler, the address calculation must be performed on-the-fly while processing the source code.

  • Multiple Symbol Definitions: In some cases, symbols may be defined multiple times in the source code, either intentionally or by mistake. Two-pass assemblers can identify and handle such situations during the first pass, ensuring that each symbol has a unique definition. One-pass assemblers may need to prioritize the first occurrence or implement specific rules for handling multiple symbol definitions.

  • Optimization and Code Generation: Two-pass assemblers have the advantage of being able to perform optimization and generate more efficient code during the second pass. They can analyze the complete program and make optimization decisions based on a global view. One-pass assemblers have limited scope for optimization as they process instructions sequentially without complete knowledge of the entire code.

Code written for a one-pass assembler may differ from code written for a two-pass assembler in the following ways:

  • Symbol Definition Order: In a two-pass assembler, symbols can be defined in any order, as long as they are resolved correctly in the second pass. However, in a one-pass assembler, symbols must be defined before they are referenced to ensure proper code generation. This may require reordering or restructuring the source code.

  • Handling Forward References: Code written for a one-pass assembler needs to account for forward references carefully. It may require techniques like using placeholder values or using explicit instructions to reserve memory space for future data.

  • Optimization Considerations: Code written for a two-pass assembler can take advantage of the optimization capabilities available in the second pass. This includes rearranging instructions, optimizing memory accesses, or applying other performance-enhancing transformations. Code written for a one-pass assembler may need to focus on simplicity and efficiency within the limitations of a single pass.

In summary, a one-pass assembler faces challenges related to forward references, address calculation, multiple symbol definitions, and limited optimization opportunities. Code written for a one-pass assembler may require careful handling of forward references and may have limitations in terms of optimization compared to code written for a two-pass assembler.

0 0

Discussions

Post the discussion to improve the above solution.