Target Machine

Target Machine

A target machine is a byte-addressable machine. This machine has n general-purpose registers, R0, R1,.....Rn-1. A Simple Target Machine Model has three-address instruction. A full-edged assembly language would have a variety of instructions. The component of instruction is an operator, followed by a target, and then followed by a list of source operands. 

Some of the instructions are as follows:

  • Load operations: LD dst, addr instruction loads the value in location addr into location dst. It means that assignments dst = addr. L, r, x is the general form of this instruction. The role of this instruction is to load the value in location x into register r.
  • Store operations: ST r, x instruction stores the value in the location x into register r.
  • Computation operations: OP, dst, src1, src2 are the form of computation operations where OP are the add or sub operator and dst, src1, and src2 are locations. The locations may or may not be distinct.
  • Unconditional Operations: The instruction BR L causes control to branch to the machine instruction with label L (BR stands for the branch).
  • Conditional jumps: The general form of this operation is Bcond, r, L. Here R is the register, L is a label, and cond stands for any of the common tests on the value in register r.

The various addressing modes associated with the target machine are discussed below:

  • In instruction, a variable name x means there is a location in memory reserved for x.
  • An indexed address in the form a(r), where ‘a’ is a variable and r is a register, can also be a form of a location. By taking the l-value of ‘a’ and adding it with the value in the register, the value of memory location denoted by a(r) can be computed.
  • An integer indexed by a register can be a memory location. For example, LD R1, 100(R2) has the effect of setting R1 = contents (100 + contents (R2)).
  • There are two indirect addressing modes: *r and *100(r). *r has the address of contents(r), and *100(r) has the address for adding 100 to the contents(r).
  • The immediate constant addressing mode is the last addressing mode, which is denoted by prefix #. 

Program and Instruction Costs

The cost refers to compiling and running a program. There are some aspects of the program on which we optimize the program. The program's cost can be determined by the compilation time’s length and the size, execution time, and power consumption of the target program. Finding the actual cost of the program is a tough task. Therefore, code generation use heuristic techniques to produce a good target program. Each target-machine instruction has an associated cost. The instruction cost is one plus the cost associated with the addressing modes of the operands. 

Example

LD R0, R1: This instruction copies the contents of register R1 into register R0. The cost of this instruction is one because no additional memory is required.

LD R0, M: This instruction's role is to load the contents of memory location M into R0. So the cost will be two due to the address of memory location M is found in the word following the instruction.

LD R1, *100(R2): The role of this instruction is to load the value given by contents (contents (100 + contents (R2))) into register R1. This instruction's cost will be two due to the constant 100 is stored in the word following the instruction.


Related Topics

Stack Allocation of Space

Stack Allocation of Space Almost all compilers for languages that use procedure, functions, or methods manage their run-time memory as a stack. Whenever a procedure is called, the local variable's space...

2 minutes read.

Storage Allocation

Storage Allocation The storage allocation represents memory management. The allocation of memory can be done in the following ways: Static AllocationStack AllocationHeap Management Static Allocation: It is a procedure used for the allocation of...

1 minute read.

Machine-Independent Optimizations in Compiler Design

Machine-Independent Optimizations The main aim of machine-independent optimization is to improve the generated intermediate code so that compiler can get better target code. Eliminating unwanted code from the object code or replacing...

8 minutes read.

Intermediate-Code Generator Compiler Design

Intermediate-Code Generator The process of translating a source language into machine code for a given target machine is done by intermediate-code. It lies between the high-level language and the machine language....

2 minutes read.

S-attributed and L-attributed SDTs

S-attributed and L-attributed SDTs STD stands for Syntax Directed Translation. When we associate some informal notations called semantic rules and the grammar, they are known as STD. So we can say...

2 minutes read.

Derivation and Parse Tree in Compiler Design

Derivation and Parse Tree In this article, we will learn Derivation and Parse Tree. Derivations The parse tree can be constructed by taking a derivational view in which production is treated as rewriting...

4 minutes read.

YACC in Compiler Design

YACC  YACC is known as Yet Another Compiler Compiler. It is used to produce the source code of the syntactic analyzer of the language produced by LALR (1) grammar. The input...

5 minutes read.

Three-Address Code

Three-Address Code If there is at most one operator on the right side of the instruction, then the instruction will be the three-address code so that no arithmetic expressions are permitted....

2 minutes read.

Phases of Compiler

Phases of Compiler The compilation process of a compiler goes through various phases. Each phase of the compiler takes the output from the previous as an input. Here we will see all...

2 minutes read.

Basic Blocks and Flow Graphs in Compiler Design

Basic Blocks and Flow Graphs In this section, we are going to learn how to work with basic block and flow graphs in compiler design. Basic Block The basic block is a set...

3 minutes read.

Syntax-Directed Translation

Syntax-Directed Translation A context-free-grammar with some additional rules is known as a syntax-directed definition. In SDT, attributes are associated with grammar symbols and rules are associated with productions. The attributes can...

3 minutes read.

Evolution of Programming Languages in Compiler Design

The Evolution of Programming Languages The first computer came in the 1940s and was programmed in a binary language that told the computer what operations are to be performed and in...

4 minutes read.

Syntax Analysis Compiler Design

Syntax Analysis This article will describe the parsing method used in the compiler. The grammatical rule of programming language can be constructed with the help of context-free grammars or BNF (Backus–Naur...

3 minutes read.

Errors in Compiler Design

Introduction Errors in compiler design refer to mistakes or issues that arise during the process of execution of the program. A compiler is a program that translates source code written in...

4 minutes read.

Parsing in Compiler Design

Parsing is the term used to describe the process of converting data between different formats. The parser can carry out this operation. The parser is a part of the translator...

4 minutes read.

Regular Expression | Compiler Design

Regular Expression A regular expression is a set of patterns that can match a character or string. It can also match alternative characters or strings. The grammar defined by the regular...

3 minutes read.

Run-Time Environments

Run-Time Environments Storage Organization Every target program has its own logical address, and an executable program runs in it. The logical address space has the location for each program value. The...

2 minutes read.

LEX

LEX Lex is a tool/computer program that generates a Lexical analyzer. Lex is developed by Vern Paxson in C around 1987. Lex works together with the YACC parser generator. It allows...

3 minutes read.

Finite State Machine

Finite State Machine A finite state machine is a simple machine to recognize patterns. It takes a string of symbols as the input and changes its state to another state, but...

3 minutes read.

Compiler Design Tutorial

Our compiler design tutorial will provide all the information about compiler from basic to advanced level. This compiler tutorial will help the student for their semester as well as for...

3 minutes read.