Embedded C language Written test

Source: Internet
Author: User

1 Read the program section, answer the question
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 out the program output
b) is there a risk in this expression 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) ++a;
E= (++d) + +;
printf ("a=%d, b=%d, c=%d, d=%d, e=%d", a,b,c,d,e);
return 0;
}
A) write out the program output
b) If the compiler arranges the layout of each variable (A,B,C,D) in memory (eg. stack,heap,data section,bss section), it is best to graphically describe it. 2 interrupts are an important part of the embedded system, which has led to a number of compiler developers providing an extension: Let standard C support interrupts, resulting in a new keyword __interrupt. 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 *radius;
printf ("Narea =%f", area);
return area;
}3 Basic knowledge of C + +
A) What is the meaning of the keyword volatile at compile time? and give three examples of different usage scenarios (either pseudo-code or literal description).
b) What are the specific functions of the static keyword in c?
c) What is the difference between the following three types of variable declarations? Please give specific meanings
int const *P;
int* const P;
int const* const p;4 Embedded System related issues
A) for shaping variable a=0x12345678, draw out how memory is stored in little endian and big endian in the same way.
b) in the arm system, when the function is called, what is the argument passed?
c) What is the difference between an interrupt (interrupt, such as a keyboard interrupt) and an exception (exception, such as a 0 exception)?5 The periodicity of the periodic task P1,p2,p3 is T1,T2,T3 100,150,400 respectively, and the execution time is 20, 40,100 respectively. Please design a scheduling algorithm for task scheduling, to meet the task execution cycle and task cycle. 6 Priority reversal problem is a serious problem in embedded system, which must be given enough attention.
A) First please explain the priority reversal problem
b) Many RTOs provide priority inheritance policy (inheritance) and priority ceiling policy (ceilings) to address the priority reversal problem, please discuss both of these strategies.

Reference Answer:
1 5
There is a risk, because c=c++%5; This expression has two modifications to C, the behavior is undefined, and the value of C is indeterminate
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) ++a;
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) The ISR cannot return a value;
b) The ISR cannot pass parameters;
c) Floating point is generally non-reentrant;
d) The printf function has re-entry and performance problems.

3 a) Define a variable with the volatile keyword, which is equivalent to telling the compiler that the value of the variable will change at any time and that it needs to be in memory each time it is used
Re-read its value, and do not arbitrarily optimize it for it.
Places to use volatile variables are recommended:
(1) Hardware registers for parallel devices
(2) Non-automatic variables (global variables) that are accessed in an interrupt service subroutine
(3) Variables shared by several tasks in multi-threaded applications
b) in the function body, a variable declared as static maintains its value in the process of the function being called.
Within the module (but outside the function body), a variable declared as static can be accessed by a function within the module, but not by other functions outside the module
Access. It is a local global variable.
Within the module, a function declared as static can only be called by other functions within this module. That is, this function is limited to declaring its
Used within the local scope of the module.
What is the difference between a static global variable and a normal global variable: the static global variable is only initialized once, preventing it from being referenced in other file units;
What is the difference between a static local variable and a normal local variable: the static local variable is initialized only once, the next time based on the last result value;
What is the difference between a static function and a normal function: The static function has only one copy in memory, and the normal function maintains a copy of each call
c) A pointer to a constant integer number
A constant pointer to an integral type number
A constant pointer to a constant integer number
4

A) 0x12345678
Little endian big endian just in turn
High address--〉0x12 low address--〉0x12
0x34 0x34
0x56 0x56
Low address--〉0x78 High address--〉0x78
b) When the parameter <=4, pass through the R0~R3, >4 pass through the pressure stack way
c) Exception: The clock synchronization with the processor must be considered when it is generated, and in practice, the exception is also known as a synchronous interrupt. The processor generates an exception when the processor performs a wrong instruction due to a programming error, or if a special case occurs during execution (such as a missing fault) that must be handled by the kernel.
The so-called interrupt should be the external hardware generated an electrical signal, from the interrupt pin of the CPU to enter, interrupt the current operation of the CPU;
The so-called exception, refers to the software run in some of the events that must be made to handle, the CPU automatically generates a sink to interrupt the current run, into the exception processing process.
The 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 a medium-priority task to be called priority reversal
Precedence inheritance policy (priority inheritance): inherits the highest priority of an existing blocked task as its priority, the task exits the critical section,
The initial priority of the complex.
Priority ceiling Policy (ceilings): a priority ceiling that controls the amount of semaphores that access critical resources.
The impact of the priority inheritance policy on the task execution process is relatively small, because only when a high-priority task requests a critical resource that has been occupied by a low-priority task
When this fact occurs, the priority of the low priority task is liftedhttp://www.cnblogs.com/lzjsky/archive/2011/01/15/1936399.html

Embedded C language Written test

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.