Wednesday, July 11, 2018

System Software Engineering


Q1. Explain Addressing modes & data allocation structure?
Ans:
Addressing mode is the way of addressing a memory location in instruction. Microcontroller needs data or operands on which the operation is to be performed. The method of specifying source of operand and output of result in an instruction is known as addressing mode. 
There are various methods of giving source and destination address in instruction, thus there are various types of Addressing Modes. Here you will find the different types of Addressing Modes that are supported in Micro Controller 8051. Types of Addressing Modes are explained below:

Types Of Addressing Modes
Following are the types of Addressing Modes:
·         Register Addressing Mode
·         Direct Addressing Mode
·         Register Indirect Addressing Mode
·         Immediate Addressing Mode
·         Index Addressing Mode
Explanation:
1.      Register Addressing Mode: In this addressing mode, the source of data or destination of result is Register. In this type of addressing mode the name of the register is given in the instruction where the data to be read or result is to be stored.
Example: ADD A, R5 ( The instruction will do the addition of data in Accumulator with data in register R5)
2.      Direct Addressing Mode: In this type of Addressing Mode, the address of data to be read is directly given in the instruction. In case, for storing result the address given in instruction is used to store the result.
Example: MOV A, 46H ( This instruction will move the contents of memory location 46H to Accumulator)
3.      Register Indirect Addressing Mode: In Register Indirect Addressing Mode, as its name suggests the data is read or stored in register indirectly. That is, we provide the register in the instruction, in which the address of the other register is stored or which points to other register where data is stored or to be stored.
Example: MOV A, @R0 ( This instruction will move the data to accumulator from the register whose address is stored in register R0 ).
Also Read: 
Architecture Of 8051
4.      Immediate Addressing Mode : In Immediate Addressing Mode , the data immediately follows the instruction. This means that data to be used is already given in the instruction itself.
Example: MOV A, #25H ( This instruction will move the data 25H to Accumulator. The # sign shows that preceding term is data, not the address.)
5.      Index Addressing Mode: Offset is added to the base index register to form the effective address if the memory location.This Addressing Mode  is used for reading lookup tables in Program Memory. The Address of the exact location of the table is formed by adding the Accumulator Data to the base pointer.
Example: MOVC, @A+DPTR ( This instruction will move the data from the memory to Accumulator; the address is made by adding the contents of Accumulator and Data Pointer


Data Allocation Structure
Dynamic Memory Allocation in C/C++
Motivation
/* a[100] vs. *b or *c */
 Func(int array_size)
 {
double k, a[100], *b, *c;
b = (double *) malloc(array_size * sizeof(double)); /* allocation in C*/
 c = new double[array_size];
/* allocation in C++ */ }
• The size of the problem often can not be determined at “compile time”.
• Dynamic memory allocation is to allocate memory at “run time”.
• Dynamically allocated memory must be referred to by pointers.

Stack vs Heap
When a program is loaded into memory:
• Machine code is loaded into text segment
 • Stack segment allocate memory for automatic variables within functions
• Heap segment is for dynamic memory allocation
 Pointers
 • A variable can be viewed as a specific block of memory in the computer memory which can be accessed by the identifier (the name of the variable).
 – int k; /* the compiler sets aside 4 bytes of memory (on a PC) to hold the value of the integer. It also sets up a symbol table. In that table it adds the symbol k and the relative address in memory where those 4 bytes were set aside. */
– k = 8; /*at run time when this statement is executed, the value 8 will be placed in that memory location reserved for the storage of the value of k. */
 • With k, there are two associated values. One is the value of the integer, 8, stored. The other is the “value” or address of the memory location.
• The variable for holding an address is a pointer variable.
– int *ptr; /*we also give pointer a type which refers to the type of data stored at the address that we will store in the pointer*/
 – ptr = &k; /* & operator retrieves the address of k */
– *ptr = 7; /* dereferencing operator “*” copies 7 to the address pointed to by ptr */
• Pointers and arrays – int a[100], *ptr_a; – ptr_a = &(a[0]); /* or ptr_a = a; */ – ptr_a++; /*or ptr_a += 1; */ // ptr_a points to the next integer, a[1];

Memory Allocation/Free Functions in C/C++ 6
C:
• void *malloc(size_t number_of_bytes) -- allocate a contiguous portion of memory -- it returns a pointer of type void * that is the beginning place in memory of allocated portion of size number_of_bytes.
• void free(void * ptr); -- A block of memory previously allocated using a call to malloc, calloc or realloc is deallocated, making it available again for further allocations.
C++:
 • “new” operator -- pointer = new type -- pointer = new type [number_of_elements] -- It returns a pointer to the beginning of the new block of memory allocated.
• “delete” operator -- delete pointer; -- delete [] pointer;
Example 1
Func()
/* C++ version */
{
 double *ptr;
ptr = new double;
*ptr = -2.5;
 }
Func_C()
/* C version */
{ double *ptr;
 ptr = (double *) malloc(sizeof(double)); …. }







Q2. Describe activities and system software for program generation, translation & Execution .
Ans:
Program generation activities: A program generation activity aims at automatic generation of a program. The source language is a specification language of an application domain and the target language is typically a procedure oriented programming language. the following figure shows program generation activity

 http://www.enggpedia.com/answers/

The program generator is a software system which accepts the specification of a program to be generated and generates a program in the target. PL. The program generator introduces a new domain between the application and PL domains. We call this the program generator domain. The specification gab is now gab between the application domain and the program generator domain. This gab is smaller than the gab between the application domain and PL domain.


Program execution activities: A program execution activity organizes system. Two model program executions are:
  1. Translation
  2. Interpretation

Translation: The program translation models bridges execution gap by translating a program written in a PL, called the source program into an equivalent program in the machine or assembly language of the computer system.

 http://www.enggpedia.com/answers/

Interpretation: The interpreter reads the source program and stores it in its memory. During interpretation it takes a statement, determines its meaning and performs actions which implement it.
High-level procedural languages may be compiled, or they may be interpreted
 A compiler operates on the entire program, translate it and generating a permanent binary module representing the program. This module can then be executed. Translation and execution are separate processes.
An interpreter translate source code and executes it, one source code program line at a time. Translation and execution are interlaced processes.

No comments:

Post a Comment

Goods and Services Tax (GST) in Hindi and English

 Goods and Services Tax (GST) Goods and Service Tax  ( GST ) is an  indirect tax  (or  consumption tax ) levied in  India  on the supp...