0% found this document useful (0 votes)
144 views33 pages

6 Stack and Subroutines

The document discusses stack and subroutines in microprocessor systems. It describes the PUSH, POP, CALL and RET instructions. PUSH decrements the stack pointer and copies register contents to memory. POP copies memory to registers and increments the stack pointer. CALL stores the return address on the stack and jumps to a subroutine. RET copies the stack address back to the program counter to return from the subroutine. Conditional CALLs and RETs also exist depending on flag settings.

Uploaded by

Rajat Bora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views33 pages

6 Stack and Subroutines

The document discusses stack and subroutines in microprocessor systems. It describes the PUSH, POP, CALL and RET instructions. PUSH decrements the stack pointer and copies register contents to memory. POP copies memory to registers and increments the stack pointer. CALL stores the return address on the stack and jumps to a subroutine. RET copies the stack address back to the program counter to return from the subroutine. Conditional CALLs and RETs also exist depending on flag settings.

Uploaded by

Rajat Bora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

MICROPROCESSOR SYSTEMS-1

STACK & SUBROUTINES


THE PUSH INSTRUCTION
• PUSH B
– Decrement SP
– Copy the contents of register B to the memory
location pointed to by SP
– Decrement SP
– Copy the contents of register C to the memory
location pointed to by SP
THE POP INSTRUCTION
• POP D
– Copy the contents of the memory location pointed
to by the SP to register E
– Increment SP
– Copy the contents of the memory location pointed
to by the SP to register D
– Increment SP
THE CALL INSTRUCTION

• CALL 2050H
– The program sequence is transferred to the
address specified by the operand. Before the
transfer, the address of the next instruction to
CALL(the contents of the program counter) is
pushed on the stack.
THE CALL INSTRUCTION
Mem Add Hexcode Mnemonics
2010 CD CALL2050H
2011 50
2012 20
The address in the program counter (2013H) is placed on
the stack as follows:
Stack pointer is decremented to 2098H
MSB is stored 2097 13
Stack pointer is again decremented 2098 20
SP 2099
LSB is stored
Call address (2050H) is temporarily stored in internal WZ
registers placed on the bus for fetch cycle.
CONDITIONAL CALLS
Instruction Code Description Condition for CALL

CC Call on carry CY=1

CNC Call on not carry CY=0

CP Call on positive S=0

CM Call on minus S=1

CPE Call on parity even P=1

CPO Call on parity odd P=0

CZ Call on zero Z=1

CNZ Call on not zero Z=0


THE RET INSTRUCTION
• The program sequence is transferred from the
subroutine to the calling program.
• The two bytes from the top of the stack are
copied into the program counter and program
execution begins at new address.
CONDITIONAL RETURN
CALL & RET PUSH & POP
When call is executed, the The programmer uses the instruction
microprocessor automatically stores the PUSH to save the contents of a register
16 bit address of the instruction next to pair on the stack.
the CALL on the stack.
When CALL is executed, the stack When PUSH is executed, the stack
pointer register is decremented by two. pointer register is decremented by two.
The instruction RET transfers the The instruction POP transfers the
contents of the top two locations of the contents of the top two locations of the
stack to the program counter. stack to the specified register pair.

When the instruction RET is executed, When the instruction POP is executed,
the stack pointer is incremented by two. the stack pointer is incremented by two.

In addition to the unconditional CALL There are no conditional PUSH and POP
and RET instructions, there are eight instructions.
conditional CALL and RETURN
instructions.
POP Rp
NEXT:
Interrupts

You might also like