home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / n / n002 / 4.ddi / ECLSRCA.ZIP / THE_END.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-08-16  |  8.6 KB  |  239 lines

  1. ;
  2. ;       THE_END.ASM  End program that terminates assembler source program
  3. ;
  4. ;       (C) Copyright 19896 SOuth Mountain Software Inc.
  5. ;       All Rights Reserved
  6. ;
  7.  
  8. ;
  9. ;       ===============================================================
  10. ;       References
  11. ;       ===============================================================
  12. ;
  13.  
  14.         EXTRN   Main:NEAR                       ; <<< External mainline
  15.  
  16.         PUBLIC  The_End                         ; End of the program
  17.         PUBLIC  getarg                          ; Get next argument
  18.         PUBLIC  start                           ; Beginning of the program
  19.         PUBLIC  atoi                            ; Convert ASCII to integer
  20.  
  21. ;
  22. ;       ===============================================================
  23. ;       Local data
  24. ;       ===============================================================
  25. ;
  26.  
  27. CSEG            SEGMENT BYTE PUBLIC 'CODE'      ; <<< put in common segment
  28.                 ASSUME  CS:CSEG, DS:CSEG, SS:CSEG, ES:CSEG
  29.  
  30.  
  31.                 DW      40 DUP (?)              ; The stack body
  32. stack           LABEL   WORD                    ; The startup stack top
  33.  
  34. SegmentPrefix   DW      ?                       ; Original Prefix segment
  35. Argument        DB      80 DUP (?)              ; Maximum command line
  36. ArgumentIndex   DW      81h                     ; Points to first argument
  37.  
  38.  
  39.  
  40. ;
  41. ;       ===============================================================
  42. ;       Global procedures
  43. ;       ===============================================================
  44. ;
  45. ;       start      Start and End the program
  46. ;       getarg     Return the next argument  
  47. ;       atoi       Convert an ASCII-decimal character string to integer
  48.  
  49.  
  50.  
  51. ;       ===============================================================
  52. ;       start   Start and End the program
  53. ;       ===============================================================
  54. ;
  55. ;       Starts the program under MS-DOS revision 2.00 (or later) and
  56. ;       calls the linked Main program.  Prior to the INTRA-SEGMENT call, the 
  57. ;       Argument pointers are setup (waiting for subsequent start 
  58. ;       calls).
  59. ;
  60. ;       Upon return, the AH register is set to indicate the type of 
  61. ;       exit, AL is set to the ERRORLEVEL, and the DX is optionally set
  62. ;       to the number of paragraphs (16 byte increments) that are to be
  63. ;       made resident.  There is no console I/O performed in this module.
  64. ;
  65. ;       Input from DOS  Description
  66. ;       --------------  ---------------------------
  67. ;       ES, DS          ES points to Segment Prefix Header (SPH)
  68. ;       CS, SS          Pointer to CSEG data segment
  69. ;
  70. ;       Output to Main  Description
  71. ;       --------------  ---------------------------
  72. ;       ES              Segment Prefix Header
  73. ;       CS, DS, SS      Pointer to CSEG data segment
  74. ;
  75. ;       Registers used  Description
  76. ;       --------------  ---------------------------
  77. ;       Not applicable
  78. ;       ===============================================================
  79. ;
  80. start           PROC NEAR
  81.                                                 ; Leave ES pointing to SPH
  82.                 MOV     AX, CS                  ; Setup up segment registers
  83.                 MOV     DS, AX
  84.                 MOV     SS, AX
  85.                 MOV     SP, OFFSET stack
  86.                 MOV     BX, ES
  87.                 MOV     SegmentPrefix, BX       ; Save the Segment Prefix
  88.                 MOV     ES, AX
  89.                 CALL    Main                    ; <<< External name
  90.  
  91. ;           Return code either:
  92. ;
  93. ;               AH = 00 Return to Prior Process
  94. ;               AL      Error status (00 implies no error)
  95. ;           or:
  96. ;               AH = 01 Return/Stay Resident
  97. ;               AL      Error status (00 implies no error)
  98. ;               DX      Number of paragraphs to save
  99.  
  100.                 CMP     AH, 00                  ; Make resident?
  101.                 JNE     _Installed
  102.                 MOV     AH, 4Ch                 ; Exit gracefully
  103.                 INT     21h
  104. _Installed:                                     ; Make resident
  105.                 MOV     AH, 31h
  106.                 INT     21h
  107.  
  108. start           ENDP
  109.  
  110. ;
  111. ;       ===============================================================
  112. ;       getarg     Return the next argument  
  113. ;       ===============================================================
  114. ;
  115. ;       Given the character index that should point to the next
  116. ;       byte in the SPH Command Line, return the argument suffixed
  117. ;       with a NULL byte.
  118. ;
  119. ;       It is assumed that all arguments are separated by SPACE
  120. ;       characters and that the command line is terminated by either
  121. ;       a CR or a NULL.
  122. ;
  123. ;       For example, command line is : XBIOS 7F 08
  124. ;
  125. ;    ES:0080   07 20 37 46 20 30 38 20 0D
  126. ;              ^^    '7''8'   '0''8'   ^^
  127. ;              ||                      ||
  128. ;            Number of characters    End of Line
  129. ;
  130. ;       Assumes that <Argument> has been preset to 80h in SPH prior to 
  131. ;       the first <GetArgument> call.
  132. ;
  133. ;       Input           Description
  134. ;       --------------  ---------------------------
  135. ;       DS              Pointer to CSEG data segment
  136. ;
  137. ;       Output          Description
  138. ;       --------------  ---------------------------
  139. ;       CY = C          No additional argument, or
  140. ;       CY = NC         Argument found
  141. ;       SI              Byte pointer to argument (if CY == NC)
  142. ;
  143. ;       Registers used  Description
  144. ;       --------------  ---------------------------
  145. ;       SI              Byte pointer past NULL byte
  146. ;       AL              Current character (NULL)
  147. ;       BX              Byte index
  148. ;       ===============================================================
  149. ;
  150.  
  151. getarg          PROC NEAR
  152.                 PUSH    ES
  153.                 MOV     AX, SegmentPrefix
  154.                 MOV     ES, AX
  155.                 MOV     BX, ArgumentIndex       ; Point to current index
  156.                 MOV     SI, OFFSET Argument     ; Point to output array
  157. ga_getoken:                                     ; Get to the argument
  158.                 CMP     BYTE PTR ES:[BX], ' '
  159.                 JL      ga_error
  160.                 JNE     ga_getout
  161.                 INC     BX
  162.                 JMP     ga_getoken
  163. ga_getout:
  164.                 MOV     AL, BYTE PTR ES:[BX]
  165.                 CMP     AL, ' '
  166.                 JLE     ga_success
  167.                 INC     BX
  168.                 MOV     [SI], AL
  169.                 INC     SI
  170.                 JMP     ga_getout
  171. ga_success:
  172.                 MOV     BYTE PTR [SI], 00h 
  173.                 MOV     SI, OFFSET Argument     ; Point to output array
  174.                 MOV     ArgumentIndex, BX
  175.                 CLC
  176.                 JMP     SHORT ga_exit
  177. ga_error:       STC
  178. ga_exit:
  179.                 POP     ES
  180.                 RET
  181. getarg          ENDP
  182.  
  183.  
  184. ;
  185. ;       ===============================================================
  186. ;       atoi            Convert ASCII to integer
  187. ;       ===============================================================
  188. ;
  189. ;       Input           Description
  190. ;       --------------  ---------------------------
  191. ;       DS:SI           Pointer to string
  192. ;
  193. ;       Output          Description
  194. ;       --------------  ---------------------------
  195. ;       CX              Unsigned integer conversion
  196. ;       AL              Last character read [SI-1]
  197. ;       DS:SI           Pointer to first non-integer character
  198. ;
  199. ;       Registers used  Description
  200. ;       --------------  ---------------------------
  201. ;       AX, SI, CX      Modified
  202. ;       CX              Accumulator
  203. ;       DX              10
  204. ;
  205. ;       ===============================================================
  206. ;
  207.  
  208. atoi            PROC    NEAR
  209.                 PUSH    DX
  210.                 PUSH    BX
  211.                 XOR     CX, CX                  ; Accumulator
  212.                 XOR     AH, AH
  213.                 MOV     BX, 10
  214. _atoi_loop:
  215.                 LODSB                           ; Get next character into AL
  216.                 CMP     AL, '9'
  217.                 JA      _atoi_exit              ; Out of range
  218.                 CMP     AL, '0'
  219.                 JB      _atoi_exit              ; Out of range
  220.  
  221.                 SUB     AL, '0'                 ; Convert to binary
  222.                 XCHG    AX, CX                  ; Multiply by 10
  223.                 MUL     BX
  224.                 ADD     AX, CX
  225.                 XCHG    AX, CX
  226.                 JMP     _atoi_loop              ; Go back for more
  227. _atoi_exit:
  228.                 POP     BX
  229.                 POP     DX
  230.                 RET
  231. atoi            ENDP
  232.  
  233.  
  234. The_End LABEL   BYTE
  235. CSEG            ENDS
  236.                 END     start 
  237.  
  238.  
  239.