👉Subroutine
👉Call instruction
👉Nested loop
✏️SUBROUTINE
📌In assembly language programming it is common to have one main program and many sub routines that are called from the main program.
📌The is allows to make separate module of program known as subroutine.
📌Each module can be tested separately and brought together in main program.
📌More importantly, in a large program the modules can be assigned to different programmers to shorten development time.
✏️CALL INSTRUCTIONS
👉LCALL (long call)
👉ACALL (absolute call)
📌LCALL (LONG CALL)
👉It is a 3 byte instruction.
👉The first byte is the opcode and second and third are used address of target subroutine.
👉This can be used to call subroutines located anywhere within the 64K-byte address space of 8051.
👉When a subroutine is called, control is transferred to that subroutine, processor saves the program counter and begins to fetch instructions from new location.
👉 After execution the subroutine, thee instruction RET (return) control back to the caller.
Syntax : LCALL LABEL
✏️ACALL (ABSOLUTE CALL)
👉ACALL is a 2-byte instruction.
👉Only 11 bits are used as address.
👉While the target address of ACALL must be within a 2K-byte range. In variation of the 8051, on-chip ROM is as low as 1K byte.
👉 In such cases, the use of ACALL instead of LCALL can save a number of bytes of ROM space.
Syntax : ACALL LABEL
✏️NESTED LOOPS
👉A loop within a loop, an inner loop within the outer one
👉The first pass of outer loop triggers the inner loop which executes to completion.
👉Then the second pass of outer loop of outer loop triggers inner loop again
👉This repeats till outer loop FINISHES.
📌SYNTAX
for (initialize counter; test condition; ++ or –)
{
for (initialize counter; test condition; ++ or --)
{
.// inner loop
}
.//outer loop
}