The bits of a 32-bit register at address 0x4B000020 are
connected to 32 proximity detectors – each bit will
be a ‘1’ if it’s corresponding detector is near a solid object. The
bits of a 32-bit register at 0x4B001020 are
connected to 32 LEDs, and writing a ‘1’ to any bit will turn on a
corresponding LED. Write a C function that
can be called to illuminate LEDs 7-0 whenever the corresponding
proximity detectors 7-0 are detecting an
object (that is, only illuminate and LED if a corresponding
detector is active). Do not change any other bits
in the LED register.
Answer :- The C function can be written as-
#define DETECTOR_ADDRESS 0x4B000020
#define LED_ADDRESS 0x4B001020
void led_control()
{
if (*DETECTOR_ADDRESS & 0x1)
*LED_ADDRESS |= 0x1; /* make LED 0 ON if detector 0 detects solid,
other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFFE; /* make LED 0 OFF if detector 0
does not detect any solid, other bits unaffected */
if (*DETECTOR_ADDRESS & 0x2)
*LED_ADDRESS |= 0x2; /* make LED 1 ON if detector 1 detects solid,
other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFFD; /* make LED 1 OFF if detector 1
does not detect any solid, other bits unaffected */
if (*DETECTOR_ADDRESS & 0x4)
*LED_ADDRESS |= 0x4; /* make LED 2 ON if detector 2 detects solid,
other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFFB; /* make LED 2 OFF if detector 2
does not detect any solid, other bits unaffected */
if (*DETECTOR_ADDRESS & 0x8)
*LED_ADDRESS |= 0x8; /* make LED 3 ON if detector 3 detects solid,
other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFF7; /* make LED 3 OFF if detector 3
does not detect any solid, other bits unaffected */
if (*DETECTOR_ADDRESS & 0x10)
*LED_ADDRESS |= 0x10; /* make LED 4 ON if detector 4 detects solid,
other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFEF; /* make LED 4 OFF if detector 4 does
not detect any solid, other bits unaffected */
if (*DETECTOR_ADDRESS & 0x20)
*LED_ADDRESS |= 0x20; /* make LED 5 ON if detector 5 detects solid,
other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFDF; /* make LED 5 OFF if detector 5
does not detect any solid, other bits unaffected */
if (*DETECTOR_ADDRESS & 0x40)
*LED_ADDRESS |= 0x40; /* make LED 6 ON if detector 6 detects solid,
other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFFBF; /* make LED 6 OFF if detector 6
does not detect any solid, other bits unaffected */
if (*DETECTOR_ADDRESS & 0x80)
*LED_ADDRESS |= 0x80; /* make LED 7 ON if detector 7 detects solid,
other LEDs unaffected */
else
*LED_ADDRESS &= 0xFFFFFF7F; /* make LED 7 OFF if detector 7
does not detect any solid, other bits unaffected */
} /* end of the function */
NOTE :- The function must be called in a loop.
The bits of a 32-bit register at address 0x4B000020 are connected to 32 proximity detectors – eac...
For a direct-mapped cache with a 32-bit address and 32-bit words, the following address bits are used to access the cache. TAG INDEX OFFSET 31-15 14-8 7-0 a. What is the cache block size (in words)? [13 points] b. How many blocks does the cache have? [12 points]