Machine-translated by Google. Questions are authored in English.
Top

Embedded C Programming Questions and Answers

Answer: C

One structure placed at the peripheral's base address gives every register a name and the compiler computes the offsets, which is far less error-prone than a list of address macros. The volatile qualifier on the members is what makes the accesses happen as written.

Please log in or register to report this question.

52.

A peripheral is described as follows. What does UART->DR = 'A'; do?

typedef struct {
    volatile uint32_t SR;
    volatile uint32_t DR;
} uart_t;
#define UART ((uart_t *)0x40004400)

Answer: D

SR occupies the first four bytes and DR the next four, so the write lands at 0x40004404. Getting the member order or a reserved gap wrong is the commonest fault in a hand-written register header, which is why vendors supply them.

Please log in or register to report this question.

Answer: A

Correct answer: keep the following members at their correct offsets

A peripheral’s registers sit at fixed addresses, and gaps in the map must be represented or every member after the gap lands on the wrong register. A reserved field fills the gap so the structure’s offsets match the hardware exactly, which is the whole point of overlaying a structure on a peripheral.

Please log in or register to report this question.

Answer: B

The library routine is usually hand-optimised for the target and the compiler may inline it or recognise the pattern. Hand-written word loops assume alignment, and setting up DMA for two hundred bytes costs more than the copy.

Please log in or register to report this question.

Answer: C

Correct answer: both the assertion and the reason are true and the reason explains the assertion

Both are true and the reason gives the mechanism. Without volatile the compiler may assume a variable changes only where the code changes it, and so keep it in a register or delete a read entirely - which breaks any variable an interrupt or another thread can alter. What must be added is that volatile guarantees the access happens, not that it happens atomically.

Please log in or register to report this question.

Answer: D

Integer operations they may be, but the representation still rounds: a third has no exact Q15 form any more than it has an exact decimal one. What fixed point gives is a known and uniform resolution rather than exactness.

Please log in or register to report this question.

57.

Match the qualifier with what it does.

1. volatile   2. const   3. static at file scope

P. Restricts the name to one translation unit   Q. Forbids modification through this name   R. Forces every access to be performed

Answer: A

The three are the qualifiers an embedded programmer uses daily and each answers a different question: how the compiler may cache an access, whether the program may write through a name, and who can see the name at all.

Please log in or register to report this question.

58.

Match the section with what it holds.

1. .text   2. .data   3. .bss

P. Statics initialised to zero   Q. Instructions   R. Statics with non-zero initialisers

Answer: B

Reading the map file means knowing which is which: .text sizes the flash, .data costs both flash and RAM because its initial values must be stored and copied, and .bss costs RAM alone. Together they account for the whole image.

Please log in or register to report this question.

59.

Consider the following statements about volatile.

1. It forces the compiler to perform every access   2. It makes the access atomic   3. It is needed for a variable shared with a handler

Answer: C

The first and third are correct and together are why the qualifier exists. Atomicity is a property of the machine instruction and the preemption, and believing volatile supplies it is one of the most persistent errors in embedded C.

Please log in or register to report this question.

60.

Consider the following statements about integer arithmetic in C.

1. Unsigned overflow wraps   2. Signed overflow is undefined   3. Comparing signed with unsigned converts the signed operand

Answer: D

Correct answer: 1, 2 and 3 are all correct

All three hold. Unsigned arithmetic is defined to wrap modulo the type’s range; signed overflow is undefined behaviour, which optimisers are entitled to assume never occurs; and in a mixed comparison of equal rank the signed operand is converted to unsigned. The three together account for a great many subtle faults in embedded code.

Please log in or register to report this question.

Loading…
Tags: Embedded C Programming Questions and Answers || Embedded C Programming MCQ Questions and Answers || Embedded C Programming GK Questions and Answers || Embedded C Programming GK MCQ Questions || Embedded C Programming Multiple Choice Questions and Answers || Embedded C Programming GK || GK on Embedded C Programming || Embedded Systems Questions and Answers || Embedded Systems MCQ Questions and Answers || Embedded Systems GK Questions and Answers || GK on Embedded Systems