Question

When a hardware value might change due to external circumstances or a value might change due...

When a hardware value might change due to external circumstances or a value might change due to an interrupt, what type modifier do you attach to the variable that might change?

C

Embedded Systems

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: Embedded Systems modifier can be used.

Explanation: As in Embedded Systems, there is a Volatile modifier in which the declaration is done outside a function block which can be use as a warning to the compiler that if there is any change in the event then the value assigned can be changed. The change in the hardware can also change the value.

For example:

We will be implementing two different codes, one by using "volatile" keyword and another without using it.

CODE No. 1:

#include<stdio.h>

int a = 1;

int main()

{

if (a == 1) //always true

  {

print{" a = 1 \n");

}

else        // a will never be other than 1
{
printf(" a != 1 \n");
}
   return 0;
}

In the above code, there is no any "volatile" keyword used. Therefore, the else part can be optimized as there is no use of the else part. The value of variable "a" can never change in the above code, therefore, there is no meaning in using the else part.

Let us see a code by using "volatile" keyword and try to optimize the code.

CODE No. 2:

#include<stdio.h>

volatile int a;    /* volatile Keyword*/

int main()
{
  
a = 2;
  
   if (a == 2)
   {
   printf(" a = 2 \n");
   }
   else       // possibility of change in the value of variable "a" due to volatile.   
   {  
   printf(" a != 2 \n");
   }
  
   return 0;
}

In the above code, "volatile" keyword is used. This makes the variable "a" changeable. when the value of "a" is 2, then the else part is not implemented but when the value of "a" changes, the else art comes in implementation. Therefore, if there will be a change due to external circumstances or due to an interrupt then the value of the variable can be changed.

Add a comment
Know the answer?
Add Answer to:
When a hardware value might change due to external circumstances or a value might change due...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Some metals can change their structure due to some circumstances like external stresses or heat treatments. In this question, we evaluate the change in metals volume due to a change in their struc...

    2. Some metals can change their structure due to some circumstances like external stresses or heat treatments. In this question, we evaluate the change in metals volume due to a change in their structure. This question can lead you to how you should design a part which is going to be subjected to heat treatments. a. Suppose that Lead can exist in both FCC and BCC forms. Given an atomic radius of R for Lead, how much is the volumetric...

  • 1. How do you change the clock source for the AT9oUSB1287? i.e., how would you change from an ext...

    1. How do you change the clock source for the AT9oUSB1287? i.e., how would you change from an external crystal to the internal RC oscillator? (1 Mark) 2. What is the difference between an MCU and an MPU? (1 Mark) 3. The Stack is stored in Data Memory. Describe what the stack does, and how it is used when an interrupt is called. (2 Marks) 1. How do you change the clock source for the AT9oUSB1287? i.e., how would you...

  • connected? How might climate change this connection! Horseshoe Crabs and the Red Knot, a type of...

    connected? How might climate change this connection! Horseshoe Crabs and the Red Knot, a type of shore bird, ecologically 3. ARACHNIDS INSTRUCTIONS: Observe scorpion and spider specimen from our collection a. What external features make scorpions appear so menacing? Should you be scared? b. Which are larger, a scorpion's pedipalps or cheliceratae? c. What is the shape of a spider's cheliceratae? Sketch it here. d. What evidence is there of body segmentation in the spider? Draw and name the two...

  • QUESTION 22 When you want a method to be able to change the value of a...

    QUESTION 22 When you want a method to be able to change the value of a variable that is passed to it as an argument, the variable must be ________. passed by value passed by reference a variable parameter a value parameter QUESTION 23 Not only may the counter variable of a  for loop be initialized in the initialization expression, but it may also be declared there. True False QUESTION 26 You have to write the data type for each parameter...

  • ( 3 pts. / 1 pt. each) Select the most appropriate communications hardware peripheral for each...

    ( 3 pts. / 1 pt. each) Select the most appropriate communications hardware peripheral for each of the scenarios below. Mark “A”, “B” or “C” is each of the boxes below. A. I2C B. SPI C. UART ANSWER: Two microcontrollers communicating with each other without a shared clock signal. Microcontroller communicating synchronously with several low-end peripheral devices. Two microcontrollers communicating synchronously with other and several intelligent peripheral devices; when each microcontroller is master, it controls the clock signal. ( 7...

  • Write no fewer than 200 words per question (800) total. This assignment is due no later...

    Write no fewer than 200 words per question (800) total. This assignment is due no later than 11:59 pm on Sunday, October 6. Late assignments will not be accepted. Type or paste question here B. In what circumstances is it ok to interrupt the daily lives of citizens or impose a burden (and ‘burden’ here can be interpreted in many ways) on ordinary people in order to produce a positive effect for the greater good. Thoroughly describe a specific example...

  • 1) When might a large-value funds transfer not be immediate? a. When it is a cross-border...

    1) When might a large-value funds transfer not be immediate? a. When it is a cross-border payment b. When the system has provisions for the payor to retract the funds c. When it is a net settlement system d. This type of system is always immediate by definition

  • Assume the same information as in assignment one. Argue why (a) replacement value might be the...

    Assume the same information as in assignment one. Argue why (a) replacement value might be the correct value to use in the financial statements, (b) why the DCF value might be the correct value to use in the financial statements, (c) why the book value might be the correct value to use in the financial statements, (d) why fair market value might be the correct value to use in the financial statements, and (e) under what circumstances would management prefer...

  • 3. Under what circumstances can internally generated goodwill be recognized? a. When the market value of...

    3. Under what circumstances can internally generated goodwill be recognized? a. When the market value of an entity exceeds b. The brand of an entity is well-respected c. The goodwill results from a contractural right d. The goodwill will result in future economic benefits e. Internally generated goodwill cannot be recognized 4. Which of the following statements is true regarding the revaluation method? a. Revaluations are always recognized in profit and loss b. Upward revaluations can never be recognized in...

  • When and under what conditions might managers change from a functional to (a) a product structure...

    When and under what conditions might managers change from a functional to (a) a product structure (b) a geographic structure (C) a market structure Be specific and identify one product or service where each applies. Present to the class.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT