8086 -在数组中存储命令行参数



我正在编写一个编码/解码。com程序,使用dos 8086的霍夫曼算法(16位tasm或masm,不使用库),需要在数组中存储2个命令行参数(inputfilename和outputfilename),以便我可以读取输入文件,应用我的霍夫曼编码,并写入输出文件。

我读到它们存储在地址80h,其中80h包含参数的长度,81h包含参数本身。因此,我们的想法是将第一个参数存储在inarg中(第二个参数存储在outarg中,我还没有开始研究它)。调用子例程9的中断21h的目的是检查它是否正确。(事实并非如此)

到目前为止我写的是:

getCLargs proc near 
mov cx, [080h]        ; store memory address of command-line argument length
mov bx, 082h          ; store command-line arguments first byte
sub si,si  
sub di,di
next:         
mov dx, [bx]          ; store first byte of argument into dx 
mov inarg[si],dx      ; put it into the first byte of the array inarg
cmp cx, di            ; compare di to the length of the args
je print              ; if equal, done, jump to print
inc di                ; else: inc di
;    inc si
jmp next              ; do it again until cx=di
print:
mov ah, 09h           ; print content of inarg array to check it's right
mov dx, inarg
mov inarg[si+1], '$'  ; not sure whether I must terminate my string array with '$'
int 21h
done:    
ret
getCLargs endp

有以下相关数据:

inarg dw ?
outarg dw ?

我从基础开始,没有考虑分隔符,并尝试只获得第一个参数(inarg,这是输入文件名)。

它不工作,所以我肯定做错了什么。对于任何有经验的程序员来说,这看起来可能是一团糟,但这是因为我试图遵循我在互联网上找到的资源而没有成功,因此只使用我目前所理解的概念来实现它。任何帮助都将非常感激。谢谢你。

您的代码有几处错误。而不是我描述如何修复它,您可能认为您不必复制参数。它们已经在内存中了,所以你可以只存储指向参数的指针,以及它们的长度。如果你不想,你甚至不需要存储长度。相反,在每个参数的末尾放置一个0字节到内存中。

http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_13/CH13-9.html上的文章提供了解析命令行的一个很好的示例。

在汇编语言艺术16位版的在线书籍中,第13章有一节是关于解析命令行的。这本书可以在网上的几个地方找到。一个很好的链接(截至2016年4月5日)是http://www.plantation-productions.com/Webster/www.artofasm.com/DOS/ch13/CH13-9.html#HEADING9-1。

最新更新