External Subroutines - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

External Subroutines

Description:

Remember that multiple object files can be linked together. ... List_of_Names = name1:type1, name2:type2, ...etc. type = {NEAR, FAR, BYTE, WORD, DWORD} ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 9
Provided by: yahyae
Category:

less

Transcript and Presenter's Notes

Title: External Subroutines


1
External Subroutines
2
Subroutines
  • A separately-assembled procedure must be
    contained in an .asm file consisting of at least
    one segment definition.
  • Reminder
  • Remember that multiple object files can be linked
    together.
  • A .exe file can be the result of linking multiple
    object files.

3
Subroutines (contd)
  • ? Syntax of procedure declaration
  • Procedure_name PROC type
  • type NEAR (default) or FAR
  • ? Near vs. FAR
  • A procedure is NEAR if the statement that
    calls it is in the same segment as the procedure
    itsself a procedure is FAR if it is called from
    a different segment.

4
Subroutines (contd)
  • The EXTERN command
  • Role
  • It is used to inform the assembler of names that
    are not defined in the same file in which they
    are used.
  • ? Syntax
  • EXTERN List_of_Names
  • List_of_Names name1type1, name2type2, etc
  • type NEAR, FAR, BYTE, WORD, DWORD

For externally defined procedures
For externally defined variables
5
Subroutines (contd)
  • Example
  • EXTERN PROC1NEAR, PROC2FAR
  • ? MASM knows from the EXTERN list that PROC1 and
    PROC2 are defined in other files. So, it
    allocates undefined addresses to them. The
    addresses are filled in when the files containing
    the procedures are linked with the file
    containing the CALLs.

6
Subroutines (contd)
  • The EXTERN command may appear any where in the
    program as long as it precedes the first
    reference to any of the names in the
    List_of_Names.
  • The PUBLIC command
  • A procedure or a variable must be declared
    with the PUBLIC command if it is to be used in a
    different file.
  • ? Syntax
  • PUBLIC name_list
  • where name_list is the list of procedure and
    variable names that may be referred to in a
    different file.
  • ? The PUBLIC keyword can appear any where in the
    file. But, it is better to be put at the begining

7
Subroutines (contd)
  • See the example!
  • How to link the two files ?
  • masm main.asm -gt main.obj
  • masm proc.asm -gt proc.obj
  • link main proc -gt main.exe
  • ? When the two object files are linked, the code
    and data segments of main and proc are combined
    into one code segment and one data segment,
    respectively.

8
Libraries
  • Instead of linking individual object files to
    form a .exe file, we can create a library file of
    object modules containing procedures.
  • When a library is specified during the linking
    step, LINK retrieves a procedures a program needs
    from the library and then creates an .exe file.
Write a Comment
User Comments (0)
About PowerShow.com