Вы находитесь на странице: 1из 5

Subject: Microprocessor and Interfacing Experiment No.

08 DATE:

Title: To study Instructions for Stack and Subroutine

Rev. No.

1.00

AIM: - TO STUDY ABOUT STACK & SUBROUTINE PUSH RP : Store register pair (BC,DE,HL & PSW) on stack This is a 1-byte instruction It copies the contents of the specified register pair on the stack as described below. The stack pointer register is decremented, & the contents of high order register(e.g, register B) are copied in the location shown by the stack pointer register. The stack pointer register is again decremented, & the contents of the low- order register (e.g, register C) are copied in that location. POP RP : Retrieve register pair (BC,DE,HL & PSW) from stack This is a 1-byte instruction It copies the contents of the top two memory locations of the stack into the specified register pair. First, the contents of the memory location indicated by the stack pointer register are copied into the low-order register (e.g,register L), then the stack pointer register is incremented by 1. The contents of the next memory location are copied into the high order register e.g,register H), & the stack pointer register is again incremented by 1. NO. OF BYTES 3 DESCRIPTION The program sequence is transferred to the address specified by the operand. Before the transfer, the address of the next instructions to CALL ( the contents of the program counter) is pushed on the stack Subroutine is called if Carry = 1. Subroutine is called if Carry = 0. Subroutine is called if Sign = 0. Subroutine is called if Sign = 1. Subroutine is called if Parity = 1. Subroutine is called if Parity = 0. Subroutine is called if Zero = 1. Subroutine is called if Zero = 0. 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 & the program execution begins at the new address. The instruction is equivalent to POP program counter. Return to main program if Carry =1.
8.1

INSTRUCTION OPCODE OPERAND CALL 16-bit

CC CNC CP CM CPE CPO CZ CNZ RET

16-bit 16-bit 16-bit 16-bit 16-bit 16-bit 16-bit 16-bit

3 3 3 3 3 3 3 3 1

RC

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

RNC RP RM RPE RPO RZ

1 1 1 1 1 1

Return to main program if Carry =0. Return to main program if Sign = 0. Return to main program if Sign = 1. Return to main program if Parity = 1. Return to main program if Parity = 0. Return to main program if Zero =1. EXERCISE

1) Read the following program & answer the following questions given below. Line no. Mnemonics 1LXI SP,0400H 1 LXI SP,0400H 2 LXI B,2055H 3 LXI H,22FFH 4 LXI D,2090H 5 PUSH H 6 PUSH B 7 MOV A,L | | | | 20 a) b) c) d) POP H

What is stored in the stack pointer register after the execution of line 1? What is the memory location of the stack where the first data byte will be stored? What is stored in memory location 03FEH when line 5(PUSH H) is executed ? After the execution of line 6 (PUSH B), what is the address in the stack pointer register, & what is stored in stack memory location 03FDH ? e) Specify the contents of register pair HL after execution of line 20 (POP H). 2) Read the following program & answer the questions. 2000 LXI SP,2100H DELAY: 2064 PUSH H 2003 LXI B,0000H 2065 PUSH B 2006 PUSH B 2066 LXI B,80FFH 2007 POP PSW LOOP :2069 DCX B 2008 LXI H,200BH 206A MOV A,B 200B CALL 2064H 206B ORA C 200E OUT 01H 206C JNZ LOOP 2010 HLT 206F POP B 2070 RET a) What is the status of the flags & the contents of the accumulator after the execution of the POP instruction located at 2007H ? b) Specify the stack locations & their contents after the execution of the CALL instruction(not the CALL subroutine). c) What are the contents of the stack pointer register & the program counter after the execution of the CALL instruction?

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

8.2

d) Specify the memory location where the program returns after the subroutine. e) What is the ultimate fate of this program ? 3) Write a program to clear all the flags & prove that DCX instruction does not affect Zero flag but DCR instruction affects it.( Use PUSH-POP) 4) Between memory locations F0F0H & FOFFH, 8 set of 16-bit data are stored. In each set first byte represents the number & the second represents dividends (number by which we have to divide first byte). Do division for each set & store result (16-bit) in same memory location. (Quotient in first memory location & remainder in second). 5) Three numbers X1 ,X2 ,X3 are stored from FOFOH. Write an ALP to compute 3 i.Xi i =1 Store the result at memory locations FOF3H(lower byte) & FOF4H (higher byte). Use subroutine technique to find i.Xi .

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

8.3

GRADE

LAB-INCHARGE ANSWERS

H.O.D.

A-1.

(a) What is stored in the stack pointer register after execution of Line 1? Ans:- 0400H (b) What is the memory location of the stack where the first data byte will be stored? Ans:- 03FFH (c) What is stored in memory location 03FFH when line 5 (PUSH B) is executed? Ans:- FFH (d) After the execution of line 6 (PUSH B) what is the address in the stack pointer register & what is stored in stack memory location 03FDH? Ans:- 03FDH, 20H (e) Specify the contents of register pair HL after execution of line 20 (POP H). Ans:- 22FFH

A-2.

(a) What are the status of the flags & the contents of the accumulator after the execution of the POP instruction located ? ANS: - All flags are cleared, A =00H (b) Specify the stack locations & their contents after the execution of the CALL instruction (not the CALL subroutine). ANS: - 20FEH = 0EH , 20FFH = 20H (C) What are the contents of the stack pointer register & program counter after the execution of the CALL instruction. ANS :- SP = 20FEH , PC = 2064H (D) Specify the memory location where the program returns after the subroutine. ANS :- 2003H (E) What is the ultimate fate of this program? ANS :- Endless loop

A-3.

lxi SP, 2100h lxi B , 0000h push B pop psw hlt BACK1: mvi D, 10h lxi H, F0F0h mvi C, 00h mov B, M inx H
8.4

A-4.

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

BACK:

mov A, M sub B Inc C cmp E jnz BACK mov M, A dcx H mov M, C inx H inx H dcr D jnz BACK1 hlt lxi H, F0F2 mov E, M mov A, M call MUL3 dcx H mov E, M mov A, M call MUL2 dcx H mov A, M inx H add M inx H adc M mov A, M mvi A, 00h rlc A inx H mov M, A hlt

A-5.

MUL3: MUL2:

add E add E mov M, A ret

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT

8.5

Вам также может понравиться