practical 8 call and subroutine
TRANSCRIPT
-
7/27/2019 Practical 8 Call and Subroutine
1/5
8.1
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.
INSTRUCTION
OPCODE
OPERAND
NO. OF
BYTES
DESCRIPTION
CALL 16-bit 3 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
CC 16-bit 3 Subroutine is called if Carry = 1.
CNC 16-bit 3 Subroutine is called if Carry = 0.
CP 16-bit 3 Subroutine is called if Sign = 0.CM 16-bit 3 Subroutine is called if Sign = 1.
CPE 16-bit 3 Subroutine is called if Parity = 1.
CPO 16-bit 3 Subroutine is called if Parity = 0.
CZ 16-bit 3 Subroutine is called if Zero = 1.
CNZ 16-bit 3 Subroutine is called if Zero = 0.
RET 1 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.
RC 1 Return to main program if Carry =1.
ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT
Subject:
Microprocessor and
Interfacing
Title:
To study Instructions for Stack and Subroutine
Experiment No.08DATE:
Rev. No.
1.00
-
7/27/2019 Practical 8 Call and Subroutine
2/5
8.2
RNC 1 Return to main program if Carry =0.
RP 1 Return to main program if Sign = 0.
RM 1 Return to main program if Sign = 1.
RPE 1 Return to main program if Parity = 1.
RPO 1 Return to main program if Parity = 0.
RZ 1 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,2090H5 PUSH H
6 PUSH B
7 MOV A,L
| |
| |
20 POP H
a) What is stored in the stack pointer register after the execution of line 1?
b) What is the memory location of the stack where the first data byte will be stored?
c) What is stored in memory location 03FEH when line 5(PUSH H) is executed ?
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 ?
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 B2008 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 theexecution of the CALL instruction?
ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT
-
7/27/2019 Practical 8 Call and Subroutine
3/5
8.3
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 firstbyte 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.Xii =1
Store the result at memory locations FOF3H(lower byte) & FOF4H (higher byte). Usesubroutine technique to find i.Xi .
ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT
-
7/27/2019 Practical 8 Call and Subroutine
4/5
8.4
GRADE LAB-INCHARGE H.O.D.
ANSWERS
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
A-4. mvi D, 10h
BACK1: lxi H, F0F0h
mvi C, 00h
mov B, Minx H
ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT
-
7/27/2019 Practical 8 Call and Subroutine
5/5
8.5
mov A, M
BACK: sub B
Inc C
cmp E
jnz BACK
mov M, A
dcx Hmov M, C
inx H
inx H
dcr D
jnz BACK1
hlt
A-5. lxi H, F0F2
mov E, M
mov A, M
call MUL3dcx H
mov E, M
mov A, M
call MUL2
dcx H
mov A, M
inx H
add M
inx H
adc M
mov A, Mmvi A, 00h
rlc A
inx H
mov M, A
hlt
MUL3: add E
MUL2: add E
mov M, A
ret
ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT