No. The program counter must be stored in a dedicated register. The stack is in working memory and you cannot operate on working memory; all values must be moved into a register in order to operate upon them. It makes no sense to move a program counter in and out of memory unless performing a context switch and you can't use a stack for context switching; a priority queue must be used for this. Keep in mind that the address of the top of the stack has to be moved in and out of its register during a context switch. It doesn't make sense to load the stack register from a priority queue before you can determine where the program counter value is. It's easier to keep all state information in the same place in the priority queue where it belongs.
No.
Both of them are pointers, but otherwise they are completely unrelated. The former points to the current position of the stack, the latter points to the current instruction of the program.
Because the stack pointer marks the top of the stack. If it is not initialised, it is not possible to determine where the next stack frame will go.
/** C Program to Check String is Palindrome using Stack.*/#include #include void push(char);char pop();char stack[100];int top = -1;void main(){char str[100];int i, count = 0, len;printf("Enter string to check it is palindrome or not : ");scanf("%s", str);len = strlen(str);for (i = 0; i < len; i++){push(str[i]);}for (i = 0; i < len; i++){if (str[i] == pop())count++;}if (count == len)printf("%s is a Palindrome string\n", str);elseprintf("%s is not a palindrome string\n", str);}/* Function to push character into stack */void push(char c){stack[++top] = c;}/* Function to pop the top character from stack */char pop(){return(stack[top--]);}
what ever you assume
Its main use is to store local variables, arguments and return address each time a function is called.When your program calls a function the following happen :- The function arguments are put on the stack- The current instruction pointer is put on the stack- The program jumps to the start of the function- Space is allocated on the stack to hold local variables- The function executes- The space holding local variables is de-allocated- The instruction pointer is restored and removed from the stack (we are now leaving the function and resuming the calling procedure)- The arguments are removed from the stack
The stack pointer keeps track of the top of the stack used by the current thread. The program counter keeps track of the next instruction in a program. Both are registers and both store a memory address.
Both of them are pointers, but otherwise they are completely unrelated. The former points to the current position of the stack, the latter points to the current instruction of the program.
A process contains a program counter, stack, heap, data section and text section.
The program counter (PC) and stack pointer (SP) registers are 16-bit registers in the 8085 and in the 8086/8088 because that is how Intel designed the processors.
The program counter (PC) and the stack pointer (SP).
The Program Counter and Stack Pointer registers are called special purpose registers because they can not be used arbitrarily; they are, well, special. You cannot, for instance, load a new value into the Program Counter and blithely continue, that action would cause an unconditional jump. Also, the Program Counter is automatically incremented by the size of the instruction, so you can not just put something in it and expect its value to persist. Similarly, you cannot load a new value into the Stack Pointer without losing the entire stack context that you are in.
The top of stack to copied to the specified register and the stack pointer is incremented by 2. A special form of POP, RET, has the program continuing with the popped address in the program counter, i.e. a return from subroutine or function call.
Because that's how Intel designed it. Even though the 8085 is an 8-bit computer, the program counter and stack pointer are 16 bits wide in order to support the address bus, which is also 16 bits wide. In the case of the 8086/8088, the program counter and stack pointer are still 16 bits wide, even though the address bus is 20 bits wide, because the 8086/8088 adds segmentation through the 16 bit segment register which is left shifted by 4.
Program Counter( PC)stores the 16-bit memory address of the next instruction to be fetched. Stack Pointer (SP)stores the address of a memory location which is used as a stack.
Its not a stack counter - its a stack pointer. The stack pointer is a register that points to the top of the stack. In the Intel configuration, it points to the next item to be popped off the stack. To push an item requires that the stack pointer be decremented first, and then the item is written. The inverse operation - the pop - requires read then increment.
when interrupt occurs, the program counter content will stores into stack, an PC will load interrupt address for next instruction execution. ofter completion ISR process PC will retrieves the stack values and execution will be continued.
A register can hold data, and it can be used for temporary storage or, in the case of an accumulator, it can participate in arithmetic or logical operations. A counter is a special case of a register. Usually, it can only be loaded, stored, or incremented, or used for the stack or as the program counter.