×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

help with command line

help with command line

help with command line

(OP)
Hello All,
I'm trying to get the input filename and output filename from a user using the command line.

The only problem is, this doesn't seem to open the input filename. I am assuming that 81h is always going to be a space, therefore I started with 82h.
 
ex. thisprogram input.txt output.txt

I am storing "input.txt "
Should I be decreasing the variable by 1 position and then adding a 0 to the end like I'm doing in this program and am I doing it right?

Am I saving my handles correct as well?

Thank you very much.



        MOV SI, 82h
    XOR DI, DI

    MOV AL, BYTE PTR ES:[SI]
    CMP AL, 0dh
    JE MISSING    

    INC SI
    CMP AL, 0dh
    JE MISSING
    
INPUT1:
    CMP AL, 20h         ; Test for Space
    JE PREINPUT2
    MOV NAME1[DI], AL
    INC DI
    INC SI
    JMP INPUT1

    
PREINPUT2:
    MOV NAME1[DI], 30h
    INC SI
    MOV DX, offset CHECK1    ; Display Check1
    INT 21h            
    XOR DI, DI

INPUT2:
    MOV AL, BYTE PTR ES:[SI]
    CMP AL, 0Dh
    JE MISSING1
    CMP AL, 20h
    JE OPENIN

    MOV NAME2[DI], AL
    INC DI
    INC SI
    JMP INPUT2

OPENIN:    
    MOV NAME2[DI], 0
    MOV AH, 9
    MOV DX, offset ANSCHECK
    INT 21h
    
    MOV DX, offset CHECK2     ; Display Check2
    INT 21h
    CLC
    
    MOV DX, offset NAME1
    MOV AH, 3Dh         ; Open file code
    MOV AL, 0           
    INT 21h
    JC ERROR1           
    MOV HANDLE1, AX        ; Save Open Input Handle
    JMP OUTPUT
    
ERROR1:
    JMP MISSMESSAGE1

MISSING1:
    CALL MISSMESSAGE1
    JMP THEEND    


MISSMESSAGE1 proc
    MOV AH, 9
    MOV DX, offset INERROR
    INT 21h
    ret
MISSMESSAGE1 endp



CHECK1 DB 'Checking for Valid Input Filename...',0dh,0ah,'$'
CHECK2 DB 'Checking for Valid Output Filename...',0dh,0ah,'$'
ANSCHECK DB 'Check Done ... OK',0dh,0ah,'$'
INERROR DB '*ERROR with Input File*', 0dh, 0ah, '$'
NAME1 DB 32 DUP (?)

RE: help with command line

Hello,

Your code is a mess and doesn't work, so I wrote a program that seems to do what you want:

CODE SEGMENT
 ASSUME CS:CODE,DS:CODE,ES:CODE

    ORG    0100H
START:
    MOV    SI,82h            ; copy from here (DS)
    MOV    DI,OFFSET NAME1        ; store it here (ES)
    CMP    BYTE PTR [SI-2],0    ; Any characters on commandline?
    JE    NOCMDLINE        ; No
LOOP1:
    LODSB                ; same as mov al,[ds:si] inc si
    STOSB                ; same as mov [es:di],al inc di
    CMP    AL,20H            ; space? (end of first file)
    JNE    CHECKEOL        ; no, check for end of line
    MOV    BYTE PTR [DI-1],0    ; close first filename
    MOV    DI,OFFSET NAME2        ; store it here
    JMP    LOOP1            ; continue
CHECKEOL:
    CMP    AL,0DH            ; end of line character?
    JNE    LOOP1            ; no, do next one
    MOV    BYTE PTR [DI-1],0    ; close filename

    CMP    BYTE PTR [NAME2],0    ; second filename copied
    JE    NOCMDLINE

    MOV    AX,3D00h        ; Open file for reading
    MOV    DX,OFFSET NAME1        ; First name
    INT    21H
    JNC    FILE1OPEN        ; Fault with opening? No
    MOV    DX,OFFSET F1FAULT    ; Display faultmessage
ERROR:
    MOV    AH,9            ; do display
    INT    21H
    INT    20H            ; terminate .COM program
NOCMDLINE:
    MOV    DX,OFFSET NOFN        ; No filenames found
    JMP    ERROR            ; print message
FILE1OPEN:                ; First file is opened
                ; rest of program
    INT    20H

NOFN    DB    'Two filenames on commandline needed',13,10,'$'
F1FAULT    DB    'Error opening first file',13,10,'$'

NAME1    DB 32 DUP (0)
NAME2    DB 32 DUP (0)

CODE ENDS
    END    START

Wouter Dijkslag
 
http://www.wody.demon.nl
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close