1

I'm writing an encoding/decoding .COM program using Huffman algorithm for dos 8086 (16-bit tasm or masm without using libraries), and need to store 2 command-line arguments (inputfilename and outputfilename) in arrays so that I can read the input file, apply my huffman encoding, and write to the output file.

I've read that they are stored at address 80h, where 80h contains the length of the arguments, and 81h onward the arguments themselves. So the idea is to store the first argument in inarg (and the second one in outarg, which I haven't started working on yet) The purpose of the interrupt 21h call with subroutine 9 was to check I had it right. (which is not the case)

Here is what I have so far:

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

With the following relevant data:

inarg dw ?
outarg dw ?

I've started with the basics without considering delimiters, and trying to get only the first argument (inarg, which is the input file name).

And it doesn't work, so I'm definitely doing something wrong. This look may like a total mess to any experienced programmer, but that's because I tried to follow resources I found on the internet without success, and therefore switch to implement it using only the concepts I understand so far. Any help would be greatly appreciated, Thank you.

4

1 回答 1

3

您的代码有几处问题。而不是我描述如何解决它,您可能会认为您不必复制参数。它们已经在内存中,因此您可以只存储指向参数的指针及其长度。如果你不想的话,你甚至不必存储长度。相反,0在每个参数的末尾放置一个字节到内存中。

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

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

于 2011-12-12T05:25:13.680 回答