Figure 4.11 static long int lSecondsToday (void) { ..... ++ lSecondsToday; if (l
ID: 653972 • Letter: F
Question
Figure 4.11
static long int lSecondsToday (void)
{
.....
++ lSecondsToday;
if (lSecondsToday == 60 * 60 * 24)
lSecondsToday = OL;
.....
}
long lSecondsSinceMidnight (void)
{
return (lSecondsToday);
}
Question: Figure 4.11 has a shared data bug when the registers in the microprocessor are not as large as the data space needed to store a long integer. Suppose that long integers are 32 bits long and that your microprocessor has 16-bit registers. How far off can the result of lSecondsSinceMidight be? What if your microprocessor has 8 bit registers?
Thank you
Explanation / Answer
If figure 4.11 is using 16 bit-registers lSecondsSinceMidnight would be off by 65,536 seconds.
For the second one the difference would be 86,272 because an inturupt would occur between the setting of R1 and R2. It would retur 127 instead of 86399
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.