Write function in C that gets array of chars, and search for the longest sequence of repeatedly 1 bits. It returns the the first bit place in the sequence and the number of 1 bits in the sequence. - (a) loop of 2^0, 2^1, … , 2^7 is done with 1<<j when 0<=j<=7. (b) Take care of remembering the first place of the bit sequence you are counting.

You have 16bit register that increment itself and loops about every second. When the register reach 0xffff it will issue an interupt and will run the function update_time(). There is a function unsigned long get_time() that returns the time. You need to implement the two functions. - (a) You need to count every interrupt in order to save the number of seconds. (b) The counter will be the 16bit MSB, and the actual register will be 16bit LSB. (c) If the register will be at ~0xfff0, you will return MSB that is not correct, because you will read the counter, then interrupt will accure and increment by one. Now you have counter that is not correct. (d) You need to check for the (c) problem, and if you catch the problem, you need to read once again the register and the counter before you return them. You depend on the fact the you have about another second until the register will loop.

hi saikrishna,
Thatz very simple… rotate left the byte which u want to muitiply by 2.
For ex:
mov a,#02h
rol a /*this gives the result.Remember it has a limitation if u hav a value whose MSB is high then this logic fails to work i mean result will fail. so to over come this we need to rotate it thru carry i.e. “rlc a” and assume carry as 9th bit.*/

## 2 Comments on Embedded firmware interview questions

How can we write 2 multiplication table using bitwise operators.

hi saikrishna,

Thatz very simple… rotate left the byte which u want to muitiply by 2.

For ex:

mov a,#02h

rol a /*this gives the result.Remember it has a limitation if u hav a value whose MSB is high then this logic fails to work i mean result will fail. so to over come this we need to rotate it thru carry i.e. “rlc a” and assume carry as 9th bit.*/