home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / ASMUTL / MAC_ASM.ZIP / ASMTUTR4.DOC < prev    next >
Encoding:
Text File  |  1983-12-11  |  5.5 KB  |  133 lines

  1.  
  2.  
  3. ;COLORINIT EQU       03H       ;Value to initialize color screen (80x25)
  4. COLORINIT EQU      01H       ;Value to initialize color screen (40X25)
  5. ;
  6. ;         Now, describe our own segment
  7. ;
  8. SETSCRN   SEGMENT             ;Set operating segment for CODE and DATA
  9. ;
  10.           ASSUME CS:SETSCRN,DS:SETSCRN,ES:SETSCRN,SS:SETSCRN    ;All segments
  11. ;
  12.           ORG       100H      ;Begin assembly at standard .COM offset
  13. ;
  14. MAIN      PROC      NEAR      ;COM files use NEAR linkage
  15.           JMP       BEGIN     ;And, it is helpful to put the data first, but
  16. ;                             ;then you must branch around it.
  17. ;
  18. ;         Data used in SETSCRN
  19. ;
  20. CHANGELOC   DD      EQUIP     ;Location of the EQUIP, recorded as far pointer
  21. MONOPROMPT  DB      'Please press the plus ( + ) key.$'    ;User sees on mono
  22. COLORPROMPT DB      'Please press the minus ( - ) key.$'   ;User sees on color
  23.  
  24.  
  25. Several things are illustrated on this page.  First, in addition to titles,
  26. the assembler supports subtitles:  hence the SUBTTL pseudo-op.  Second, the
  27. PAGE pseudo-op can be used to go to a new page in the listing.  You see an
  28. example here of the DSECT-style segment in the "SEGMENT AT 40H".  Here, our
  29. our interest is in correctly describing the location of some data in the
  30. BIOS work area which really is located at segment 40H.
  31.  
  32. You will also see illustrated the EQU instruction, which just gives a sym-
  33. bolic name to a number.  I don't make a fetish of giving a name to every
  34. single number in a program.  I do feel strongly, though, that interrupts
  35. and function codes, where the number is arbitrary and the function being
  36. performed is the thing of interest, should always be given symbolic names.
  37.  
  38. One last new element in this section is the define doubleword (DD) instruc-
  39. tion.  A doubleword constant can refer, as in this case, to a location in
  40. another segment.  The assembler will be happy to use information at its
  41. disposal to properly assemble it.  In this case, the assembler knows that
  42. EQUIP is offset 10 in the segment BIOSDATA which is at 40H.
  43.  
  44.           SUBTTL -- Perform function
  45.           PAGE
  46. BEGIN:    CALL      MONOON                  ;Turn on mono display
  47.           MOV       DX,OFFSET MONOPROMPT          ;GET MONO PROMPT
  48.           MOV       AH,PRTMSG                     ;ISSUE
  49.           INT       DOS                           ;IT
  50.           CALL      COLORON                 ;Turn on color display
  51.           MOV       DX,OFFSET COLORPROMPT         ;GET COLOR PROMPT
  52.           MOV       AH,PRTMSG                     ;ISSUE
  53.           INT       DOS                           ;IT
  54.           MOV       AH,GETKEY               ;Obtain user response
  55.           INT       KBD
  56.           CMP       AL,'+'                  ;Does he want MONO?
  57.           JNZ       NOMONO
  58.  
  59.  
  60. IBM PC Assembly Language Tutorial                                        26
  61.  
  62.  
  63.  
  64.           CALL      MONOON                  ;yes.  give it to him
  65. NOMONO:   RET
  66. MAIN      ENDP
  67.  
  68.  
  69. The main code section makes use of subroutines to keep the basic flow sim-
  70. ple.  About all that's new to you in this section is the use of the BIOS
  71. interrupt KBD to read a character from the keyboard.
  72.  
  73. Now for the subroutines, MONOON and COLORON:
  74.  
  75.           SUBTTL -- Routines to turn monitors on
  76.           PAGE
  77. MONOON    PROC      NEAR                ;Turn mono on
  78.           LES       DI,CHANGELOC        ;Get location to change
  79.           ASSUME    ES:BIOSDATA         ;TELL ASSEMBLER ABOUT CHANGE TO ES
  80.           OR        EQUIP,MONO
  81.           MOV       AX,MONOINIT         ;Get screen initialization value
  82.           INT       SCREEN              ;Initialize screen
  83.           RET
  84. MONOON    ENDP
  85. COLORON   PROC      NEAR                ;Turn color on
  86.           LES       DI,CHANGELOC        ;Get location to change
  87.           ASSUME    ES:BIOSDATA         ;TELL ASSEMBLER ABOUT CHANGE TO ES
  88.           AND       EQUIP,COLOR
  89.           MOV       AX,COLORINIT        ;Get screen initialization value
  90.           INT       SCREEN              ;Initialize screen
  91.           RET
  92. COLORON   ENDP
  93. SETSCRN   ENDS                          ;End of segment
  94.           END       MAIN                ;End of assembly; execution at MAIN
  95.  
  96.  
  97. The instructions LES and LDS are useful ones for dealing with doubleword
  98. addresses.  The offset is loaded into the operand register and the segment
  99. into ES (for LES) or DS (for LDS).  By telling the assembler, with an
  100. ASSUME, that ES now addresses the BIOSDATA segment, it is able to correctly
  101. assemble the OR and AND instructions which refer to the EQUIP byte.  An ES
  102. segment prefix is added.
  103.  
  104. To understand the action here, you simply need to know that flags in that
  105. particular byte control how the BIOS screen service initializes the adapt-
  106. ers.  BIOS will only work with one adapter at a time; by setting the equip-
  107. ment flags to show one or the other as installed and calling BIOS screen
  108. initialization, we achieve the desired effect.
  109.  
  110. The rest is up to you.
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. IBM PC Assembly Language Tutorial                                        27
  122. .
  123.  
  124. The rest is up to you.
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. IBM PC Assembly Language Tutorial                                        27
  136.