Embedded Interview Questions PDF
Embedded Interview Questions PDF
1. Describe inheritance, multithreading, watchdog timer, etc.
a. Inheritance: Inheritance allows us to define a class in terms of another class,
which makes it easier to create and maintain an application. Inheritance
allows to reuse the code functionally and allows fast implementation time.
b. Multithreading: Multithreading is the ability of a program to manage its use
by more than one user at a time and to even manage multiple requests by the
same user without having to have multiple copies of the programming
running in the computer.
c. Watchdog timer: WDT is a piece of hardware that can be used to
automatically detect software anomalies and reset the processor if any occur.
2. What is virtual memory and caches(Also read upon Cache coherency)
a. Physical memory is scarce in machines, so virtual memory is an optimization
to expand that
b. Memory stored in pages in hard disk and by using caches
3. What are priority inversion, reentrancy, spinlocks
a. Priority Inversion: lower priority task running with semaphore, higher
priority is waiting for semaphore. Medium priority task interrupts, runs, and
then high priority can run
i. Solution is to bump priority of low priority to highest priority and then
it can’t be preempted by medium (It’s called priority inheritance)
b. Reentrancy: function is reentrant when during its execution if it gets
interrupted, it can return and resume function without any change
i. Can’t use global/static data
c. Spinlock: a task is waiting for a certain resource that is locked and is
continually checking if it opened up, using most of the CPU resources
i. Good rule of thumb - avoid them in user code
4. What is atomic programming/non-locking operation?
a. Atomic operations are operations that are guaranteed to keep their values
safe
Atomicity
In computer programming, an operation done by a computer is
C/C++ Concepts
-->when to use linked list
a. you need constant-time insertions/deletions from the list (such as in
real-time computing where time predictability is absolutely critical)
b. you don't know how many items will be in the list. With arrays, you may need
to re-declare and copy memory if the array grows too big.
c. you don't need random access to any elements
d. you want to be able to insert items in the middle of the list (such as a priority
queue)
a class "CAR" : Its objects are Hyundai, Ford, Suzuki. It will have the same methods but
different designs -> this is how you can relate objects and classes with the real world.
8. what are virtual functions? How are they used? Why are they used? When are they
used? Example?
a. To achieve runtime polymorphism
b. They are defined in base classes - and overridden in derived classes
c. For example, input vehicle...but don’t know if car, bus, or truck
A virtual function is a member function which is declared within base class and is re-defined
(Overridden) by derived class. When you refer to a derived class object using a pointer or a
reference to the base class, you can call a virtual function for that object and execute the
derived class’s version of the function.
● Virtual functions ensure that the correct function is called for an object,
regardless of the type of reference (or pointer) used for function call.
● They are mainly used to achieve Runtime polymorphism
● Functions are declared with a virtual keyword in base class.
● The resolving of function call is done at Run-time.
9. How is multiply is implemented?
a. Set result to 0
b. Repeat
c. Shift 2nd multiplicand left until rightmost digit is lined up with leftmost 1 in
first multiplicand
i. Add 2nd multiplicand in that position to result
ii. Remove that 1 from 1st multiplicand
d. Until 1st multiplicand is zero
e. Result is correct
10. Design an elevator system
a. I started from thinking about how many buttons (including buttons inside the
elevator, and outside for every floor) should be tracked in this system.
b. After that, considered how to implement an ISR (interrupt service routine)
and what data structure should be used (maybe a queue for the next targeted
store, and a array for status of all buttons) to track them, and use these
information to control the elevator.
11. How post increment works.
a. You use the value first and then increment it.
12. One questioner asked how to modify a malloc to guarantee that it was 32-byte
aligned
a. ptr & ~0x1F will set the last 5 bits to 0, making it 32 byte aligned
13. How do breakpoints in a C program work?
a. http://www.nynaeve.net/?p=80
14. How does a debugger work?
15. ISR & interrupt vector table
a. ISR addresses stored in vector table
16. Float to int conversion
17. Memory map of program
a. Output from linker script
b. Bss is uninitialized data
c. Data is initialized data
d. Text is names, symbols etc
18. If we declare more number of variables than the registers available on the processor?
Where they will be stored.
a. In some memory block and they are loaded back appropriately into registers
b. Have to remove something that’s in memory at that point
19. How to handle the Generic functions , like Void pointers
a. Function that accepts void pointers should only accept one type
20. Data Struct/Class memory padding
a. // char 1 byte
b. // short int 2 bytes
c. // int 4 bytes
d. // double 8 bytes
e. // pointer 4 bytes in 32 bit machine, 8 in 64-bit
f. Memory is padded to nearest multiple
g. For optimizing memory accesses for byte addressable memory
21. Difference between Macro and Inline?
a. Macros are used for repeating functions throughout the code, so you use
#define at the top and the preprocessor typically takes care of this
b. Inline functions tell the compiler that the function is also defined at that spot
-so you save time by not jumping to another location, jumping back,
c. Inline functions provides following advantages over macros.
● Since they are functions so type of arguments is checked by the
compiler whether they are correct or not.
● There is no risk if called multiple times. But there is risk in macros
which can be dangerous when the argument is an expression.
● They can include multiple lines of code without trailing backslashes.
● Inline functions have their own scope for variables and they can
return a value.
● Debugging code is easy in case of Inline functions as compared to
macros.
22. How to avoid overflow/underflow
a. Use types like long double for more precision and more bits
23. How do you send data over the network between two machines with different
endianess
a. https://www.ibm.com/developerworks/aix/library/au-endianc/index.html
b. https://barrgroup.com/Embedded-Systems/How-To/Big-Endian-Little-End
ian
Coding
General
UART
SPI
I2C
● SDA/SCL
● Synchronized to the clock signal
● Start + Address Frame + ACK + Data Frames + ACK + Stop
● Both ways transfer
CAN
4G/LTE
5G
Sorting Algorithms
Time Complexity Space Complexity
Sort
Best Worst Average Best Worst Average
Bubble Sort O(n^2) O(n^2) O(n^2) O(1) O(1) O(1) completes some pre sorting
Selection Sort O(n^2) O(n^2) O(n^2) O(1) O(1) O(1) good for small arrays
Adaptive
O(n^2) O(n^2) O(n^2) O(1) O(1) O(1)
Insertion
Bucket Sort O(n) O(n) O(n) O(1) O(1) O(1) good for small universes
fastest sort, good to start
O(n log O(log
Quick Sort O(n log n) O(n^2) O(1) O(log n) out and do insertion for
n) n) internal loop
O(n log
Merge Sort O(n log n) O(n log n) O(n) O(n) O(n)
n)
fixdown, fixup (log n), build
O(n log heap (n) heapsort( build
Heap Sort O(n log n) O(n log n) O(1) O(1) O(1) heap and fix down from
n)
bottom)
Additional firmware interview Questions - from glassdoor
1. Swap two variables without using a temporary variable
2. How to invert all bits in a byte?
3. C function that takes two bit indices and an int, reverses the bits in the int between
the two indices.
4. Name a few different type of registers.
5. What is priority inversion and methods to avoid it?
6. Disadvantage of recursive function call in C in a resource constrained environment.
7. What is an interface?
8. What is an abstract class? - C++ concepts
9. How many pins in JTAG cable? - 20
10. What techniques would you use to reduce power consumption in an embedded
system?
a. Sleep modes , refresh operation
11. What kind of data structure you will use to store data from a serial receive line?
a. Queue - FIFO
12. Write a C program to determine endianness of a microprocessor
13. Detect loop in a linked list
14. Difference between semaphore, mutex and spinlock
15. What are some ways in which UART can have communication error?
16. Traversing Binary Tree
17. Find an element using Binary Search in array
18. Switch debouncing software logic
19. Where do global variables get stored?
20. Inter thread communication, Inter process communication
21. What is extern variable?
5 Memory Segments in C:
1. Code Segment
● The code segment, also referred as the text segment, is the area of
memory which contains the frequently executed code.
● The code segment is often read-only to avoid risk of getting
overridden by programming bugs like buffer-overflow, etc.
● The code segment does not contain program variables like local
variable (also called as automatic variables in C), global variables, etc.
● Based on the C implementation, the code segment can also contain
read-only string literals. For example, when you do p rintf("Hello,
world") then string "Hello, world" gets created in the code/text
segment. You can verify this using s ize command in Linux OS.
● Further reading
Data Segment
The data segment is divided in the below two parts and typically lies below the
heap area or in some implementations above the stack, but the data segment
never lies between the heap and stack area.
4. Stack Segment
● Stack segment is used to store variables which are created inside
functions (function could be main function or user-defined function),
variable like
1. Local variables of the function (including pointer variables)
2. Arguments passed to function
3. Return address
● Variables stored in the stack will be removed as soon as the function
execution finishes.
● Further reading
5. Heap Segment