【发布时间】:2011-12-12 04:55:44
【问题描述】:
我正在使用 Huffman 算法为 dos 8086(16 位 tasm 或 masm 不使用库)编写编码/解码 .COM 程序,并且需要将 2 个命令行参数(输入文件名和输出文件名)存储在数组中,以便我可以读取输入文件,应用我的霍夫曼编码,然后写入输出文件。
我读到它们存储在地址 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,即输入文件名)。
而且它不起作用,所以我肯定做错了什么。 对于任何有经验的程序员来说,这看起来可能完全是一团糟,但那是因为我试图遵循我在互联网上找到的资源但没有成功,因此只使用我目前理解的概念来实现它。 任何帮助将不胜感激, 谢谢。
【问题讨论】:
标签: assembly masm x86-16 huffman-code tasm