1. Read the program section and answer questions.
Int main (INT argc, char * argv [])
{
Int c = 9, D = 0;
C = C ++ % 5;
D = C;
Printf ("d = % d \ n", d );
Return 0;
}
A) Write Program output
B) Is this expression risky in a portable system? Why?
# Include "stdio. H"
Int A = 0;
Int B;
Static char C;
Int main (INT argc, char * argv [])
{
Char d = 4;
Static short E;
A ++;
B = 100;
C = (char) ++;
E = (++ d) ++;
Printf ("A = % d, B = % d, c = % D, D = % d, e = % d", a, B, c, d, e );
Return 0;
}
A) Write Program output
B) if the compiler arranges the layout of each variable (A, B, C, D) in the memory (eg. Stack, heap, data section, BSS section), it is best to use a Graphical description.
2. interruption is an important part of embedded systems, which leads to many compilation developers to provide an extension: To interrupt Standard C support, a New Keyword _ interrupt is generated. The following code uses the _ interrupt keyword to define an interrupt service subroutine (ISR). Please comment on the following code.
_ Interrupt double compute_area (double radius)
{
Double area = pI * radius;
Printf ("narea = % F", area );
Return area;
}
3 C/C ++ basic knowledge
A) What is the meaning of the keyword volatile during compilation? Three examples of different use cases are provided (which can be pseudo-code or text description ).
B) What are the specific functions of the static keyword in C language?
C) What is the difference between the following three variable declarations? Please give the specific meaning
Int const * P;
Int * const P;
Int const * const P;
4 embedded system problems
A) for integer variables A = 0x12345678, draw out how to store them in memory in the little endian and big endian modes.
B) In the arm system, which method does the Parameter Pass when a function is called?
C) What is the difference between an interrupt (interrupt, such as a keyboard interrupt) and an exception (exception, such as a division by zero exception?
5. Set the periodic tasks P1, P2, and P3 to T1, T2, and T3 to 100,150,400 respectively, and the execution time to 20, 40, and 100 respectively. Design a Scheduling Algorithm for task scheduling to meet the task execution cycle and task cycle.
6 priority reversal is a serious problem in embedded systems and must be paid enough attention.
A) First, please explain the priority reversal problem.
B) Many RTOS provide priority inheritance policies (Priority Inheritance) and priority ceiling policies (Priority ceilings) to solve the priority reversal problem. Please discuss these two policies. Reference answer: 1 5
There is a risk, because C = C ++ % 5; this expression has been modified twice for C, the behavior is undefined, and the value of C is undefined.
Int A = 0; // data section
Int B; // data section
Static char C; // BSS
Int main (INT argc, char * argv [])
{
Char d = 4; // Stack
Static short e; // bss a ++;
B = 100;
C = (char) ++;
E = (++ d) ++;
Printf ("A = % d, B = % d, c = % D, D = % d, e = % d", a, B, c, d, e );
Return 0;
} A = 2, B = 100, c = 2, D = 6, E = 5 2 a) ISR cannot return a value;
B) ISR cannot pass parameters;
C) floating points are generally not reentrant;
D) The printf function has re-entry and performance problems. 3 a) using the volatile keyword to define a variable is equivalent to telling the compiler that the value of this variable will change at any time. Every time you use it, you need to re-read its value from the memory, do not optimize it at will. We recommend that you use the volatile variable:
(1) Hardware registers of parallel Devices
(2) Non-automatic variables (global variables) that will be accessed in an interrupt service subroutine)
(3) variable B shared by several tasks in a multithreaded application) in the function body, a variable declared as static remains unchanged during the function call process.
In a module (but in the external body of a function), a variable declared as static can be accessed by the function used in the module, but cannot be accessed by other functions outside the module. It is a local global variable.
In a module, a function declared as static can only be called by other functions in this module. That is, this function is restricted to use within the local scope of the module that declares it.
What is the difference between static global variables and common global variables? STATIC global variables are only made once to prevent being referenced in other file units;
What is the difference between static local variables and common local variables: static local variables are initialized only once, and the next time is based on the previous result value;
What is the difference between a static function and a common function: a static function has only one copy in the memory, and a common function maintains one copy in each call. C) a pointer to a constant integer.
A constant pointer to an integer
A constant pointer pointing to a constant integer 4 a) 0x12345678
Little endian big endian is the opposite
High address --> 0x12 low address --> 0x12
0x34 0x34
0x56 0x56
Low address --> 0x78 high address --> 0x78
B) when the parameter is <= 4 ~ R3 transfer,> 4 pass through the pressure stack c) exception: synchronization with the processor's clock must be considered during generation. In practice, exceptions are also called synchronization interruptions. When the processor executes a wrong command due to a programming error, or a special situation (such as a page missing) occurs during execution, the processor will generate an exception when it must be processed by the kernel. Interruption refers to an electrical signal generated by external hardware. It enters from the interrupt pin of the CPU and interrupts the current operation of the CPU;
The so-called exception refers to some events that must be handled during software operation. The CPU automatically generates an event to interrupt the current operation and transfer the event to the exception handling process.
Difference between asynchronous and synchronous: '5 6 high-priority tasks need to wait for low-priority tasks to release resources, while low-priority tasks are waiting for medium-priority tasks. This is called priority inversion.
Priority Inheritance: inherits the highest priority of an existing blocked task as its priority. The task exits from the critical section and resumes its initial priority.
Priority ceilings: Specifies the priority ceiling for semaphores that access critical resources.
The Priority Inheritance policy has little impact on the task execution process, because only when the fact that a high-priority task has been applied for a critical resource occupied by a low-priority task occurs, to raise the priority of a low-priority task.