Page 14 - DCAP102_DCAP_401_Foundations of Computer Programming
P. 14

Unit 1: Foundation of Programming Languages




          1.5 Assembly Program and its Components                                               Notes

          Sample Program:

          In this program we just display:
          Line Numbers          Offset        Source Code
          0001                                DATA SEGMENT
          0002                  0000          MESSAGE DB “HAVE A NICE DAY!$”

          0003                                DATA ENDS
          0004                                STACK SEGMENT
          0005                                STACK 0400H
          0006                                STACK ENDS
          0007                                CODE SEGMENT

          0008                                ASSUME CS: CODE, DS: DATA SS: STACK
          0009           Offset        Machine               Code
          0010           0000          B8XXXX                MOV AX, DATA
          0011           0003          8ED8                  MOV DS, AX

          0012           0005          BAXXXX                MOV DX, OFFSET MESSAGE
          0013           0008          B409                  MOV AH, 09H
          0014           000A          CD21                  INT 21H
          0015           000C          B8004C                MOV AX, 4C00H
          0016           000F          CD21                  INT 21H
          0017                                               CODE ENDS

          0018                                               END
          The details of this program are:

          The Program Annotation

          The program annotation consists of three columns of data: line numbers, offset and machine
          code.


          1.   The assembler assigns line numbers to the statements in the source file sequentially. If the
               assembler issues an error message; the message will contain a reference to one of these line
               numbers.
          2.   The second column from the left contains offsets. Each offset indicates the address of an
               instruction or a datum as an offset from the base of its logical segment, e.g., the statement
               at line 0010 produces machine language at offset 0000H of the CODE SEGMENT and the
               statement at line number 0002 produces machine language at offset 0000H of the DATA
               SEGMENT.
          3.   The third column in the annotation displays the machine language produce by code
               instruction in the program.

          Segment numbers: There is a good reason for not leaving the determination of segment numbers
          up to the assembler. It allows programs written in 8086 assembly language to be almost entirely



                                           LOVELY PROFESSIONAL UNIVERSITY                                     7
   9   10   11   12   13   14   15   16   17   18   19