Thursday, 12 September 2013

Free download study notes on what is a subroutine in a microprocessor 8085 and use of it?

Here i will discuss on what is a subroutine in a microprocessor 8085 and use of it? you can also download it by clicking download link at bellow.  As name suggest subroutine is a sub ordinate of main routine .Basically a subroutine is a group of instructions, written separately from the main program, which performs a function that is required repeatedly in the main program.
 Now question is why a subroutine is used in a program?

Look we know a subroutine is called more than once by the main program, So if we use a subroutines in a main program we can saves precious memory space. The more the number of times a subroutine is called by the main program, the more is the saving of memory space and also we can shorten the lines in program and we can easily avoided the risk of error.
So for calling a subroutine in program we use CALL instruction

Now it is better to know some Explanation on the CALL instruction.

CALL is a 3-byte unconditional instruction. By using the execution of CALL instruction, the main program branches to the starting address of the subroutine. See in bellow the format of CALL instruction it is looks like this.

CALL memory address (16-bit)

Now I give you example to make you understand the process of subroutine calling.

Let take an example, we start main program begins at the address from 4080 H by initializing the stack pointer at 621F H. Now let suppose we write our subroutine at 4000 H. Now when CALL 4400 is encountered at 4100 in the main program, the return address following the CALL is 4103. The program counter is stored with the first address of the subroutine i,e 4400 H.
Thus PC = 4400 and the stack contain the very next address of the Call instruction i,e 4103H. Please see the diagram bellow to understand easily. Now see another important thing that the upper byte of the return address i.e., 41 stored at 621E and the lower byte (i.e., 03) at the stack address 621D. So it means the address of Stack is auto decremented. Thus, the program now starts at the subroutine starting address 4400.

When the last subroutine instruction RET is encountered, the two contents at the memory locations 621D and 621E are popped out so that the PC (program counter) content now becomes 4103—which is the return address from the subroutine. Thus the program starts at 4103 in the main program and SP returns to 621F.

See the block diagram for Multiple calling subroutine.

For download this study note in pdf click on DOWNLOAD

No comments:

Post a Comment