Professional Documents
Culture Documents
Act 5
Act 5
Bael 05/11/21
BSEE-III
Activity 5
1. What is stack? Explain the use of the stack, and stack pointer and how they are affected
by instruction such as PUSH, POP, CALL and RET.
Answer:
Stack is a memory usage model. It is simply part of the system memory, and a pointer
register (inside the processor) is used to make it work as a first-in/last-out buffer. The
common use of a stack is to save register contents before some data processing and then
restore those contents from the stack after the processing task is done.
When doing PUSH and POP operations, the pointer register, commonly called stack
pointer, is adjusted automatically to prevent next stack operations from corrupting
previous stacked data. More details on stack operations are provided on later part of this
chapter. It is not necessary to use both SPs. Simple applications can rely purely on the
MSP. The SPs are used for accessing stack memory processes such as PUSH and POP.
The CALL instruction preserves the current value of the instruction pointer, pushing it
onto the stack in order to support nested function calls, and then loads the instruction
pointer with the new address, provided as an operand to the instruction. This value on the
stack is referred to as the return address. Whenever the function has finished executing,
the RET instruction pops the return address off of the stack and restores it into the
instruction pointer, thus transferring control back to the function that initiated the
function call.
2. What is subroutine? How is it useful? Explain the use of stack in CALL and RETURN
instructions.
Answer:
–Rather than repeat the same instructions several times, they can be grouped into
a subroutine that is called from the different locations.
–Rather than repeat the same instructions several times, they can be grouped into
a subroutine that is called from the different locations.
–The RET instruction is used to return the execution to the calling routine.
Answer:
PUSH PSW
–Decrement SP
–Decrement SP
PUSH B requires 1-Byte, 3-Machine Cycles (Opcode Fetch, Memory Write, and Memory Write)
and 12 T-States for execution
Answer:
The CALL instruction interrupts the flow of a program by passing control to an internal
or external subroutine. An internal subroutine is part of the calling program. An external
subroutine is another program. The RETURN instruction returns control from a
subroutine back to the calling program and optionally returns a value. When calling an
internal subroutine, CALL passes control to a label specified after the CALL keyword.
When the subroutine ends with the RETURN instruction, the instructions following
CALL are processed.
5. If the CALL and RET instructions are not provided in the 8085A, could it possibly be
possible to write subroutines for this microprocessor? If so, how will you call and return
from the subroutine?
Answer:
If the condition associated with the conditional CALL is not met, the program counter
contents are saved on the stack, and the address contained in the CALL instruction is
loaded into program counter. Whenever the instructions in a subroutine are required to be
executed, we branch program control to the subroutine using th CALL instruction.
CALL is a 3-Byte instruction, with 1 Byte for the opcode, and 2 Bytes for the address of
the subroutine. CALL mnemonics stands for “call a subroutine”. After executing the
instructions written in the subroutine we shall want to return control to the next
instruction written after the CALL instruction then we shall use mnemonic RET.
Here RET stands for RETurn from the subroutine. RET is a 1-Byte instruction.
Answer:
Subroutine program must provide enough information so that other users can utilize the
subroutine without having to examine its internal structure. So along with subroutine
program it is necessary to give the following guidelines.
Answer:
When one subroutine calls another subroutine to complete a particular task, the
operations is called nesting. The second subroutine may in turn call a third subroutine and
so on each successive CALL without an intervening return creates an additional level of
nesting. These routines are called nested subroutines.
Answer:
In some situations it may happen that subroutine1 is called from main program,
subroutine2 is called from subroutine1 and subroutine1 is again called from subroutine2
in this situation program execution flow re-enters in the subroutine1. These types of
subroutines are called re-entrant subroutines.
Answer:
A recursive subroutine is a subroutine which calls itself. Recursive subroutines are used
to work with complex data structures called trees. If the subroutine is called with N
(recursion depth) = 3, then the N is decremented by 1 after each subroutine CALL and
the subroutine is called until N=0.