Lvalue or location value is an address that is stored into while rvalue is the "read" value, ie., value of a constant or the value stored at a location. In the assignment
a = 31;
we have the lvalue of a used on the left hand side and the integer contant value 31 assigned to this location.
In the assignment
Q: What is interrupt nesting?
Pre-Emption of low priority Interrupt by another high priority interrupt is known as Interrupt nesting.
If a high priority interrupt pre-empts the lower priority interrupt, then the higher priority Interrupt context would be saved on the previous lower priority one. We now say the depth is two and nesting is two.
Q: How is nesting of interrupt handled ?
Most architectures have two stacks. Task and Interrupt stack. The size of interrupt stack is decided by the maximum depth of nesting. If an ISR gets interrupted, the interrupt stack saves the context of the first interrupt service routine. The context here is generally all the registers, PC and local variables. When the second ISR executes its return from interrupt instruction, it pops back to the first ISR, stack,registers and interrupt level. Now when this first ISR routine executes return from interrupt, then it may back to the task level, the stack is restored to the task stack and the registers and processor level go back to the normal task level.
Q: How to avoid nesting of interrupts?
Nesting of interrupts can be avoided by disabling the interrupt as soon as interrupt service routine is invoked.
In most architecture, interrupts are automatically disabled on invoking ISR.
Q:For a level triggered interrupt, if the interrupts are not disabled, will it result in repeated invoking of ISR?
Yes. If an interrupt is level triggered, then you need to reset the level
when the interrupt is serviced. IF you fail to reset the interrupt
request, the interrupt will recur when interrupts (at that level) are
re-enabled. Usually that would be when the ISR returns.
Q:How is signed negative numbers stored in memory?
Q: How is -1 represented in memory?
A:
In most intel architectures, signed negative numbers are stored in memory as two's Complement.
eg.
-1 will be stored as 11111111,
-2 as 11111110,
-3 as 11111101
Q: Which is the best way to write Loops?
Q: Is Count Down_to_Zero Loop better than Count_Up_Loops?
A: Always, count Down to Zero loops are better.
This is because,at loop termination, comparison to Zero can be optimized by complier. (Eg using SUBS)
Else, At the end of the loop there is ADD and CMP.
Q: What is loop unrolling?
A: Small loops can be unrolled for higher performance, with the disadvantage of increased
codesize. When a loop is unrolled, a loop counter needs to be updated less often and
fewer branches are executed. If the loop iterates only a few times, it can be fully unrolled,
so that the loop overhead completely disappears.
eg:
int countbit1(uint n)
{ int bits = 0;
while (n != 0)
{
if (n & 1) bits++;
n >>= 1;
}
return bits;
}
int countbit2(uint n)
{ int bits = 0;
while (n != 0)
{
if (n & 1) bits++;
if (n & 2) bits++;
if (n & 4) bits++;
if (n & 8) bits++;
n >>= 4;
}
return bits;
}
Q: How does, taking the address of local variable result in unoptimized code?
A: The most powerful optimization for compliler is register allocation. That is it operates the variable from register, than memory. Generally local variables are allocated in registers. However if we take the address of a local variable, compiler will not allocate the variable to register.
Q: How does global variable result in unoptimized code?
A: For the same reason as above, compiler will never put the global variable into register. So its bad.