Page 16 - DCAP102_DCAP_401_Foundations of Computer Programming
P. 16

Unit 1: Foundation of Programming Languages




          3.   PROC Directive: The code segment contains the executable code for a program, which  Notes

               consists of one or more procedures defined initially with the PROC directive and ended
               with the ENDP directive.
                         Procedure-name PROC FAR ; Beginning of Procedure

                         Procedure-name ENDP FAR ; End Procedure
          4.   END DIRECTIVE: ENDS directive ends a segment, ENDP directive ends a procedure and
               END directive ends the entire program that appears as the last statement.
          5.   ASSUME Directive: An .EXE program uses the SS register to address the base of stack, DS
               to address the base of data segment, CS to address base of the code segment and ES register
               to address the base of Extra segment. This directive tells the assembler to correlate segment
               register with a segment name.

                       Example:
               ASSUME SS: stack_seg_name, DS: data_seg_name, CS: code_seg_name.


          6.   SEGMENT  Directive: The segment directive defines the logical segment to which
               subsequent instructions or data allocations statement belong. It also gives a segment name
               to the base of that segment.
          The address of every element in a 8086 assembly program must be represented in segment -
          relative format. That means that every address must be expressed in terms of a segment register
          and an offset from the base of the segmented addressed by that register. By defining the base

          of a logical segment, a segment directive makes it possible to set a segment register to address
          that base and also makes it possible to calculate the offset of each element in that segment from
          a common base.
          An 8086 assembly language program consists of logical segments that can be a code segment, a
          stack segment, a data segment, and an extra segment.
          A segment directive indicates to assemble all statements following it in a single source fi le until
          an ENDS directive.

          Code Segment
          The logical program segment is named code segment. When the linker links a program it makes
          a note in the header section of the program’s executable fi le describing the location of the code
          segment when the DOS invokes the loader to load an executable file into memory, the loader

          reads that note. As it loads the program into memory, the loader also makes notes to itself of
          exactly where in memory it actually places each of the program’s other logical segments. As the
          loader hands execution over to the program it has just loaded, it sets the CS register to address the

          base of the segment identified by the linker as the code segment. This renders every instruction in
          the code segment addressable in segment relative terms in the form CS: xxxx.

          The linker also assumes by default that the first instruction in the code segment is intended to be

          the first instruction to be executed. That instruction will appear in memory at an offset of 0000H
          from the base of the code segment, so the linker passes that value on to the loader by leaving an
          another note in the header of the program’s executable fi le.
          The loader sets the IP (Instruction Pointer) register to that value. This sets CS:IP to the segment

          relative address of the first instruction in the program.








                                           LOVELY PROFESSIONAL UNIVERSITY                                     9
   11   12   13   14   15   16   17   18   19   20   21