home *** CD-ROM | disk | FTP | other *** search
- ;
- ; THE_END.ASM End program that terminates assembler source program
- ;
- ; (C) Copyright 19896 SOuth Mountain Software Inc.
- ; All Rights Reserved
- ;
-
- ;
- ; ===============================================================
- ; References
- ; ===============================================================
- ;
-
- EXTRN Main:NEAR ; <<< External mainline
-
- PUBLIC The_End ; End of the program
- PUBLIC getarg ; Get next argument
- PUBLIC start ; Beginning of the program
- PUBLIC atoi ; Convert ASCII to integer
-
- ;
- ; ===============================================================
- ; Local data
- ; ===============================================================
- ;
-
- CSEG SEGMENT BYTE PUBLIC 'CODE' ; <<< put in common segment
- ASSUME CS:CSEG, DS:CSEG, SS:CSEG, ES:CSEG
-
-
- DW 40 DUP (?) ; The stack body
- stack LABEL WORD ; The startup stack top
-
- SegmentPrefix DW ? ; Original Prefix segment
- Argument DB 80 DUP (?) ; Maximum command line
- ArgumentIndex DW 81h ; Points to first argument
-
-
-
- ;
- ; ===============================================================
- ; Global procedures
- ; ===============================================================
- ;
- ; start Start and End the program
- ; getarg Return the next argument
- ; atoi Convert an ASCII-decimal character string to integer
-
-
-
- ; ===============================================================
- ; start Start and End the program
- ; ===============================================================
- ;
- ; Starts the program under MS-DOS revision 2.00 (or later) and
- ; calls the linked Main program. Prior to the INTRA-SEGMENT call, the
- ; Argument pointers are setup (waiting for subsequent start
- ; calls).
- ;
- ; Upon return, the AH register is set to indicate the type of
- ; exit, AL is set to the ERRORLEVEL, and the DX is optionally set
- ; to the number of paragraphs (16 byte increments) that are to be
- ; made resident. There is no console I/O performed in this module.
- ;
- ; Input from DOS Description
- ; -------------- ---------------------------
- ; ES, DS ES points to Segment Prefix Header (SPH)
- ; CS, SS Pointer to CSEG data segment
- ;
- ; Output to Main Description
- ; -------------- ---------------------------
- ; ES Segment Prefix Header
- ; CS, DS, SS Pointer to CSEG data segment
- ;
- ; Registers used Description
- ; -------------- ---------------------------
- ; Not applicable
- ; ===============================================================
- ;
- start PROC NEAR
- ; Leave ES pointing to SPH
- MOV AX, CS ; Setup up segment registers
- MOV DS, AX
- MOV SS, AX
- MOV SP, OFFSET stack
- MOV BX, ES
- MOV SegmentPrefix, BX ; Save the Segment Prefix
- MOV ES, AX
- CALL Main ; <<< External name
-
- ; Return code either:
- ;
- ; AH = 00 Return to Prior Process
- ; AL Error status (00 implies no error)
- ; or:
- ; AH = 01 Return/Stay Resident
- ; AL Error status (00 implies no error)
- ; DX Number of paragraphs to save
-
- CMP AH, 00 ; Make resident?
- JNE _Installed
- MOV AH, 4Ch ; Exit gracefully
- INT 21h
- _Installed: ; Make resident
- MOV AH, 31h
- INT 21h
-
- start ENDP
-
- ;
- ; ===============================================================
- ; getarg Return the next argument
- ; ===============================================================
- ;
- ; Given the character index that should point to the next
- ; byte in the SPH Command Line, return the argument suffixed
- ; with a NULL byte.
- ;
- ; It is assumed that all arguments are separated by SPACE
- ; characters and that the command line is terminated by either
- ; a CR or a NULL.
- ;
- ; For example, command line is : XBIOS 7F 08
- ;
- ; ES:0080 07 20 37 46 20 30 38 20 0D
- ; ^^ '7''8' '0''8' ^^
- ; || ||
- ; Number of characters End of Line
- ;
- ; Assumes that <Argument> has been preset to 80h in SPH prior to
- ; the first <GetArgument> call.
- ;
- ; Input Description
- ; -------------- ---------------------------
- ; DS Pointer to CSEG data segment
- ;
- ; Output Description
- ; -------------- ---------------------------
- ; CY = C No additional argument, or
- ; CY = NC Argument found
- ; SI Byte pointer to argument (if CY == NC)
- ;
- ; Registers used Description
- ; -------------- ---------------------------
- ; SI Byte pointer past NULL byte
- ; AL Current character (NULL)
- ; BX Byte index
- ; ===============================================================
- ;
-
- getarg PROC NEAR
- PUSH ES
- MOV AX, SegmentPrefix
- MOV ES, AX
- MOV BX, ArgumentIndex ; Point to current index
- MOV SI, OFFSET Argument ; Point to output array
- ga_getoken: ; Get to the argument
- CMP BYTE PTR ES:[BX], ' '
- JL ga_error
- JNE ga_getout
- INC BX
- JMP ga_getoken
- ga_getout:
- MOV AL, BYTE PTR ES:[BX]
- CMP AL, ' '
- JLE ga_success
- INC BX
- MOV [SI], AL
- INC SI
- JMP ga_getout
- ga_success:
- MOV BYTE PTR [SI], 00h
- MOV SI, OFFSET Argument ; Point to output array
- MOV ArgumentIndex, BX
- CLC
- JMP SHORT ga_exit
- ga_error: STC
- ga_exit:
- POP ES
- RET
- getarg ENDP
-
-
- ;
- ; ===============================================================
- ; atoi Convert ASCII to integer
- ; ===============================================================
- ;
- ; Input Description
- ; -------------- ---------------------------
- ; DS:SI Pointer to string
- ;
- ; Output Description
- ; -------------- ---------------------------
- ; CX Unsigned integer conversion
- ; AL Last character read [SI-1]
- ; DS:SI Pointer to first non-integer character
- ;
- ; Registers used Description
- ; -------------- ---------------------------
- ; AX, SI, CX Modified
- ; CX Accumulator
- ; DX 10
- ;
- ; ===============================================================
- ;
-
- atoi PROC NEAR
- PUSH DX
- PUSH BX
- XOR CX, CX ; Accumulator
- XOR AH, AH
- MOV BX, 10
- _atoi_loop:
- LODSB ; Get next character into AL
- CMP AL, '9'
- JA _atoi_exit ; Out of range
- CMP AL, '0'
- JB _atoi_exit ; Out of range
-
- SUB AL, '0' ; Convert to binary
- XCHG AX, CX ; Multiply by 10
- MUL BX
- ADD AX, CX
- XCHG AX, CX
- JMP _atoi_loop ; Go back for more
- _atoi_exit:
- POP BX
- POP DX
- RET
- atoi ENDP
-
-
- The_End LABEL BYTE
- CSEG ENDS
- END start
-
-