Top 50 Embedded Systems Interview Questions You Must Prepare 07.Dec.2019

Top 50 Embedded Systems Interview Questions You Must Prepare 07.Dec.2019

Embedded Systems Interview Questions and Answers

Embedded Systems Interview Questions and Answers

Advantages And Disadvantages Of Using Macro And Inline Functions?

Advantage: Macros and Inline functions are efficient than calling a normal function. The times spend in calling the function is saved in case of macros and inline functions as these are included directly into the code.
Disadvantage: Macros and inline functions increased the size of executable code.

Can A Pointer Be Volatile ?

Yes, although this is not very common. An example is when an interrupt service routine modifies a pointer to a buffer.

What Is Mutex?

Mutual exclusion (often abbreviated to mutex) algorithms are used in concurrent programming to avoid the simultaneous use of a common resource, such as a global variable, by pieces of computer code called critical sections.

What Is A Memory Leak? What Is A Segmentation Fault?

The memory leak refers to the uncleared memory may builds up across lifetime of the process. When it comes to a huge value system stalls its execution due to unavailability of the memory. The segmentation fault on the other hand refers to condition when our program tries to access a memory space that has already been freed up.

What Is The Difference Between Fifo And The Memory?

Fifo(First In Last Out) is a memory structure where data can be stored and retrieved (in the order of its entry only). This is a queue,wheras Memory is a storage device which can hold data dynamically or at any desired locations and can be retrieved in any order.

Accessing Fixed Memory Locations?

Embedded systems are often characterized by requiring the programmer to access a specific memory location. On a certain project it is required to set an integer variable at the absolute address 0x67a9 to the value 0xaa5@The compiler is a pure ANSI compiler. Write code to accomplish this task.

This problem tests whether you know that it is legal to typecast an integer to a pointer in order to access an absolute location. The exact syntax varies depending upon one's style. However, I would typically be looking for something like this:

  int *ptr;  ptr = (int *)0x67a9;  *ptr = 0xaa55;    

A more obscure approach is:

  *(int * const)(0x67a9) = 0xaa55;

Which Is The Best Way To Write Loops?

The best way is to write count down loops and compiler can generate better machine code for it than the count up loops. In count down at loop termination, it needs to generate one instruction (SUBS), which subtracts as well as check the zero flag, but in count up case it has to add and compare with a constant, which takes two instructions.

How Are Variables Mapped Across To The Various Memories By The C Compiler?

The compiler maintains the symbol table which has the related information of all the variable names along with the length of the allocated space, the access unit length for the pointer (type of pointer) and the starting address of the memory space.

Can A Volatile Be Constant?

volatile const a;
Yes it can be, it me that, it can be changes by hardware state change, but its read only register in hardware, so code should not try to modify it.

What Is Isr? Can They Be Passed Any Parameter And Can They Return A Value?

ISR refers to the Interrupt Service Routines. These are procedures stored at specific memory addresses which are called when certain type of interrupt occurs. The ISRs cannot return a value and they cannot be passed any parameters.

Explain Can We Have Constant Volatile Variable?

Const and volatile keywords should not be used together because both are opposite in nature. A variable is declared as "const" me it's value is not able to be changed but if it is declared as "Volatile" then it is not under control.

How Is Function Itoa() Written In C?

  #include<stdlib.h>  #include<stdio.h>  int main()  {  int n = 6789;  char p[20];  itoa(n,s,10);  printf("n=%d,s=%s",n,s);  return 0;  } 

What Is The Size Of The Int, Char And Float Data Types?

The size of the char and int are always dependent on the underlying operating system or firmware. This is limited to the number of address lines in the address bus. The int usually takes up a value of 2 bytes or 4 bytes. The char can take up a space of 1 or 2 bytes. The float data type takes up a value of 4 bytes.

Explain The Properties Of A Object Oriented Programming Language.

  • Encapsulation: The data that are related to the specific object are contained inside the object structure and hidden from the other entities of the environment.  
  • Polymorphism: The mechanism by which the same pointer can refer to different types of objects, which are basically linked by some generic commonality.
  •  Abstraction: Hiding the data and implementation details from the real objects. The framework of reference is still present to be used by the other objects.
  •  Inheritance: The way to take out the common features and have them as separate object entities only to be reused by the other objects in a modular fashion.

What Is The Order Of Calling For The Constructors And Destructors In Case Of Objects Of Inherited Classes?

The constructors are called with base class first order and the destructors are called in the child first order. That is, the if we have 2 levels of inheritance A (base)-> B (inherit 1)-> C (inherit 2) then the constructor A is called first followed by B and C. The C destructor is called first followed by B and A.

What Is Plc System?

Programming logical control system.

What Is A 'volatile' Variable?

Volatile is a keyword to specify the compiler that this variable value can change any time, so compiler should always read its value from its address, and not to use temporary registers to store its value and use in later part of the code. This is especially important to handle the memory mapped registers which are mapped as some variables or structures in embedded systems, such as hardware status registers etc, whose value can be changed anytime, depending on the hardware state.

Examples of volatile variables are,
• Hardware registers in peripherals (for example, status registers)
• Non-automatic variables referenced within an interrupt service routine
• Variables shared by multiple tasks in a multi-threaded application

What Is Meant By A Forward Reference In C?

The forward reference refers to the case when we point an address space of a smaller data type with a pointer of a bigger data type. This can be pictured as allocating memory in single bytes and accessing it with integer pointer as chunks of 4.

Which Is Better A Char, Short Or Int Type For Optimization?

Where possible, it is best to avoid using char and short as local variables. For the types char and short the compiler needs to reduce the size of the local variable to 8 or 16 bits after each assignment. This is called sign-extending for signed variables and zero extending for unsigned variables. It is implemented by shifting the register left by 24 or 16 bits, followed by a signed or unsigned shift right by the same amount, taking two instructions (zero-extension of an unsigned char takes one instruction).

These shifts can be avoided by using int and unsigned int for local variables. This is particularly important for calculations which first load data into local variables and then process the data inside the local variables. Even if data is input and output as 8- or 16-bit quantities, it is worth considering processing them as 32bit quantities

Difference In Inline Functions And Macro

  •  Macro is expanded by preprocessor and inline function are expanded by compiler.
  •  Expressions passed as arguments to inline functions are evaluated only once while _expression passed as argument to inline functions are evaluated more than once.
  • More over inline functions are used to overcome the overhead of function calls.
  • Macros are used to maintain the readability and easy maintenance of the code.

What Is Interrupt Latency?

Interrupt latency refers to the amount of time between when an interrupt is triggered and when the interrupt is seen by software.

What Does Malloc Do? What Will Happen If We Have A Statement Like Malloc(sizeof(0));

Malloc is the function that is used for dynamically allocating memory to the different variables. The malloc returns a memory pointer of void type (void *). The statement malloc(sizeof(0)) returns a valid integer pointer because sizeof(0) represents the size of memory taken up by the integer value of @The memory allocated by memory is not automatically cleaned up by the compiler after execution of the functions and should be cleaned up by the programmer using the free() function.

What Is Difference Between Using A Macro And Inline Function?

The macro are just symbolic representations and cannot contain data type differentiations within the parameters that we give. The inline functions can have the data types too defined as a part of them. The disadvantage in using both is that the inclusion of condition checks may lead to increase in code space if the function is called many times.

What Type Of Registers Contains An (intel) Cpu?

Special function registers like accumulator, Program controller(PC),data pointer(DPTR),TMOD and TCON (timing registers),3 register banks with r0 to r7,Bit addressable registers like B.

Explain Can Microcontroller Work Independently?

Obviously, it can work independently. But to see the output we need certain output devices like LED, Buzzer can be connected to check its functionality. Without the help of any o/p device connected we can check the functionality of Microcontroller.

What Is Semaphore?

In computer science, a semaphore is a protected variable or abstract data type which constitutes the classic method for restricting access to shared resources such as shared memory in a parallel programming environment. A counting semaphore is a counter for a set of available resources, rather than a locked/unlocked flag of a single resource.

What Is The Use Of Having The Const Qualifier?

The const qualifier identifies a specific parameter or variable as read-only attribute to the function or to the entire program. This can come in handy when we are dealing with static data inside function and in a program.

Explain What Happens When Recursion Functions Are Declared Inline?

Inline functions property says whenever it will called, it will copy the complete definition of that function. Recursive function declared as inline creates the burden on the compilers execution. The size of the stack may/may not be overflow if the function size is big.

What Do You Mean By Interrupt Latency?

Interrupt latency refers to the time taken for the system to start the handler for the specific interrupt. The time from the time of arrival of interrupt to the time it is being handled.

What Is Difference Between Micro Processor & Micro Controller?

  •  Microprocessor is a manager of the resources (I/O, Memory) which lie out-side of its architecture.
  • Micro-controllers have I/O, Memory etc. built into it and specially designed for Control applications.

Why Cannot Arrays Be Passed By Values To Functions?

When a array is passed to a function, the array is internally changed to a ‘pointer’. And pointers are always passed by reference.

Write A Constant Time Consuming Statement Lot Finding Out If A Given Number Is A Power Of 2?

If n is the given number, then the expression (n & (n-1)) = 0 gives the logical output depicting if it is a power of 2 or not, if (n & (n-1) == 0) printf (“The given number is a power of 2”);

Scope Of Static Variables?

Scope of static variable is within the file if it is static global. Scope of static variable is within the function if variable is declared local to a function. But the life time is throughout the program.

What Are Recursive Functions? Can We Make Them Inline?

The recursive functions refer to the functions which make calls to itself before giving out the final result. These can be declared as in-line functions and the compiler will allocate the memory space intended for the first call of the function.

Explain Can Structures Be Passed To The Functions By Value?

Yes structures can be passed to functions by value. Though passing by value has two disadvantages:
1) The charges by the calling function are not reflected.
2) It’s slower than the pass by reference function call.

Explain What Will This Return Malloc(sizeof(-10))?

It will return a 4 byte address value.
Because -10 is a signed integer(varies from compiler to compiler).

What Are The Advantages And Disadvantages Of Using Macro And Inline Functions?

Advantage:
Macros and Inline functions are efficient than calling a normal function. The times spend in calling the function is saved in case of macros and inline functions as these are included directly into the code.
Disadvantage:
Macros and inline functions increased the size of executable code.

Why Do We Need A Infinite Loop In Embedded Systems Development? What Are The Different Ways By Which You Can Code In A Infinite Loop?

The infinite loops are coded in to give a delay or sleep to the program execution for a specific amount of clock ticks. They can be implemented as:

  while(;;);   for();   (or)   Loop:   goto Loop;

Explain What Is Interrupt Latency? How Can We Reduce It?

Interrupt latency is the time required to return from the interrupt service routine after tackling a particular interrupt. We can reduce it by writing smaller ISR routines.

What Is A Semaphore? What Are The Different Types Of Semaphore?

The semaphore is an abstract data store that is used to control resource accesses across the various threads of execution or across different processes. There are two types of semaphores:
• The binary semaphore which can take only 0,1 values. (used when there is contention for a single resource entity). 
• The counting semaphore which can take incremental values to certain limit (used when number of resources is limited).

Explain What Is Forward Reference W.r.t. Pointers In C?

Pointer use's to reference to value a into int a=10 to memory add this value and 10 is add p value added this data in memory location for p.

What Is Pass By Value And Pass By Reference? How Are Structure Passed As Arguments?

The parameter to a function can be a copy of a value that is represented by variable or can be a reference to a memory space that stores value of variable. The former is referred to as pass by value and the latter is referred to as pass by reference. The difference is that when parameters are passed by value the changes made to the variable value within the function is not reflected in the caller function, but when passed as reference changes are reflected outside the called function. The structures are always passed by reference.

What Is A Pure Function In Arm Terminology?

Pure functions are those which return a result which depends only on their arguments. They can be thought of as mathematical functions: they always return the same result if the arguments are the same. To tell the compiler that a function is pure, use the special declaration keyword __pure.

  __pure int square(int x)  {      return x * x;  }

What Is Concurrency? Explain With Example Deadlock And Starvation.

Concurrency is nothing but execution of different tractions simultaneously on one single resource.
Dead lock :
A group of threads are waiting for resources held by others in the group. None of them will ever make progress.
Example :
An example of a deadlock which may occur in database products is the following. Client applications using the database may require exclusive access to a table, and in order to gain exclusive access they ask for a lock. If one client application holds a lock on a table and attempts to obtain the lock on a second table that is already held by a second client application, this may lead to deadlock if the second application then attempts to obtain the lock that is held by the first application.
Starvation :
A thread may wait indefinitely because other threads keep coming in and getting the requested resources before this thread does. Note that resource is being actively used and the thread will stop waiting if other threads stop coming in.
Example :
High priority thread:

  while(1);

if the system is priority based system then low priority thread never gets a chance.

 

Dma Deals With Which Address (physical/virtual Addresses)?

DMA deals with Physical addresses.

  • Only when CPU accesses addresses it refers to MMU(Memory Management Unit) and MMU converts the Physical address to Virtual address.
  • But, DMA controller is a device which directly drives the data and address bus during data trfer. So, it is purely Physical address. (It never needs to go through MMU & Virtual addresses).
  • That is why when writing the device drivers, the physical address of the data buffer has to be assigned to the DMA.

What Is The Difference Between Embedded Systems And The System In Which Rtos Is Running?

Embedded system is just combination of s/w and h/w that is some embedded system may have os some may not and rtos is an os.

                                                                  OR

Embedded system can include RTOS and cannot include also. it depends on the requirement. if the system needs to serve only event sequentially, there is no need of RTOS. If the system demands the parallel execution of events then we need RTOS.

What Is Loop Unrolling?

Small loops can be unrolled for higher performance, with the disadvantage of increased codesize. When a loop is unrolled, a loop counter needs to be updated less often and fewer branches are executed. If the loop iterates only a few times, it can be fully unrolled, so that the loop overhead completely disappears.

  int CountBitOne(uint n)  {         int bits = 0;      while (n != 0)      {          if (n & 1) bits++;          n >> = 1;      }    return bits;  }     int CountBitOne(uint n)  {     int bits = 0;      while (n != 0)      {      if (n & 1) bits++;      if (n & 2) bits++;      if (n & 4) bits++;      if (n & 8) bits++;      n >> = 4;      }    return bits;  }  

What Is The Role Of Segment Register?

In the x86 processor architecture, memory addresses are specified in two parts called the segment and the offset. One usually thinks of the segment as specifying the beginning of a block of memory allocated by the system and the offset as an index into it. Segment values are stored in the segment registers. There are four or more segment registers: CS contains the segment of the current instruction (IP is the offset), SS contains the stack segment (SP is the offset), DS is the segment used by default for most data operations, ES (and, in more recent processors, FS and GS) is an extra segment register. Most memory operations accept a segment override prefix that allows use of a segment register other than the default one.

What Is Dirac Delta Function And Its Fourier Trform And Its Importance?

  • Dirac delta is a continuous time function with unit area and infinite amplitude at t=0 the fourier trform of dirac delta is @
  • using dirac delta as an input to the system, we can get the system response. it is used to study the behavior of the circuit.
  • we can use this system behavior to find the output for any input.

Explain What Are The 5 Different Types Of Inheritance Relationship?

5 level types are as under:

  • single: B derived from A.
  • multilevel: derived from B and B derived from A.
  • multiple: C derived from A and B.
  • Hierarchical: B derived from A and C derived from A.
  • hybrid: combination of above types.