Passing Parameters8086
Passing Parameters8086
Sivaprakash Prof,IT/CMREC
Dr.S.Sivaprakash Prof,IT/CMREC
•Describe how a stack is initialize and used in 8086 assembly language program which call procedures.
•Write, assemble, link and run a program which consists of more than one module.
• Accessing a procedure
Procedure :
A procedure is group of instructions that usually performs one task. It is a reusable section of a software program
which is stored in memory once but can be used as often as necessary.
A procedure can be of two types.
1) Near Procedure
2) Far Procedure
Near Procedure: A procedure is known as NEAR procedure if is written(defined) in the same code segment which is
calling that procedure.
Only Instruction Pointer(IP register) contents will be changed in NEAR procedure.
FAR procedure : A procedure is known as FAR procedure if it is written (defined) in the different code segment than the
calling segment.
In this case both Instruction Pointer(IP) and the Code Segment(CS) register content will be changed.
Dr.S.Sivaprakash Prof,IT/CMREC
ENDP Directive:
•This directive is used along with the name of the procedure to indicate the end of a procedure to the assembler.
•The PROC and ENDP directive are used to bracket a procedure.
Dr.S.Sivaprakash Prof,IT/CMREC
CALL instruction and RET instruction :
CALL instruction :
The CALL instruction is used to transfer execution to a procedure.
It performs two operation.
When it executes, first it stores the address of instruction after the CALL instruction on the stack.
Second it changes the content of IP register in case of Near call and changes the content of IP register and CS register in case
of FAR call.
There are two types of calls.
1)Near Call or Intra segment call.
2) Far call or Inter Segment call
Operation for Near Call : When 8086 executes a near CALL instruction, it decrements the stack pointer by 2 and copies
the IP register contents on to the stack.
Then it copies address of first instruction of called procedure.
SP SP-2
IP stores onto stack
IP starting address of a procedure.
Dr.S.Sivaprakash Prof,IT/CMREC
Re-entrant procedure :
In some situation, it may happen that procedure 1 is called from main program and procedure 2 is called from procedure
1.And again procedure 1 is called from procedure 2.
In this situation , program execution flow re-enters in the procedure 1 ( first time when procedure 1 was called from main
program and second time when procedure 1 was called from procedure 2) .
Hence this type of procedure is called as Reentrant procedure.
Dr.S.Sivaprakash Prof,IT/CMREC
produce the starting address of the procedure by adding a 16-bit signed displacement to the contents of the instruction pointer.
•INDIRECT WITHIN-SEGMENT NEAR CALL:
the instruction pointer is replaced with the 16-bit value stored in the register or memory location.
•THE DIRECT INTERSEGMENT FAR CALL:
Used when the called procedure is in different segment. The new value of the instruction pointer is written as bytes 2 and 3 of
the instruction code. The low byte of the new IP value is written before the high byte.
•THE INDIRECT INTERSEGMENT FAR CALL:
Replaces the instruction pointer and the contents of the segment register with the two 16-bit values from the memory.
Dr.S.Sivaprakash Prof,IT/CMREC
The PUSH register/memory instruction decrements the stack pointer by 2 and copies he contents of the
specified 16-bit register or memory location to memory at the new top-of-stack location.
The POP register/memory instruction copies the word on the top-of-stack to the specified 16-bit register or
memory location and increments the stack pointer by 2.
Dr.S.Sivaprakash Prof,IT/CMREC
Carefully workout the overall structure of the program and break it down into modules which can easily be
written as procedures.
Simulate each procedure with few instructions which simply pass test values to the mainline program. This
is called as dummy or stubs.
Check that number of PUSH and POP operations are same.
Use breakpoints before CALL, RET and start of the program or any key points in the program.
Dr.S.Sivaprakash Prof,IT/CMREC
Macro:
A MACRO can be defined anywhere in a program using the directives MACRO and ENDM. The label prior
to MACRO is the macro name which should be used in the actual program. The ENDM directive marks the end of the
instructions or statements sequence assigned with the macro name.
A MACRO is group of small instructions that usually performs one task. It is a reusable section of a software
program.A macro can be defined anywhere in a program using directive MACRO &ENDM.
Dr.S.Sivaprakash Prof,IT/CMREC
• A big advantage of using procedures is that the machine codes for the
group of instruction in the procedures needs to be loaded in to main
memory only once.
• Disadvantage using the procedures is the need for the stack.
• A macro is the group of instruction we bracket and give a name to at the
start of the program.
• Using macro avoids the overhead time involved in calling and returning
from a procedures.
• Disadvantage is that this will make the program take up more memory
than using a procedure.
Dr.S.Sivaprakash Prof,IT/CMREC
Dr.S.Sivaprakash Prof,IT/CMREC
The procedure of generating delays using a microprocessor based system can be stepwise described as follows:
1.Determine the exact required delay.
2. a) Select the instructions for delay loop. While selecting the instructions, care should be taken that the execution location
or register used by the main program must note be modified by the delay routine.
b) The instructions executed for the delay loop are dummy instructions in the sense that the result of those
instructions is useless but the time required for their execution is an elemental part of the required delay.
3. Find out the number of clock states required for execution of each of the selected delay loop instructions. Further find out
the number of clock states required (n) to execute the loop once by adding all the clock states required to execute the
instructions individually.
4. Find out the period of the clock frequency at which microprocessor is running i.e. duration of a clock state (T).
5. Find out the time required for the execution of the loop once by multiplying the period T with the number of clock states
required (n) to execute the delay loop once.
6. Find out the count (N) by dividing the required time delay Td by the duration for execution of the loop once (n*T).