home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
database
/
slyce110.zip
/
RC.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-13
|
9KB
|
209 lines
page 60,133
%noincl
include macro.lib
include equates.lib
.sall
code segment word 'code'
assume cs:code,ds:code,es:code
org 100H
;
; Programmer: T. G. Browning
;
Main proc near
mov bx,CmdTailOffs
call argc
cmp ax,2
jne ErrExit
mov ax,0001
mov bx,CmdTailOffs
call argv
call Asc2Bin
push ax
mov ax,0002
mov bx,CmdTailOffs
call argv
call Asc2Bin
pop dx
xchg dh,dl
dec dh
cmp dh,24
jg ErrExit
mov dl,al
dec dl
cmp dl,79
jg ErrExit
xor bx,bx
@dos10 02H
DOSOut:
@dosExit
ErrExit:
mov dx,OffSet Syntax
@dos21 09H
jmp DOSOut
Main endp
;
; DATA
Syntax db 'RC.COM. Batch utility by MorganSoft. Released to the Public Domain.',CR,LF
db 'Syntax: rc row col.',CR,LF,'$'
Bin1 dw ?
MultVal dw ?
TenPower db 10
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
argc proc near
;
; Count command line arguments.
; Call with ES:BX = command line
; Returns AX = argument count
;
Public argc
push bx ; save bx and cx
push cx
mov ax,0 ; force count = 0
argc1: mov cx,-1 ; set flag = outside argument
argc2: inc bx ; point to next characterf
cmp byte ptr es:[bx],cr
je argc3 ; exit if carriage return
cmp byte ptr es:[bx],blank
je argc1 ; outside argument if ASCII blank
cmp byte ptr es:[bx],tab
je argc1 ;\ outside argument if ASCII tab
; otherwise not blank or tab.
jcxz argc2 ; jump if alread inside argument
inc ax ; else found argument. Count it
not cx ; set flag = inside argument
jmp argc2 ; and look at next character
argc3: pop cx ; restore original bx and cx
pop bx
ret ; ax = argument count
argc endp
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
argv proc near
;
; Get address and length of command line arguments
; Call with ES:BX = Command line
; AX = Argument #
; Returns: ES:BX = address
; ax = length
;
Public argv
push cx ; save original cx,di
push di
or ax,ax ; is it argument 0?
jz argv8 ; yes, jumpt to program name
xor ah,ah ; initialize argument counter
argv1: mov cx,-1 ; set flag = outside argument
argv2: inc bx ; point to next character
cmp byte ptr es:[bx],cr
je argv7 ; exit if carriage return
cmp byte ptr es:[bx],blank
je argv1 ; outside argument if ASCII blank
cmp byte ptr es:[bx],tab
je argv1 ; outside argument if ASCII tab
; if not blank or tab,
jcxz argv2 ; jump if alread inside argument
inc ah ; else count arguments found
cmp ah,al ; is this the one we're looking for
je argv4 ; yes, go find length
not cx ; no, set flag = inside argument
jmp argv2 ; and look at next character
argv4: ; found desired argument, now
; determine the length
mov ax,bx ; save param starting address
argv5:
inc bx ; point to next char
cmp byte ptr es:[bx],cr
je argv6 ; found end if carriage return
cmp byte ptr es:[bx],blank
je argv6 ; found end if space
cmp byte ptr es:[bx],tab
jne argv5 ; found end if tab
argv6: xchg bx,ax ; set es:bx = argument address
sub ax,bx ; and ax = argument length
jmp argvx ; return to caller
argv7: xor ax,ax ; set ax = 0 argument not found
jmp argvx ; return to caller
argv8: ; special handling for argv = 0
mov ax,3000H ; check if DOS 3.0 or later
int 21H ; (force al= 0 in case DOS 1)
cmp al,3
jb argv7 ; DOS 1 or 2, return a null string
mov es,es:[2ch] ; get environment segment from PSP
xor di,di ; find the program name by
xor al,al ; first skipping over all the
mov cx,-1 ; environment variables
cld
argv9:
repne scasb ; scan for double null (can't use
scasb ; stasw, might be odd addr
jne argv9 ; loop if it was a single null
add di,2 ; skip word count
mov bx,di ; save program name address.
mov cx,-1 ; now fin its length....
repne scasb ; scan for another null byte
not cx ; convert CX to length
dec cx
mov ax,cx ; return length in ax
argvx: ; comman exit point
pop di ; restore original cx and di
pop dx
ret
argv endp
;==================================================
; Asc2Bin: Procedure to convert an ASCII value ;
; to Binary. ;
; Requires ax=length, bx = offset ;
; ;
; Returns ax: Binary Value ;
;==================================================
Asc2Bin proc near
push bx
push cx
push dx
push si
mov Bin1,0
mov MultVal,1
mov cx,ax
mov si,bx
add si,cx
dec si
xor ax,ax
A2B10:
mov al,[si]
and al,0FH
mul MultVal
add Bin1,ax
mov ax,MultVal
mul TenPower
mov MultVal,ax
dec si
loop A2B10
mov ax,Bin1
pop si
pop dx
pop cx
pop bx
clc
ret
Asc2Bin endp
Code ends
end Main