1. Write declaration statements (for Atmega2560 volatile data) for the following
ID: 3788030 • Letter: 1
Question
1. Write declaration statements (for Atmega2560 volatile data) for the following.
The variable pointed to by y_addr is an integer.
The variable pointed to by ch_addr is an unsigned character.
The variable pointed to by z is an integer.
date_pt is a pointer to an integer.
pt_chr is a pointer to an unsigned character.
2. For the following declarations,
int *x_pt, *y_addr;
long *dt_addr, *pt_addr;
double *pt_z;
int a;
long b;
double c;
Determine which of the following statements is valid.
a. y_addr = &a; b. y_addr = &b; c. y_addr = &c;
d. y_addr = a; e. y_addr = b; f. y_addr = c;
g. dt_addr = &a; h. dt_addr = &b; i. da_addr = &c;
j. dt_addr = a; k. dt_addr = b; l. dt_addr = c;
m. pt_z = &a; n. pt_addr = &b; o. pt_addr = &c;
p. pt_addr = a; q. pt_addr = b; r. pt_addr = c;
s. y_addr = x_pt; t. y_addr = dt_addr; u. y_addr = pt_addr;
3. If a variable is declared as a pointer, what must be stored in the variable?
4. if var2 is a variable, what does &var2 mean?
5. Using the sizeof ( ) operator, determine the number of bytes used by your PC to store the address of an integer, character, and double precision number. (Hint: sizeof (*int) can be used to determine the number of memory bytes used for a pointer to an integer.) Would you expect the size of each address to be the same? Why or why not?
6. Determine the results of the following operations:
11001010
& 10100101
11001010
| 10100101
dfda
11001010
^ 10100101
fdafd
7. Write the hexadecimal representations of all binary numbers in Question 6.
8. Determine the binary and hexadecimal results of the following operations, assuming unsigned numbers:
the hexadecimal number 0x0157, shifted left by one bit position
the hexadecimal number 0x0701, shifted left by two bit positions
the hexadecimal number 0x0673 shifted right by two bit positions
the hexadecimal number 0x0057 shifted right by three bit positions
9. a. Assume that the arbitrary bit pattern xxxxxxxx, where each x can represent either 1 or 0, is stored in the integer variable named f lag. Determine the hexadecimal value of a mask that can be ANDed with the bit pattern to reproduce the third and fourth bits of f lag and set all other bits to zero. The rightmost bit in f lag is considered bit 0.
b. Determine the hexadecimal value of a mask that can be inclusively ORed with the bit pattern in f1ag to reproduce the fifth and seventh bits of flag and set all other bits to one. Again, consider the rightmost bit of flag to be bit 0.
c. Determine the hexadecimal value of a mask that can be used to complement the values of the first and third bits of f1ag and leave all other bits unchanged. Determine the bit operation that should be used with the mask value to produce the desired result.
10. The BIOS (Basic Input Output Services) controls low level I/O on a computer. When a (PC) computer first starts up the system BIOS creates a data area starting at memory address 0x400 for its own use. Address 0x0417 is the Keyboard shift flags register, the bits of this byte have the following meanings:
This byte can be written as well as read. Thus we may change the status of the CapsLock, NumLock and ScrollLock LEDs on the keyboard by setting or clearing the relevant bit.
Write a C function using pointers and bit operators to turn Caps lock on without changing the other bits.
NOTE: Do NOT try to execute this on your PC unless you boot it to DOS in real mode.
11001010
& 10100101
11001010
| 10100101
dfda
11001010
^ 10100101
fdafd
Explanation / Answer
1. (a) The variable pointed to by y_addr is an integer.
volatile int a;
int *y_addr=&a;
(b) The variable pointed to by ch_addr is an unsigned character.
volatile unsigned char b;
unsigned char *ch_addr=&b;
(c) The variable pointed to by z is an integer.
volatile int c;
int *z=&c;
(d) date_pt is a pointer to an integer.
volatile int *date_pt;
*date_pt=5;
(e) pt_chr is a pointer to an unsigned character.
volatile unsigned char *pt_chr;
*pt_chr='a';
2. Following options are valid:
(a) y_addr = &a; -> int variable can be assigned to int type of pointer only. Since pointers assign the same memory space.
(h) dt_addr = &b; -> long variable can be assigned to long type of pointer only. Since pointers assign the same memory space.
(o) pt_addr = &c; -> double variable can be assigned to double type of pointer only. Since pointers assign the same memory space.
(s) y_addr = x_pt -> Same type of pointers take same memory space, so they can not be assigned to other type of pointers.
3. A pointer is a variable which stores memory location of another same type of variable.
For example:
int *x
Serial.print(x);
then this will give 0 as output
4. If var2 is a variable, then &var2 will be direct memory address/reference of the variable var2.
5. sizeof(*int), sizeof(*char), sizeof(*double)
They all are different. However, if we check the addresses they all will be equal because address will be saved in hexadecimal form, so it will be equal for all data types.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.