Wednesday, 5 December 2012

Worth Read #5

Bit manipulation 
Embedded systems always require the user to manipulate bits in registers or variables. Given an integer variable a, write two code fragments. The first should set bit 3 of a. The second should clear bit 3 of a. In both cases, the remaining bits should be unmodified. 
These are the three basic responses to this question: 
• No idea. The interviewee cannot have done any embedded systems work 
• Use bit fields. Bit fields are right up there with trigraphs as the most brain-dead portion of C. Bit fields are inherently non-portable across compilers, and as such guarantee that your code is not reusable.
• Use #defines and bit masks. This is a highly portable method and is the one that should be used. My optimal solution to this problem would be:

#define BIT3 (0x1 << 3)
static int a;
void set_bit3(void) {
a |= BIT3;
}
void clear_bit3(void) {
a &= ~BIT3;
}
Some people prefer to define a mask together with manifest constants for the set and clear values. This is also acceptable. The element that I'm looking for is the use of manifest constants, together with the |= and &= ~ constructs

this is very simple info I've given, but this simple question itself is sufficient for judging whether u r an embedded guy or not anta... so, think of it...

Enjoy...

Worth Read #4

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 0xaa55. 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;
Even if your taste runs more to the second solution, I suggest the first solution when you are in an interview situation.

Worth Read #3

Interrupts (MOST IMPORTANT)

Interrupts are an important part of embedded systems. Consequently, many compiler vendors offer an extension to standard C to support interrupts. Typically, this new keyword is __interrupt. The following code uses __interrupt to define an interrupt service routine (ISR). Comment on the code. 

__interrupt double compute_area (double radius)
{
double area = PI * radius *
radius;
printf("\nArea = %f", area);
return area;
}
This function has so much wrong with it, it's hard to know where to start:
• ISRs cannot return a value. If you don't understand this, you aren't hired
• ISRs cannot be passed parameters. See the first item for your employment prospects if you missed this
• On many processors/compilers, floating-point operations are not necessarily re-entrant. In some cases one needs to stack additional registers. In other cases, one simply cannot do floating point in an ISR. Furthermore, given that a general rule of thumb is that ISRs should be short and sweet, one wonders about the wisdom of doing floating-point math here
• In a vein similar to the third point, printf() often has problems with reentrancy and performance. If you missed points three and four, I wouldn't be too hard on you. Needless to say, if you got these last two points, your employment prospects are looking better and better

Worth Read #2

worth read:
Code example
What does the following code output and why? 

void foo(void)

{
unsigned int a = 6;
int b = -20;
(a+b > 6) ? puts("> 6") :
puts("<= 6");
}
This question tests whether you understand the integer promotion rules in C-an area that I find is very poorly understood by many developers. Anyway, the answer is that this outputs "> 6." The reason for this is that expressions involving signed and unsigned types have all operands promoted to unsigned types. Thus ý20 becomes a very large positive integer and the expression evaluates to greater than 6. This is a very important point in embedded systems where unsigned data types should be used frequently (see Reference 2). If you get this one wrong, you are perilously close to not getting the job.

Worth Read #1


Comment on the following code fragment. 

unsigned int zero = 0;
unsigned int compzero = 0xFFFF; 
/*1's complement of zero */
On machines where an int is not 16 bits, this will be incorrect. It should be coded:

unsigned int compzero = ~0;
This question really gets to whether the candidate understands the importance of word length on a computer. In my experience, good embedded programmers are critically aware of the underlying hardware and its limitations, whereas computer programmers tend to dismiss the hardware as a necessary annoyance.
By this stage, candidates are either completely demoralized-or they're on a roll and having a good time. If it's obvious that the candidate isn't very good, then the test is terminated at this point. However, if the candidate is doing well, then interviewer throw in these supplemental questions. These questions are hard, and interviewer expects that only the very best candidates will do well on them. In posing these questions, I'm looking more at the way the candidate tackles the problems, rather than the answers. Anyway, have fun...

enjoy...

Saturday, 16 June 2012

                                                                हम है राही प्यार के 
                                                                फिर मिलेंगे चलते चलते ।

Monday, 28 May 2012

childhood

बार बार आती है मुझको 
मधुर याद बचपन तेरी 
गया ले गया तू जीवन की 
सब से मस्त ख़ुशी मेरी