A) Why is this code not reentrant? On what line would an interrupt haveto occur to cause the bug to manifest? Please explain your answer
B) How could you fix it so that it is reentrant? Please explain your answer
Reentrant:
If an interrupt that pauses its execution and shifts control to another function.After complete the function then control is again transferred to the starting function and it returns the execution phase.
Reentrants are used in application like hardware interrupt handling,recursion.
Reentrant must satisfy the below conditions:
1)It may not use global and static data,because the interrupt may change certain global values and resuming the course of action.
2)It should not modify it's own code.
This is important because the course of action of the function should remain the same throughout the code.
3)Should not call another non-reenterant function.
Example:
int factorial(int i)
{
return i*5;
}
int mul(int i)
{
return factorial(i) *5;
}
Above example mul function is a reentrant because it interrupt it's execution and go to the factorial function complete the execution of factorial function and control come to the mul function and execute the instructions in that block.
So mul is a reenterant.
a) char temp;
void interrupt_handler(void)
{
char x1,x2;
x1=inb(0x120);
x2=inb(0x121);
acknowledge_interrupt();
temp=x1;
x1=x2;
x2=temp;
printf("Get and swapped x1=%d x2=%d \n",x1,x2);
}
Above program is not a reentrant because global variable is used in function void interrupt_handler(void) function.
Reenterant most follows above specified 2 conditions.
Interrupt well have occured in 5th line because the variable read from the i/o port.
Then control stop execution and go to the i/o port this called a interrupt.
And we find bug on the function opening brace.
b)
We declare temp variable in inside the function and we can fix it to reenterant.
And given above program there is no code in acknowldge_interrupt() funcion.
We don't whether acknowldge_interrupt() funcion reenterant or non-reenterant function if the function is non-reenterant then it fix to the reenterant function.
A) Why is this code not reentrant? On what line would an interrupt haveto occur to...
I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...