ms dos - 8086 Assembly / MS-DOS, passing file name from the command line -
say have program.asm - have following in data segment:
.data filename db 'file.txt', 0 fhndl dw ? buffer db ?
i want 'file.txt' dynamic guess? once compiled, program.exe needs able accept file name via command line:
c:\> program anotherfile.txt execution goes here
how enable this? thank in advance.
dos stores command line in legacy structure called program segment prefix ("psp"). , mean legacy. structure designed backwards-compatible programs ported cp/m.
where's psp?
you know how programs built .com
files start org 100h
? reason precisely - .com programs - psp stored @ beginning of code segment (at cs:0h). psp 0ffh bytes long, , actual program code starts right after (that is, @ cs:100h).
the address conveniently available @ ds:00h , es:00h, since key characteristic of .com format segment registers start same value (and com program typically never changes them).
to read command line .com
program, can pick length @ cs:80h (or ds:80h, etc. long haven't changed registers). command line starts @ cs:81h , takes rest of psp, ending carriage return (0dh) terminator, command line never more 126 bytes long.
(and why command line has been 126 bytes in dos forever, despite fact wished years made longer. since winnt uses provides different mechanism access command line, winnt/xp/etc. command line doesn't suffer size limitation).
for .exe
program, can't rely on cs:00h because startup code segment can anywhere in memory. however, when program starts, dos stores psp @ base of default data segment. so, @ startup, ds:00h , es:00h point psp, both .exe , .com programs.
if didn't keep track of psp address @ beginning of program, , change both ds , es, can ask dos provide segment value @ time, via int 21h, function 62h. segment portion of psp address returned in bx (the offset being of course 0h).
Comments
Post a Comment