Some C programming. All Interrupt Service Routines with the exception of SysTick
ID: 3811050 • Letter: S
Question
Some C programming. All Interrupt Service Routines with the exception of SysTick_Handler must do this: i. Explicitly pop the SP before returning from the interrupt ii. Not use the Stack iii. Write to a FIFO iv Explicitly acknowledge the Interrupt v. Write to a mailbox vi. None of the above Write comments for even line of the following code and declare the variable's value: int x = 1, y = 2, x[10]; int *ip; ip = &x; y = *ip; *ip = 0; ip = &z;[2]; From the Valvano's book examples explain the meaning of the following statement: #define PF2 (*((volatile unsigned long *)0x40025010)) Write a subroutine that copies string s to string t (both are null-terminated) using pointer arithmetic.Explanation / Answer
part 2
2.1)
int x=1,y=2,z[10]; //declaration of 2 integer variables with definitions: x = 1 and y = 2
//declaration of 1 integer array containing 10 elements : z
int *lp; //declaration of integer pointer: lp i.e. lp will contain address of the integer variables
lp=&x;y=*lp;*lp=0; //lp contains address of variable x
//y takes the value at the address hold by lp, i.e. value of x. So, y = 1
//valye of the variable whose address is being hold by lp is 0 now. So, x = 0
lp=&z[2] //lp now holds the address of the 3rd variable z[2] in the array z
Final value of variables:
x = 0, y = 1
2.2)
#define PF2 (*((volatile unsigned long *) 0x40025010)
#define : it is used to create alias for an expression, so that whenever PF2(macros) will appear in the code, it will be replaced by
(*((volatile unsigned long *) 0x40025010)
PF2 : macros declared
unsigned long : means we are using a 2 or 4 byte sized memory location (1 byte = 8 bits)
unsigned long *: means we are pointing to a pointer which takes address of a unsigned long type variable, i.e. pointing to 2 or 4 byte location
((volatile unsigned long *) 0x40025010: the address we are goint to point is at 0x40025010 location, i.e. whenever PF2 will be found in the code,
it will point to the address 0x40025010.
*((volatile unsigned long *) 0x40025010: first * from the left signifies we want to manipulate the value in the address,
*(some_pointer) gives value at the address hold in the pointer.
volatile: volatile forces the compiler to issue a Load or Store anytime PF2 is accessed as the value may change without the compiler knowing it
2.3)
subroutine(function) to copy string s to string t using pointer arithmetic
char * copyStrings(char *s, char *t)
{
char *outputString = t
int i;
while(*s != '')
{
*t = *s;
s++;
t++;
}
*t = '';
return outputString;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.