Question

2.- [11 points) When the object code is loaded into memory, a segment called the run time environment is created. Name the se
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Language Processing System

We have learnt that any computer system is made of hardware and software. The hardware understands a language, which humans cannot understand. So we write programs in high-level language, which is easier for us to understand and remember. These programs are then fed into a series of tools and OS components to get the desired code that can be used by the machine. This is known as Language Processing System.

Source Code Pre Processor Pre-processed Code Compiler Target Assembly Code Assembler Relocatable Machine Code Linker Library

The high-level language is converted into binary language in various phases. A compiler is a program that converts high-level language to assembly language. Similarly, an assembler is a program that converts the assembly language to machine-level language.

Let us first understand how a program, using C compiler, is executed on a host machine.

  • User writes a program in C language (high-level language).

  • The C compiler, compiles the program and translates it to assembly program (low-level language).

  • An assembler then translates the assembly program into machine code (object).

  • A linker tool is used to link all the parts of the program together for execution (executable machine code).

  • A loader loads all of them into memory and then the program is executed.

Before diving straight into the concepts of compilers, we should understand a few other tools that work closely with compilers.

Preprocessor

A preprocessor, generally considered as a part of compiler, is a tool that produces input for compilers. It deals with macro-processing, augmentation, file inclusion, language extension, etc.

Interpreter

An interpreter, like a compiler, translates high-level language into low-level machine language. The difference lies in the way they read the source code or input. A compiler reads the whole source code at once, creates tokens, checks semantics, generates intermediate code, executes the whole program and may involve many passes. In contrast, an interpreter reads a statement from the input, converts it to an intermediate code, executes it, then takes the next statement in sequence. If an error occurs, an interpreter stops execution and reports it. whereas a compiler reads the whole program even if it encounters several errors.

Assembler

An assembler translates assembly language programs into machine code.The output of an assembler is called an object file, which contains a combination of machine instructions as well as the data required to place these instructions in memory.

Linker

Linker is a computer program that links and merges various object files together in order to make an executable file. All these files might have been compiled by separate assemblers. The major task of a linker is to search and locate referenced module/routines in a program and to determine the memory location where these codes will be loaded, making the program instruction to have absolute references.

Loader

Loader is a part of operating system and is responsible for loading executable files into memory and execute them. It calculates the size of a program (instructions and data) and creates memory space for it. It initializes various registers to initiate execution.

Cross-compiler

A compiler that runs on platform (A) and is capable of generating executable code for platform (B) is called a cross-compiler.

Source-to-source Compiler

A compiler that takes the source code of one programming language and translates it into the source code of another programming language is called a source-to-source compiler.

Phases of Compiler

The compilation process is a sequence of various phases. Each phase takes input from its previous stage, has its own representation of source program, and feeds its output to the next phase of the compiler. Let us understand the phases of a compiler.

Source Code Lexical Analyzer Syntax Analyzer Semantic Analyzer Symbol Table Intermediate Code Generator Error Handler Machine

Code Generation

In this phase, the code generator takes the optimized representation of the intermediate code and maps it to the target machine language. The code generator translates the intermediate code into a sequence of (generally) re-locatable machine code. Sequence of instructions of machine code performs the task as the intermediate code would do.

Introduction of Object Code in Compiler Design

Assume that, you have a c program, then you give the C program to compiler and compiler will produce the output in assembly code.Now, that assembly language code will give to the assembler and assembler is going to produce you some code. That is known as Object Code.

Text code Compiler Assembly code Assembler Object code

But, when you compile a program, then you are not going to use both compiler and assembler.You just take the program and give it to the compiler and compiler will give you the directly executable code. The compiler is actually combined inside the assembler along with loader and linker.So all the module kept together in the compiler software itself. So when you calling gcc, you are actually not just calling the compiler, you are calling the compiler, then assembler, then linker and loader.

Once you call the compiler, then your object code is going to present in Hard-disk. This object code contains various part –

Header Text segment Data segment Relocation information Symbol table Debugging information OBJECT CODE

  • Header –
    The header will say what are the various parts present in this object code and then point that parts.So header will say where the text segment is going to start and a pointer to it and where the data segment going to start and it say where the relocation information and symbol information there.

    It is nothing but like an index, like you have a textbook, there an index page will contains at what page number each topic present. Similarly, the header will tell you, what are the palaces at which each information is present.So that later for other software it will be useful to directly go into those segment.

  • Text segment –
    It is nothing but the set of instruction.
  • Data segment –
    Data segment will contain whatever data you have used.For example, you might have used something constraint, then that going to be present in the data segment.
  • Relocation Information –
    Whenever you try to write a program, we generally use symbol to specify anything.Let us assume you have instruction 1, instruction 2, instruction 3, instruction 4,….

O LO level 1 L1 level 2 L2 level 3 L3 level 4 L4 level 15 L5 level Goto 14 Goto 4

Now if you say somewhere Goto L4 (Even if you don’t write Goto statement in the high-level language, the output of the compiler will write it), then that code will be converted into object code and L4 will be replaced by Goto 4. Now Goto 4 for the level L4 is going to work fine, as long as the program is going to be loaded starting at address no 0. But most of the cases, the initial part of the RAM is going to be dedicated to the operating system. Even if it is not dedicated to the operating system, then might be some other process which will already be running at address no 0. So, when you are going to load the program into memory, means if the program has to be load in the main memory, it might be loaded anywhere.Let us say 1000 is the new starting address, then all the addresses has to be changed, that is known as Reallocation.
1000 LO level 1001 L1 level 1002 L2 level 1003 L3 level 1004 L4 level 1005 L5 level O LO level 1 L1 level 2 L2 level 13 L3 le

The original address is known as Relocatable address and the final address which we get after loading the program into main memory is known as the Absolute address.

Symbol table –

It contains every symbol that you have in your program.for example, int a, b, c then, a, b, c are the symbol.it will show what are the variables that your program contains.

Debugging information –

It will help to find how a variable is keeping on changing............................

Add a comment
Know the answer?
Add Answer to:
2.- [11 points) When the object code is loaded into memory, a segment called the run...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 9.- ( 11 points) Draw a diagram showing the ELF(object code), Process Control Block, Thread Control...

    9.- ( 11 points) Draw a diagram showing the ELF(object code), Process Control Block, Thread Control Blocks and the run-time environment for a program with three threads, indicating how these data structures are related. Use arrows to show all relationships.

  • ) Using Linux or Unix command line interpreter, compile and run the programs in Figure 3.8,...

    ) Using Linux or Unix command line interpreter, compile and run the programs in Figure 3.8, Figure 3.30. DO NOT compile and ron these programs on Windows Write the 3.16, Figare 317 and Figure 3 programs in Notepadt+, for example, then compile and run them at the command pr apt. Provide screenshots of your programs compilation, execution, and the results. 144 6 7 8 9 ry-maps a shared-memory object of the ws writing to the object. The flag shared-memory object...

  • create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in...

    create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in Horstmann Section 7.5, pp. 350-351 according to the specifications below. The input file should be called 'data.txt' and should be created according to the highlighted instructions below. Note that even though you know the name of the input file, you should not hard-code this name into your program. Instead, prompt the user for the name of the input file. The input file should contain...

  • When i run my python code i get the following error... and im not sure how...

    When i run my python code i get the following error... and im not sure how to fix the error, can someone help me? ____________________Hers my Code__________________ import face_recognition import cv2 # Get a reference to your webcam video_capture = cv2.VideoCapture(0) # Load a sample picture of yourself and learn how to recognize it. kyle_image = face_recognition.load_image_file("kyle.jpg") kyle_face_encoding = face_recognition.face_encodings(kyle_image)[0] # Load a second sample picture and learn how to recognize it. ##lauren_image = face_recognition.load_image_file("lauren.jpg") ##lauren_face_encoding = face_recognition.face_encodings(lauren_image)[0] # Load...

  • PYTHON The provided code in the ATM program is incomplete. Complete the run method of the...

    PYTHON The provided code in the ATM program is incomplete. Complete the run method of the ATM class. The program should display a message that the police will be called after a user has had three successive failures. The program should also shut down the bank when this happens. [comment]: <> (The ATM program allows a user an indefinite number of attempts to log in. Fix the program so that it displays a message that the police will be called...

  • Part 2 (22 pts) .ORIG x3000 LEA R1, STRZ AND R2, R2, #0 LD R4, CHAR...

    Part 2 (22 pts) .ORIG x3000 LEA R1, STRZ AND R2, R2, #0 LD R4, CHAR REPEAT LDR R3, R1, #0 BRz FINISH   ;Branch to FINISH if the value of R3 is zero ADD R3, R3, R4 BRnp PASS   ;Branch to PASS if the value of R3 is positive or negative ADD R2, R2, #1 PASS ADD R1, R1, #1 BR REPEAT   ;Branch always to REPEAT FINISH ST R2, COUNT HALT CHAR .FILL xFF91 COUNT .FILL x0000 STRZ .STRINGZ "Hello...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • Objectives You will implement and test a class called MyString. Each MyString object keeps track ...

    Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • the is my HTML and CSS code. I didn't attach the image or the CSS file...

    the is my HTML and CSS code. I didn't attach the image or the CSS file because of the space limit. two things I wanted to incorporate on this page are to make "MY TOP 3 MUSIC GENRES" blink using javascript and to make the video links autoplay using javascript both should be using javascript requirement: our professor told us not to use <div> or alert. thank you for your help <!DOCTYPE html> <!-- I used w3school for the formatting...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT