Mentor Graphics is a US based multinational company that deals with electronic design and electrical and hardware based software related services. I was recently called for interview in its Lahore office after being short listed. It was a technical interview and for job related to Embedded system so most of the questions were about either embedded systems or C language and hardware.hh
Their email described following things
Following are some questions and answers asked form me by interviewer.
10. See following program
const int x=9;
What will happen if i tried to change value of x?
It will give and error.
11. Now see this
int *p;
p=&x;
*p=10;
What will happen in this case?
Again same error.
12. What will be output of following?
13. If both have same sizes, why can't we use int type pointer for double type?
'cause a double type pointer is pointing a double and int type is pointing int. [Not sure]
14. How you configured timer in your project?
In data sheet of the controller, sequence to set bits of relevant register were given. There were some parameters like overflow value etc were to be set to start that timer.
That registers were set and it was configured.
15. How you used timer?
Timer was used to produce delays and also to sample data at regular intervals. So We used Sys Tick timer which is 24 bit timer. We used 80Mhz clock. It was count up timer. Each bit was count up after the delay of (1/80M)s so routine was made to produce of specific intervals.
16. What if you can't set value of a timer and you have to produce some specific interval?
Then we can set it Reload value. So every time overflow occurs, it will reload with a value relevant to our delay.
17. Following is a c Code
struct A a1[4]; [He was suspicious about this, he said it will be then struct of struct, I think he was confused with Cpp]
18. Now what will happen if i do following a1++?
[I was confused here, We had argument. He tried to convince me something may be he was trying to trap me. Unfortunately, I got into trap and I think answered wrong ]
It will be a compiler error.
19. What is pipeline in MCU's?
It is a concept that while one instruction is being loaded, other will also be loaded to save time. He asked another question but I said that I dont know deep about this so...
20. What is const int *p and int int const *p who will be constant in these?
It is a famous question in interviews of C. It can be found here.
http://stackoverflow.com/questions/1143262/what-is-the- difference-between-const-int-const-int- const-and-int-const
21. By what steps program is compiled? [He asked it differently but I don't remember exact words]
http://stackoverflow.com/questions/3996651/what-is-compiler-linker-loader
21. What is difference between big endian and little endian?
Both are ways of storing memory. In little endian, LSB is stored in smaller address place and MSB is placed in higher address places. Vice versa is true in other.
22. Suppose we have a system, a black box, we don't know anything about it. How can you know weather its big endian or little endian?
We can write a simple program as following
char var=1;
int c;
c=(int) var;
As we know int is a 4 byte and char is one byte. Now when type casted, c will have 4 bytes. So if it will be equal to 1 it means little endian other wise big endian.
23.What is interrupt and what happens when it occurs?
An interrupt is blockage in flow of main program. I told him whole process of interrupts what I have read in ARM with all the details.
24. So how NVIC know ISR address.
I told him that it IPSR register where interrupt number is loaded form NVIC. All the ISR's are stored in a memory address from 0 to top. So after this PC loads that specific interrupt. But he was not convinced.
25. Following is a program
We can write ~(printf("Hellow")). As return type of printf is number of bytes being printed. So what if condition will be false but print function will print Hellow and then it will go to else and will print World.
26. Suppose data of an automotive is stored in location like following
Now suppose at location 0-3 car reg number is stored, on 4-9 something else is saved and so on and so far. Write a C program that takes starting bit, and size and extracts all of them and returns.
[I was a bit wrong in this. I told him right algorithm but I was failed to produce right c code for cutter]
27. Suppose a MCU has only 12 registers while a C program is using 20 variables in it. All of them at once. How registers will manage it?
Register are only there to speed up the process of CPU by providing immediate data. In fact these variables are stored in memory. One other way is pushing and then poping when required in stack.
It was very interesting interview. I imagined it as two nerds discussing most nerdy things. We argued a lot of time during interview. Overall it was best experience.
Their email described following things
You will be assessed as per following criteria:
- Good programming experience in C and or/Java
- Good understanding of hardware Architecture (x86, ARM or MIPS) and Operating Systems Concepts
- Hands-on experience with either of following embedded development environment would be a plus – Keil, RealView MDK, IAR Embedded Workbench, Code Composer Studio, Sourcery Codebench
- What is Cache memory?
It is a faster type of memory used in computers while CPU is processing. So contents of memory is first fetched in this memory so that future requests can be served faster. - What is its difference with other memories? Why don't we use RAM as its faster too.
Cache is much faster than RAM and its is used to make the process fast. It is much costly than other memories. RAM is primary memory and different from RAM. - What are Registers in Embedded systems?
Registers are type of memory that is used to hold the contents that are going to use in processor. They may hold instructions, variables and things like that.So if CPU wanted to add two numbers, instructions will be first loaded into registers and then given to CPU. - How many registers are there in ARM Cortex M3?
It has 12 general purpose registers out of which 6 are called low level and other 6 are called high level. Than 4 Control registers PC, LR, SP and . Then two Special purpose registers like Program status register. - Suppose we have a 32 bit register whose first and second bit are used to on and off UART. So if bit 8 is 1,Tx channel is on and if 10 bit is 1, Rx is on. How will you do it?
By and ORing that with a number. So to set bit 8, we will and that register as follows.
UART_Reg |=h0000100; // for 8th bit
UART_Reg |=h0000400; // for 10th bit - How can you do in same instruction?
UART_Reg |=h0000500; // for 8th and 10 bit - Suppose we have a 32 bit register showing status of a 32 interrupts of 32 ADC channels. Now Suppose a battery is connected at an xth channel. Write a efficient C program that can detect channel Number and return it.
- int ChannelFinder(int INT_Reg)
- {
- int ch_No,i,temp;
- temp=INT_Reg;
- for(i=0;i<=31;i++)
- {
- temp>>i;
- if(temp==1)
- {
- ch_No=i;
- break;
- }
- }
- return ch_No;
- }
- Now suppose that more than on interrupts are occurring . Also in the if condition call another routine that will call ISR with Ch_No. Calling this routine will also clear previous Interrupt.
- int ChannelFinder(int INT_Reg)
- {
- int ch_No,i,temp;
- temp=INT_Reg;
- for(i=0;i<=31;i++)
- {
- temp>>i;
- temp |=1;
- if(temp==1)
- {
- ch_No=i;
- ISR_funct(ch_No);
- break;
- }
- }
- }
9. This program is checking for interrupt even if there is no interrupt, change it in such a way that it only checks when there is some interrupt?
- int ChannelFinder(int INT_Reg)
- {
- int ch_No,i,temp;
- temp=INT_Reg;
- if(INT_Reg>=1)
- {
- for(i=0;i<=31;i++)
- {
- temp>>i;
- temp |=1;
- if(temp==1)
- {
- ch_No=i;
- ISR_funct(ch_No);
- break;
- }
- }
- }
- else
- break;
- }
10. See following program
const int x=9;
What will happen if i tried to change value of x?
It will give and error.
11. Now see this
int *p;
p=&x;
*p=10;
What will happen in this case?
Again same error.
12. What will be output of following?
- int *p;
- sizeof(p);
- double *p1;
- sizeof(p1);
13. If both have same sizes, why can't we use int type pointer for double type?
'cause a double type pointer is pointing a double and int type is pointing int. [Not sure]
14. How you configured timer in your project?
In data sheet of the controller, sequence to set bits of relevant register were given. There were some parameters like overflow value etc were to be set to start that timer.
That registers were set and it was configured.
15. How you used timer?
Timer was used to produce delays and also to sample data at regular intervals. So We used Sys Tick timer which is 24 bit timer. We used 80Mhz clock. It was count up timer. Each bit was count up after the delay of (1/80M)s so routine was made to produce of specific intervals.
16. What if you can't set value of a timer and you have to produce some specific interval?
Then we can set it Reload value. So every time overflow occurs, it will reload with a value relevant to our delay.
17. Following is a c Code
- struct A{
- int var1;
- int *p1;
- int *p2
- };
struct A a1[4]; [He was suspicious about this, he said it will be then struct of struct, I think he was confused with Cpp]
18. Now what will happen if i do following a1++?
[I was confused here, We had argument. He tried to convince me something may be he was trying to trap me. Unfortunately, I got into trap and I think answered wrong ]
It will be a compiler error.
19. What is pipeline in MCU's?
It is a concept that while one instruction is being loaded, other will also be loaded to save time. He asked another question but I said that I dont know deep about this so...
20. What is const int *p and int int const *p who will be constant in these?
It is a famous question in interviews of C. It can be found here.
http://stackoverflow.com/questions/1143262/what-is-the- difference-between-const-int-const-int- const-and-int-const
21. By what steps program is compiled? [He asked it differently but I don't remember exact words]
http://stackoverflow.com/questions/3996651/what-is-compiler-linker-loader
21. What is difference between big endian and little endian?
Both are ways of storing memory. In little endian, LSB is stored in smaller address place and MSB is placed in higher address places. Vice versa is true in other.
22. Suppose we have a system, a black box, we don't know anything about it. How can you know weather its big endian or little endian?
We can write a simple program as following
char var=1;
int c;
c=(int) var;
As we know int is a 4 byte and char is one byte. Now when type casted, c will have 4 bytes. So if it will be equal to 1 it means little endian other wise big endian.
23.What is interrupt and what happens when it occurs?
An interrupt is blockage in flow of main program. I told him whole process of interrupts what I have read in ARM with all the details.
24. So how NVIC know ISR address.
I told him that it IPSR register where interrupt number is loaded form NVIC. All the ISR's are stored in a memory address from 0 to top. So after this PC loads that specific interrupt. But he was not convinced.
25. Following is a program
- if( Unknown Condition )
- {
- printf("Hellow");
- }
- else
- printf("World");
We can write ~(printf("Hellow")). As return type of printf is number of bytes being printed. So what if condition will be false but print function will print Hellow and then it will go to else and will print World.
- if( ~(printf("Hellow")) )
- {
- printf("Hellow");
- }
- else
- printf("World");
26. Suppose data of an automotive is stored in location like following
Now suppose at location 0-3 car reg number is stored, on 4-9 something else is saved and so on and so far. Write a C program that takes starting bit, and size and extracts all of them and returns.
- int Extractor(int start, int size)
- {
- int i,cutter=0;
- int *adres;
- adress=start/32;
- for (i=start;i<=size;i=2*i)
- {
- cutter=cutter+i;
- }
- return ((*p)&cutter);
- }
[I was a bit wrong in this. I told him right algorithm but I was failed to produce right c code for cutter]
27. Suppose a MCU has only 12 registers while a C program is using 20 variables in it. All of them at once. How registers will manage it?
Register are only there to speed up the process of CPU by providing immediate data. In fact these variables are stored in memory. One other way is pushing and then poping when required in stack.
It was very interesting interview. I imagined it as two nerds discussing most nerdy things. We argued a lot of time during interview. Overall it was best experience.