Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!sun-barr!cs.utexas.edu!uunet!mcvax!ukc!etive!djm From: djm@etive.ed.ac.uk (D Murphy) Newsgroups: comp.binaries.ibm.pc.d Subject: 8086 assembler query Message-ID: <2178@etive.ed.ac.uk> Date: 30 May 89 16:38:27 GMT Reply-To: djm@etive.ed.ac.uk (D Murphy) Organization: Edinburgh University Computer Services Lines: 98 I'm writing an assembly language program for a PC and need to access command line arguments as strings. On execution, DOS sets DS and ES to the segment address of the Program Segment Prefix, and the area of memory offset 81h to 100h from the PSP contains all the characters (except pipes and redirection) entered after the command name. The code fragment below was what I thought would do the job. Unfortunately it doesn't and I can't see why it doesn't. I'd appreciate any suggestions as to why it won't work and/or advice on what to do to make it work. When run, all that happens is that a pile of characters are written to the screen, including the command line parameters, then the end of the program is reached and execution stops. Thanks in anticipation, Murff.... JANET: djm@uk.ac.ed.etive Internet: djm%ed.etive@nsfnet-relay.ac.uk Murff@uk.ac.ed.emas-a Murff%ed.emas-a@nsfnet-relay.ac.uk trinity@uk.ac.ed.cs.tardis trinity%ed.cs.tardis@nsfnet-relay.ac.uk D.J. Murphy *Artificial* intelligence ? Evidently..... CODE FRAGMENT FOLLOWS: ; data SEGMENT ; ; ; Strings infile DB 40 DUP (0) ; Old filename outfile DB 40 DUP (0) ; New filename ; ; data ENDS ; ; ********* Code ************ ; code SEGMENT ; ASSUME cs:code,ds:data,ss:stack ; start: ; <----- ENTRY POINT HERE ------ mov bx,0081 ; pointer to start of command line mov dh,00 ; clear start-of-args flag mov al,00 ; zero argument count ; ;*********************************************** ; ; Register utilization for command line scanning ; ah = current character ; al = argument count ; bx = PSP offset for reading command line ; cx = pointer to offset of current argument ; dh = reading-argument flag ; dl = not used ; ds = not altered ; es = PSP segment address ; ss = not altered ; cs = not altered ; ;*********************************************** ; jp1: inc bx ; start searching command line mov ah,[bx] ; load character cmp ah,13d ; end of command line ? je jp5 ; change dir entry if yes cmp dh,01 ; have we started reading an argument ? je jp3 ; if we have, process character cmp ah,20 ; if not, is this the start of an arg ? je jp1 ; if not, get next character ; mov dh,01 ; if it is, set read-arg flag inc al ; increment argument count cmp al,01 ; is this the first argument ? jnz jp2 ; mov cx,OFFSET infile ; if it is, load cx with pointer to infile jmp jp3 ; and process character ; jp2: mov cx,OFFSET outfile ; otherwise load cx = pointer to outfile ; jp3: cmp ah,20 ; is current character a space ? je jp4 ; if it is, set string termination push bx ; mov bx,cx ; mov ah,[bx] ; otherwise write character to string pop bx ; inc cx ; and increment string pointer jmp jp1 ; then get the next character ; jp4: mov dh,00 ; otherwise clear read-arg flag cmp al,02 ; was that the second argument ? je jp5 ; stop reading if it was jmp jp1 ; otherwise loop to get next argument ; jp5: