30
VISTEON SAMPLE PAPER www.ChetanaSinterview.com 1)here is the program for singly linked list using recursion… #include "alloc.h" #include "stdio.h" struct node { int data; struct node *link; }; void main() { int ch=1,d=0; struct node *head; void addnode(struct node**,int); void dispnode(struct node*); clrscr(); head=NULL; printf("do u want to add nodes!yes=1,no=0"); scanf("%d",&ch); while(ch!=0) { printf("\nenter data to be added"); scanf("%d",&d); addnode(&head,d); printf("\ndo u want to add nodes?(yes=1,no=0):"); scanf("%d",&ch); } dispnode(head); } void addnode(struct node **h,int data) { if (*h==NULL) { *h=(struct node*)malloc(sizeof(struct node)); (*h)->data=data; (*h)->link=NULL; } else { www.ChetanaSinterview.com

Visteon Paper

Embed Size (px)

Citation preview

Page 1: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

1)here is the program for singly linked list using recursion…

#include "alloc.h"#include "stdio.h"struct node{

int data;struct node *link;

};

void main(){

int ch=1,d=0; struct node *head; void addnode(struct node**,int); void dispnode(struct node*); clrscr(); head=NULL; printf("do u want to add nodes!yes=1,no=0"); scanf("%d",&ch);

while(ch!=0) {

printf("\nenter data to be added"); scanf("%d",&d); addnode(&head,d); printf("\ndo u want to add nodes?(yes=1,no=0):"); scanf("%d",&ch);

} dispnode(head);}

void addnode(struct node **h,int data){

if (*h==NULL) {

*h=(struct node*)malloc(sizeof(struct node)); (*h)->data=data; (*h)->link=NULL;

} else { addnode(&((*h)->link),data); }}

void dispnode(struct node *temp){

while ((temp)!=NULL) {

www.ChetanaSinterview.com

Page 2: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

printf("%d->",temp->data); temp=temp->link; }

}-------------------------------------------------------------------------------------------------------------------

1. factorial recursion prg- Here is the program. But I was asked the output of a factorial recursion program.

Main(){ unsigned long factorial(int); int n;unsigned long result; printf(“Enter the number”); scanf(“%d”, &n);result = factorial(n);printf(“factorial of the given number =%(format specifier for unsigned long???)”, result); }unsigned long factorial(int n){ if(n==1)return 1;elsereturn (n* factorial(n-1));

}=

-------------------------------------------------------------------------------------------------------------------

7. prg on a structure pointers. The program given to me was like this.

Declaration for a structure was given.Say typedef struct{int a; Char b;}test_struct;test_struct test;test_struct * test_ptr;but the program was given to print test_ptr.a which is not possible. It should be test.a or test_ptr->a;

***********************************************8. o/p of a c prg for char array & pointer.

www.ChetanaSinterview.com

Page 3: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

These questions were in the form of strings like some variable a[]= “buffers” print a[3] kinds .the answer is “f”One question was char a;a = ‘a’ +5. print a.Value of ‘a’ (note the small letter ‘a’) so the value would be ‘f’ – check this also!

***********************************************

C prog o/p for 2 dimentional array & pointer For this you can refer to any C book. The question pattern is like this. A[][3] = {0,1,2,3,4,5,6,7,9}, Print a[2]. Here we need to understand that mention of the row dimension is optional , but the column dimension needs to be mentioned.

A[][3] = { {0,1,2}, {3,4,5}, {6,7,9 }} a[2] = address of the second 1-d array.***********************************************

2. unsign a=10; signed int b= -20;a=a+b ; wht is the value in a?

You can attempt it this way!Add 1 to the number to be subtracted, which gives –19.Convert the two numbers to binary.A = 10 = 0000 0000 0000 1010.B = -19= 0000 0000 0001 0011One’c omplement of B = 1111 1111 1110 1100

Add this to A gives = 1111 1111 1111 0110 = FFF6 Ans***********************************************void main( ){

for( i=0; i<8; i++){

if(i==4)continue;if(i==5)break;++i;

}printf( "i = %d", i);

}

ANS I = 5Continue will go to start of the loop, break will come out of the loop

*****************************************************

www.ChetanaSinterview.com

Page 4: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

void main(){

for(y = 1;++y<8;)z+=y;

printf("z = %d",z);}

ANS 27*****************************************************

long factorial(int x){

return( x * factorial(x-1));}

gives the factorial of x*****************************************************func1( int a);void main(){

int a;a = 20;func1(a);printf("%d", a);

}funct1(int a){

a+=2;}

ANS a = 20 (Its call by Value)**************************************************This Paper is downloaded from www.ChetanaSinterview.com

void main(){

int count = 10 , *temp, sum = 0;temp = &count;*temp = 20; temp = &sum;*temp = count;printf(" count = %d, *temp = %d, sum = %d", count, *temp, sum);

}Ans 20 20 20 (changing using reference)***********************************************************

void my_func( int x){

if(x > 0)my_func(--x);printf("%d",x);

}

void main( ){

my_func(5);

www.ChetanaSinterview.com

Page 5: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

return1;}Ans : 001234 (Recursion, It prints from last value, since its – last value is from 0)*************************************************************

struct w{

unsigned char a;unsigned char b;unsigned int c;unsigned long d;

}

void main(){

unsigned int *ptr;struct w p = { 40, 30, 400, 40000};ptr = (unsigned int *)p; //wrongprintf("%d", p[1]); //wrong

}

Ans Invalid Indirection, struct can always be printed using its object. Invalid pointer conversion, struct can not be type casted to a normal unsigned int ptr**********************************************************

void main(){

char *ptr = "abcdefg";ptr + = (ptr+5);printf("%c",*ptr);

}

Ans : Invalid Pointer addition Ptr+5 is valid , but ptr+=ptr+anything is wrong*******************************************************

What is stack overflow? When a stack is not big enough and if data is still written into the associated memory, then this results in corruption of memory adjacent to the stack(usually memory prior to the actual stack memory, because most stacks grow to lower addresses).

The below method is useful in detecting this typr of out-of bounds stack growth. Before initialization, fill each thread’s stack with some data pattern like 0xfefe. After thorough application testing, each thread’s stack area may be examined to determine its maximum stack growth. The amount od stack used is calculated by finding the first intact data pattern from the beginning of the stack.Another method is to use RAM fault indicators. Find out how many are used in your project.

www.ChetanaSinterview.com

Page 6: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

Very Nice example –

The stack is a region of memory on which local automatic variables are created and function arguments are passed. The implementation allocates a default stack size per process. On modern operating systems, a typical stack has at least 1 megabyte, which is sufficient for most purposes. Under anomalous conditions, the program exceeds its stack limit. This causes a stack overflow. The two most common causes for a stack overflow is an infinite recursion, as in: int f(){ g();}int g() { f(); }f() calls g(), which in turn calls f() and so on. Eventually, the stack overflows. Another common cause for stack overflow is an attempt to create a large array on the stack, for example: int main(){ int n[10000000]; // array is too large int j =0; //j's address exceeds the stack's limits, error}If your program crashes due to a stack overflow, check for infinite recursion or too large local objects.

***********************************************- How to define Bitfields in C

A bitfield or a field rin short is a set of adjacent bits within a single implementation defined storage unit that we call a “word”. Bitfields have the following disadvantages: Increases the probable cost of increasing the instruction space and time needed to access the fields.Advantages: Bitfields reduce the storage cost of a structure.Disadvantages: Inceases the instruction space and time needed to access the fields.

struct {unsigned int is keyword : 1;unsigned int is_extern : 1;unsigned int is_static : 1;} flags;

Adjacent field members of structures are packed into implementation-dependent storage units in an implementation-dependent direction. When a field following another field will not fit into apartially-filled storage unit, it may be split between units, or the unit may be padded. An unnamed field with width 0 forces this padding, so that the next field will begin at the edge ofthe next allocation unit.***********************************************- definition for a function pointer

www.ChetanaSinterview.com

Page 7: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

A variable which can hold a pointer to a function. A simple function pointer declaration looks like this: Int (*pfi)(); This declares pfi as a pointer to a function which will return an int. The * indicated that a pointer is involved. The extra parenthesis around (*pfi) are required because without them the declaration would like int *pfi(); and this would declare a function returning a pointer to an int.. With the explicit parenthesis, however, int(*pfi)() tells us that pfi is a pointer first and that what it’s a pointer to is a function and what the function returns is an int.***********************************************- definition for a function pointer that takes a pointer as a inputint (*pfi)(int * x);

- O/p of a recursion prgProgram on #ifdef

***********************************************- O/p for a Program on "float" index for a switchFor a switch construct , it is not possible to use a float index.***********************************************What is meant by 16 and 32 bit processor?A 16 bit processor is one in which the data bus is 16 bits wide. A 32 bit processor is one in which the data bus is 32 bits wide. How about the size of the internal registers?***********************************************"Trace" in emulatorTrace is the history of executed code.This is a feature of emulator, which will show the entire path the program has taken till the breakpoint was reached. It wud show the data transferred, interrupt that occurred etc. which is very useful for debugging.

***********************************************Difference b/w STATIC, Volatile, Auto, Register Static: A variable declared static within the body of a function maintains its value betweenfunction invocationsA variable declared static within a module, (but outside the body of a function) isaccessible by all functions within that module. It is not accessible by functions within anyother module. That is, it is a localized globalFunctions declared static within a module may only be called by other functions withinthat module. That is, the scope of the function is localized to the module within which itis declaredThis Paper is downloaded from www.ChetanaSinterview.com

www.ChetanaSinterview.com

Page 8: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

Volatile:A volatile variable is one that can change unexpectedly. Consequently, the compiler can make no assumptions about the value of the variable. In particular, the optimizer must be careful to reload the variable every time it is used instead of holding a copy in a register.Examples of volatile variables are: Hardware registers in peripherals (for example, status registers)Non-automatic variables referenced within an interrupt service routineVariables shared by multiple tasks in a multi-threaded application

Auto: A variable declared as Auto is used within the function body.

register: A register declaration is equivalent to auto which is used only within functions. But register declaration hints that the declared objects will be accessed frequently. The idea Is that register variables are to be placed in machine registers which may result in smaller and faster programs.The register declaration looks likeregister int x;register char c;Only a few variables in each function may be kept in registers, and only certaintypes are allowed. Excess register declarations are harmless, however, since the wordregister is ignored for excess or disallowed declarations.

If a variable is declared as register, the & operator cannot be used.***********************************************max value for a short int-16 bit

***********************************************Explain Watchdog –the Watchdog Timer helps the system recover when there is a problem. The Watchdog Timer works by resetting the system when there is a time-out. The microcontroller continually resets the timer, as part of the software loop, before the timer times-out. If there is ever a software problem, such as an infinite loop or an operation that waits for a peripheral device, the Watchdog timer expires and resets the microcontroller.watchdog is implemented to prevent the processor from getting in to a undefined state.watchdog is toggled(acknowledged/ writing keys) peroidically before the watchdog timeout. In the normal operation this will be done. If this toggling doesn't happen with in the timeout period , watchdog will reset.***********************************************Rotate operators in C Answer – NO***********************************************tools to convert source file to exeComplier, linker, assembler***********************************************Difference b/w STOP and WAIT instruction

www.ChetanaSinterview.com

Page 9: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

STOP instruction is used to enter into the low power mode called “stop” mode or “pseudo stop” mode. Executing the STOP instruction stops all clocks and the oscillator thus putting the chip in fully static mode. Wake up from this mode can be done via reset or via external interrupts.

WAIT instruction is used to enter the low power mode called “wait” mode. In this mode CPU will not execute instructions. The internal CPU signals (address and data bus) will be fully static. All peripherals stay active. Further, the peripherals can individually turn off their local clocks.___________________________________________________Both are low power modes in a micro controller –

Wait ModeIn wait mode the CPU’s clock is stopped but the peripheral clocks are enabled. Thismeans that peripherals draw current but the CPU draws very little current. Because theperipherals are running they can ‘wake’ the CPU up. All peripherals stay active. Further, the peripherals can individually turn off their local clocks.

The wait mode is entered by using the “WAIT” instruction.In wait mode the major peripherals have the following status:

IRQ: This pin may wake the CPU up by causing an interrupt

ADC: This may be either enabled o disabled. Bear in mind that the ADCconsumes considerable power because it has a 1MHz clock running a fair bit ofcircuitry. If the ADC is not used then set all the channel bits in ADSCR to high.This shuts the ADC down so that it does not waste power. If the ADC is beingused then it will wake the CPU up when it causes an interrupt.

TIMER: The timer also consumes considerable power because of its big counterthat must be clocked. If the timer is not needed then the TSTOP bit in the timershould be set to stop the timer. This will save power. If the timer is used then anytimer interrupt will cause the CPU to wake up.

These features allow the processor to wake up only when needed. This could mean thatthe processor only wakes up when the user presses a button, it could mean that theprocessor only wakes up when the ADC has obtained a sample or it could mean that theprocessor only wakes up at periodic intervals to do some time-related task.

Stop ModeIf the wait mode consumes too much power for your purpose then you can use the stopmode. This mode causes the external crystal oscillator to shut down, causing the CPUas well as the peripherals to lose their clocks. This is a much lower power mode thanwait. Practically the only power that is consumed is leakage current. Since the system ispowered down to a lower level than wait mode there are fewer wake up options. Thestop mode can be entered by using the “STOP” instruction. The status of the majorperipherals in stop mode is as follows:IRQ pin: This peripheral does not need a clock to function. This means that thepin can cause a stop mode wakeup.

www.ChetanaSinterview.com

Page 10: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

ADC: No wake up is possibleTimer Module: No wake up is possible.When using low power modes bear in mind that the processor is not the only thing in thecircuit that consumes power. Check that no port pins are sourcing or sinking currentunnecessarily. Also check that all input port pins are held either high or low. This is ofparticular importance when using port pins for ADC input. If the pin is held out of thenormal high/low level then that pin will draw considerable current, usually more than therest of the processor put together.

***********************************************while loop with continue programThis results in an infinite loop.***********************************************Advantages of Design before codingROPE1)reusuability2)optimization3)portability4) Easy to debug5)interfaces shd be clearly defined***********************************************How to chose a MicroThe following factors need to be considered before choosing a micro:ClockMemory capabilities.Peripherals supported.CostAvailabilityAvailability of flashing/programming tools.***********************************************Arithmetic shift and Logic shift differenceAs far as left shift is concerned, the results of arithmetic shift and logical shift are the same.(i.e) the MSB is lost and the LSB is filled with a 0For right shift operation, the sign bit also needs to be considered in order to obtain correct results for right shift operations which in turn is equivalent to division operation.In the case of arithmetic shift, the LSB is lost and the MSB is filled with the sign bit , either 0 or 1 as the case may be.In the case of logical shift, the LSB is lost and the MSB is filled with a 0.***********************************************is string comparison allowed in preprocessor – Answer NO***********************************************nested interruptsmaskable interrupts can be blocked using a masking instruction. This instruction can be used by an interrupt handler to prevent interrupt nesting.

"nested" interrupts (i.e.: interrupts which interrupt other interrupt programs).

www.ChetanaSinterview.com

Page 11: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

Whenever any prior operation is interrupted by an exception process such as an interrupt operation, there is a recursion jeopardy problem because the interrupt processing program will use the same registers and may change some of the values therein.The conventional solution to the problem is to save in a memory (also referred to as "stacking") the current values of some or all of the registers prior to beginning the processing of the interrupt and reading those saved values back into the registers from memory (also referred to as "unstacking") when interrupt processing is complete. This solution ids time consuming and requires relatively extensive software support. However, this solution is theoretically capable of handling an unlimited number of "nested" interrupts (i.e.: interrupts which interrupt other interrupt programs).

When multiple exceptions are valid at the same time (i.e. more than one exception occurs during execution of an instruction), they are handled by the core (after completing the execution of the current instruction) according to the following priority scheme.

Reset Data Abort FIQ IRQ Prefetch Abort Undefined Instruction, SWI

The Undefined Instruction and SWI cannot occur at the same time because they are both caused by an instruction entering the execution stage of the ARM instruction pipeline, so are mutually exclusive and thus they have the same priority. Please note the difference between prioritization of exceptions (when multiple exceptions are valid at the same time), and the actual exception handler code. Exception handlers are themselves liable to interruption by exceptions, and so you must be careful that your exception handlers do not cause further exceptions. If they do, then you must take steps to avoid infinite "exception loops" whereby the link register gets corrupted and points to the entry point of the exception handler, thus giving you no way back to your application code. The following describes each exception individually.ResetThis is the highest priority interrupt and will be taken whenever it is signalled. The reset handler should initialize the system, and so there is no need to worry about state preservation etc. When reset is entered, IRQ and FIQ are disabled, and should not be enabled until all interrupt sources have been initialized to avoid spurious interrupts. Reset is handled in Supervisor (SVC) mode. One of the very first things that a reset handler should do is to set up the stack pointers for all the other modes, in case of an exception occurring. Note that an exception is not likely to occur in the first few instructions of the reset handler, and indeed no code should be here to provoke such an event. It would be uncommon to have a SWI, an Undefined instruction, or a memory access occur when in the reset handler. It is reasonable to assume that your reset handler has been hand crafted to map on to your system exactly so as to avoid any exceptions taking place during the handling of reset. Data AbortThe Data Abort has a higher priority than FIQ so that if both occur simultaneously the Data Abort mode is entered first, before immediately processing the FIQ exception. When the FIQ handler returns, it will return to the Data abort vector to handle the data abort. A Data Abort exception disables IRQ, and so the data abort handler can not be interrupted by an IRQ unless IRQs have been specifically re-enabled. Again, it is unlikely that a SWI or an Undef instruction will be executed as part of your handler (though it is possible, and the ARM will enter the relevant mode and deal with that exception, before returning to the abort handler). If you have a prefetch abort, caused by a read error in your abort handler (e.g. the handler was placed in an area of memory that is not currently paged in by the memory controller), then the abort handler will be re-entered. Thus your abort handler should not cause further aborts.

www.ChetanaSinterview.com

Page 12: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

FIQWith the exception of Reset, this is the highest priority interrupt in terms of being handled. The FIQ exception will disable all IRQs and FIQs and the handler should be hand crafted to execute as quickly as possible. The same arguments as above apply to Aborts, SWIs etc interrupting the handler. Similarly, when an FIQ is detected, the ARM core automatically disables further FIQs and IRQs (the F and I bits in the CPSR are set for the duration of the FIQ handler). This means that an FIQ handler will not be interrupted by another FIQ or an IRQ, unless you specifically re-enable FIQ or IRQ. For IRQ and FIQ, the default behaviour of the ARM core is to avoid nested (reentrant) interrupts.IRQWhen an IRQ occurs, it will be dealt with provided an FIQ or data abort has not been raised at the same time. IRQs are disabled (and should only be re-enabled after this current source has been cleared*), and are dealt with in the usual manner. As above, the handler code execution is prone to exceptions as per any other code. *Please note that you must be very careful when re-enabling IRQs inside your IRQ handler. See ADS Developer Guide (3MB PDF),"Handling Processor Exceptions" chapter or SDT 2.50 User Guide (7MB PDF), section 9.5.2 for information. When an IRQ is detected, the ARM core automatically disables further IRQs (the I bit in the CPSR is set for the duration of the IRQ handler). This means that an IRQ handler will *not* be interrupted by another IRQ, unless you specifically re-enable IRQ. Prefetch AbortIf the instruction being executed was read in error, then it is flagged as causing a Prefetch Abort, but this exception is only taken if the instruction reaches the execution stage of the pipeline, and if none of the above exceptions have gone off at this point. IRQs will be disabled, but other exception sources are enabled, and can be taken during the exception handler if necessary. SWIIf the instruction has been fetched (and decoded) successfully, and none of the other exceptions have been flagged, and this instruction is a SWI instruction, then the ARM will enter SVC mode, and go into the SWI handler code. If the SWI calls another SWI, then the LR must be stacked away before the "child" SWI is branched to. This can be done in C code in SDT 2.50 by compiling with the -fz option. See section 9.4.3 of the SDT 2.50 User Guide (7MB PDF) for information. In ADS, -fz is the default behaviour. Undefined InstructionIf the instruction has been fetched (and decoded) successfully, and none of the other exceptions have been flagged, and this instruction is an undefined instruction, then the ARM will enter Undef mode, and go into the undefined instruction handler code. The undefined instruction handler will generally either offer the instruction to any co-processors in the system, or flag an error in the system if none are present. SWI and Undefined Instruction have the same level of priority, as they cannot occur at the same time. The instruction being executed cannot be both a SWI and an Undefined instruction

***********************************************diff bet #if and #ifdef

19.#if - / #ifdef A: preprocessor directive, Control statements to control preprocessing .it might be used for conditional inclusion of source/header files and conditional define values in preprocessing itself. Also#if - the operand would be an expression…(checking fr a condition)#ifdef – single operand checks if the operand was defined or not.

Different segments of a program may be compiled conditionally. Conditional compilation statements must observe the following sequence:

1. 1.      One of: #if or #ifdef or #ifndef.

www.ChetanaSinterview.com

Page 13: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

2. Any number of optional #elif lines. 3. One optional #else line. 4. One #endif line.

         #if integral-constant-expression

Is true if integral-constant-expression evaluates to non-zero.

If true, tokens following the #if line are included.

The integral-constant-expression following the #if is evaluated by following this sequence of steps:

1. 1.      Any preprocessing tokens in the expression are expanded. Any use of the #define operator evaluates to ``1'' or ``0'' if its operand is, respectively, defined, or not.

2. If any identifiers remain, they evaluate to ``0''. 3. The remaining integral constant expression is evaluated. The constant expression must be

made up of components that evaluate to an integral constant. In the context of a #if, the integral constant expression may not contain the sizeof operator, casts, or floating point constants.

The following table shows how various types of constant expressions following a #if would be evaluated. Assume that name is not defined.

------------------------------------------------ Constant expression Step 1 Step 2 Step 3 ------------------------------------------------ !defined(__STDC__) !1 !1 0 3||name 3||name 3||0 1 2 + name 2 + name 2 + 0 2

#ifdef identifier

Is true if identifier is currently defined by #define or by the -D option to the cc command line.

#ifndef identifier

Is true if identifier is not currently defined by #define (or has been undefined).

#elif constant-expression

Indicates alternate if-condition when all preceding if-conditions are false.

#else

Indicates alternate action when no preceding if or elif conditions are true. A comment may follow the else, but a token may not.

#endif

Terminates the current conditional. A comment may follow the endif but a token may not.

www.ChetanaSinterview.com

Page 14: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

3stack and its selection criteria

C++ offers programmers a choice of allocating objects on the heap or on the stack. Stack-based allocation is more efficient: allocation is cheaper, deallocation costs are truly zero, and the language provides assistance in demarcating object lifecycles, reducing the risk of forgetting to free the object. On the other hand, in C++, you need to be very careful when publishing or sharing references to stack-based objects because stack-based objects are automatically freed when the stack frame is unwound, leading to dangling pointers.

Another advantage of stack-based allocation is that it is far more cache-friendly. On modern processors, the cost of a cache miss is significant, so if the language and runtime can help your program achieve better data locality, performance will be improved. The top of the stack is almost always "hot" in the cache, whereas the top of the heap is almost always "cold" (because it has likely been a long time since that memory was used). As a result, allocating an object on the heap will likely entail more cache misses than allocating that object on the stack.

Worse, a cache miss when allocating an object on the heap has a particularly nasty memory interaction. When allocating memory from the heap, the contents of that memory are garbage -- whatever bits happen to be left over from the last time that memory was used. If you allocate a block of memory on the heap that is not already in the cache, execution will stall while the contents of that memory are brought into the cache. Then, you will immediately overwrite those values that you paid to bring into the cache with zeros or other initial values, resulting in a lot of wasted memory activity

76how do you initialize a microClock,registers,watchdog,stack,peripherals1.Initialise the stack pointer

2.Initialise stack |3.register initialisation4.periperal power up5. micro startup ( - disable interrupt , setting the watchdog, clocks, initialise the I/O Ports to default 6.enable interrupts7. start the watchdog task.

8dynamic allocationallocation of memory during run time. But in embedded systems dynamic memory allocation may result in memory fragmentation. Also while freeing the used space using free() generally problems are encountered.

Study Calloc and malloc

9#pragma

Preprocessing lines of the form

    #pragma pp-tokens

specify implementation-defined actions.

10#errorA preprocessing line consisting of:

www.ChetanaSinterview.com

Page 15: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

#error token-sequencecauses the compiler to produce a diagnostic message containing the token-sequence, and stop.

Example –

#if (offsetof(timer, DATA) != 4)} #error DATA must be at offset 4 in timer#endifUsing this approach, the compiler evaluates the condition at compile time—during preprocessing, actually. If the assertion fails (the #if condition is true), the preprocessor executes the #error directive, which displays a message containing the text in the directive and terminates the compilation. The exact form of the message varies from compiler to compiler, but you should expect to see something that looks like: timer.h, line 14: #error: DATA must be at offset 4 in timer -------------------------------------------------------------------------------------------------------------------11Testbit setbit clearbit and togglebit

- SETBIT, CLEARBIT, TESTBIT, TOGGLEBIT Macro definitions

- #define SETBIT(x,bitmask) (x|=bitmask),where bitmask is 2^n ,where n is the bit position which shd be set..

- #define CLEARBIT(x,bitmask) (x&=~bitmask)- #define TESTBIT(x,bitmask) (((x&bitmask)!=0)?1:0)- #define TOGGLEBIT(x,bitmask)(x^=bitmask)

-------------------------------------------------------------------------------------------------------------------15how do you build a C file

1) Compiling & code optimization2) Linking3) Create object code

Create a make file by - list all the .C files , specify the compiler option, assembler option & linker option , include the command linecommand to compile all the c files . include the linker command . Include the necessary include files , make sure all the necessary files are in the correct path . Go the path wherethe make file resides and give the command to build (complile and link).

-------------------------------------------------------------------------------------------------------------------contents of header files

- Typedefs,- Declarations of global variables.- Declartions of external function prototypes.- Macro definitions.

Multiple inclusion checks

-------------------------------------------------------------------------------------------------------------------how will u get the frequency of a square wave using the micro

www.ChetanaSinterview.com

Page 16: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

Since asked question is a square wave it is enough if we find the half of the time- period.So it wud be like this.

Configure an interrupt capable port pin as input port.Configure the interrupt for both rising and falling edges.Connect the square wave source to this input pin.Configure a timer as free-running…that is this timer should start running as soon as it is configured.In the ISR, capture the time of this timer in variable say a.During the next isr capture the time of this timer in variable say b.The difference between b and a wud give us the timeperiod/2. Therefore frequency = 2/( timeperiod/2).IF you configure the interrupt only for rising edge or falling edge you can do the same and the frequency wud be 1/timeperiod itself now.

-------------------------------------------------------------------------------------------------------------------ADC/DACThe question on ADC was If a 16 bit ADC can measure upto 48V what is the count value if the voltage is 14V.Since it is a 16 bit micro FFFF means 48 V.Therefore count for 14 V is (14 X (2^16))/48

-------------------------------------------------------------------------------------------------------------------unsigned/signed char

unsigned char – 0 to 255 signed char - -128 to +127-------------------------------------------------------------------------------------------------------------------

asynchronous/synchronous communicationAsyncronous- there is no synchronization between the transmitter and receiver as they operate on a different clock. So data transfer can happen intermittently. It is necessary to have a start bit and stop bit to transmit each byte.In synchronous communication both are clocked and so there is no need for any start or stop bits for each byte. The speed of asynchronous is less because of adding start & stop bits are added to each byte…

Synchronous communication relies on the presence of a clocking system at both ends of the transmission, and these clocks must be synchronized at the beginning of the session so that the timing of the transmission, not start- and stop-bit encapsulation, defines where data begins and ends.

Asynchronous communication is a continuous stream of data that uses a start bit to flag the beginning of a byte of information, and ends with a stop bit and sometimes a parity bit, used for error checking. This type of communication does not use a timing mechanism to control the flow of data or to interpret the start or end of discreet pieces of data

www.ChetanaSinterview.com

Page 17: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

_____________________________________________________________________Maskable/non-maskable/edge triggered/level triggered

Maskable- interrupts that can be disabledNonmaskable – interrupts cannot be disabled- eg.Reset interrupt.Edge triggered – interrupt is triggered when the input edge occurs either rising or falling

Level triggered – interrupt occurs in the level

Edge-triggered interrupts are identified by a simple and transient voltage changed on the interrupt lines as adapters request service from the device drivers. This method of signaling has several limitations. The programmable interrupt controller not only can miss this instantaneous voltage transition, but also often misinterpret noise on the lines as valid interrupts.

Level-triggered interrupts are marked by not only a transition, but also continuation of the new voltage until the adapter drops the signal on instructions from the device driver-------------------------------------------------------------------------------------------------------------------This Paper is downloaded from www.ChetanaSinterview.com

max value for a short int-16 bit 32767

32.One interrupt service routine was given and we are asked to comment on it.. I am attaching a html file where you can find answer for this and many others.

mechanism to avoid endless loop If there is ever a software problem such as an infinite loop or an operation that waits for a peripheral device, the watchdog timer expires and resets the microcontroller.

critical section A block of code that must be executed in sequence and without interruption to guarantee correct operation of the software.Race condition is a situation in which the outcome of a program may be affected by the exact order in which the instructions are executed. Race condition is only an issue where interrupts and pre-emption are possible and where critical sections exist.

www.ChetanaSinterview.com

Page 18: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

(In an environment ,where multiple processes share common resources,each process is given exclusive access to the resources,wherein only 1 process can access the resource.Also in our embedded software when we enter critical section we would disable the interrupts so that they don’t share control in that section of the code and we enable them while leaving this section.

-------------------------------------------------------------------------------------------------------------------26.tools to convert source file to exe –compiler,linker,assembler-------------------------------------------------------------------------------------------------------------------27."float" index for a switch –not possible-------------------------------------------------------------------------------------------------------------------28.while loop with continue program – a program in which continue statement was used. The condition to exit the loop would never be reached in that program so endless loop.-------------------------------------------------------------------------------------------------------------------29.what is the exe time for 4 clk cycles instruction with a clock freq of 4000000HZ1 clk cycle = 1/4000000therefore 4 clk cycles = 4/4000000 = 1micro second-------------------------------------------------------------------------------------------------------------------30.what is the use of declaring the variable as volatile-no optimization is carried out by the compiler-value of the variable can change without an explicit assignment operation,example register values.When ever a variable is going to be updated unexpectedly by some other process or interrupt , this keyword volatile should be used in its declaration and usage. e.g memory mapped periperal registers, global var modified by ISR-------------------------------------------------------------------------------------------------------------------31.diff bet #define and typedef in variable declarations#define UPTR1 unsigned char *typedef UPTR unsigned char *;

UPTR1 a,b; here only a is declared as pointer.UPTR c,d; here both c and d are declared as pointers-------------------------------------------------------------------------------------------------------------------

www.ChetanaSinterview.com

Page 19: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

19. There was another function with Recursion which results INFINITE loop.

22. Interrupt function - with parameter and a printf function

-------------------------------------------------------------------------------------------------------------------23. #define* dtp struct s typedef struct s * ttp

dtp p1, p2; ttp p3, p4

what is the difference?-------------------------------------------------------------------------------------------------------------------25. struct DB { int roll_num; char name[10]; }; void main (){

char buff[30]; struct DB Database; printf("Enter roll"); scanf("%d", database.roll_num);

printf("enter name") scanf("%s",buff); database.name = buff;}

Rewirte the above program correctly.

-------------------------------------------------------------------------------------------------------------------26. struct a { char a; char b; int c; long d; };

main (){ struct a = { 30,40,400,500000}; char *b; b= (char *)a; printf ("%c", b[3]);

www.ChetanaSinterview.com

Page 20: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

***********************************************

27. What is casting?

***********************************************28.

int matrix[5][5]; int count = 0;

int *ptr;

for (i=0;i<5;i++) for(j=0;j<5;j++) matrix[i][j]=count++;

ptr = matrix[1][1];

pritnf("%d", ptr[2]);

-------------------------------------------------------------------------------------------------------------------What is auxiliary carry flag?

-------------------------------------------------------------------------------------------------------------------This Paper is downloaded from www.ChetanaSinterview.com

1. What are the flags in 8086? - In 8086 Carry flag, Parity flag, Auxiliary carry flag, Zero flag, Overflow flag, Trace flag, Interrupt flag, Direction flag, and Sign flag.

2. What are the various interrupts in 8086? - Maskable interrupts, Non-Maskable interrupts. 3. What is meant by Maskable interrupts? - An interrupt that can be turned off by the programmer

is known as Maskable interrupt. 4. What is Non-Maskable interrupts? - An interrupt which can be never be turned off (ie.disabled)

is known as Non-Maskable interrupt. 5. Which interrupts are generally used for critical events? - Non-Maskable interrupts are used in

critical events. Such as Power failure, Emergency, Shut off etc., 6. Give examples for Maskable interrupts? - RST 7.5, RST6.5, RST5.5 are Maskable interrupts 7. Give example for Non-Maskable interrupts? - Trap is known as Non-Maskable interrupts,

which is used in emergency condition. 8. What is the Maximum clock frequency in 8086? - 5 Mhz is the Maximum clock frequency in

8086. 9. What are the various segment registers in 8086? - Code, Data, Stack, Extra Segment registers

in 8086. 10. Which Stack is used in 8086? - FIFO (First In First Out) stack is used in 8086.In this type of

Stack the first stored information is retrieved first. 11. What are the address lines for the software interrupts? -

www.ChetanaSinterview.com

Page 21: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

RST 0 0000 H

RST1 0008 H

RST2 0010 H

RST3 0018 H

RST4 0020 H

RST5 0028 H

RST6 0030 H

RST7 0038 H

12. What is SIM and RIM instructions? - SIM is Set Interrupt Mask. Used to mask the hardware interrupts. RIM is Read Interrupt Mask. Used to check whether the interrupt is Masked or not.

13. Which is the tool used to connect the user and the computer? - Interpreter is the tool used to connect the user and the tool.

14. What is the position of the Stack Pointer after the PUSH instruction? - The address line is 02 less than the earlier value.

15. What is the position of the Stack Pointer after the POP instruction? - The address line is 02 greater than the earlier value.

16. Logic calculations are done in which type of registers? - Accumulator is the register in which Arithmetic and Logic calculations are done.

17. What are the different functional units in 8086? - Bus Interface Unit and Execution unit, are the two different functional units in 8086.

18. Give examples for Micro controller? - Z80, Intel MSC51 &96, Motorola are the best examples of Microcontroller.

19. What is meant by cross-compiler? - A program runs on one machine and executes on another is called as cross-compiler.

20. What are the address lines for the hardware interrupts? -

RST 7.5003C H

RST 6.5 0034 H

RST 5.5 002C H

TRAP 0024 H

www.ChetanaSinterview.com

Page 22: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

21. Which Segment is used to store interrupt and subroutine return address registers? - Stack Segment in segment register is used to store interrupt and subroutine return address registers.

22. Which Flags can be set or reset by the programmer and also used to control the operation of the processor? - Trace Flag, Interrupt Flag, Direction Flag.

23. What does EU do? - Execution Unit receives program instruction codes and data from BIU, executes these instructions and store the result in general registers.

24. Which microprocessor accepts the program written for 8086 without any changes? - 8088 is that processor.

25. What is the difference between 8086 and 8088? - The BIU in 8088 is 8-bit data bus & 16- bit in 8086.Instruction queue is 4 byte long in 8088and 6 byte in 8086.

EDIC (Electronic Diagnosis Interface Computer)

This usually means the number of bits that can be processed at one time by each

instruction (e.g. 8-bit, 16-bit, 32-bit, etc...). Microcontrollers are almost always 8-

bit or maybe 16-bit devices.

Concentrate on these concepts . The questions may differ slightly….All the best!!!!

1. Order of power consumption for WAIT and STOP modes.2. What is key debounce.

Nested Interrupts?How to aviod it?

Difference between STOP and WAIT mode. How does the micro come out of these modes?

Stack overrun - cause and how to avoid it?

This Paper is downloaded from www.ChetanaSinterview.com- C prog o/p for 2 dimentional array & pointer-***********************************************- o/p of a c prg for char array & pointer-***********************************************- Correct a prg based on structure pointers.

***********************************************what is the use of declaring the variable as volatile

12watch dog

To count the no. of bits set in a byteStructure & union - pros & consShift operatorsBinary search algorithmInitializing the structure using system calls ;; copying to 2 structure var of same type

www.ChetanaSinterview.com

Page 23: Visteon Paper

VISTEON SAMPLE PAPER www.ChetanaSinterview.com

Library filesCompilers, Assemblers & Linkers

Multiplexer/DemultipexerPnp & npn transistors

www.ChetanaSinterview.com