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

发布于 2024-12-21 04:47:44 字数 1329 浏览 1 评论 0原文

我正在使用适用于 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,这是输入文件名) 。

而且它不起作用,所以我肯定做错了什么。 对于任何经验丰富的程序员来说,这看起来可能完全是一团糟,但那是因为我试图遵循在互联网上找到的资源但没有成功,因此转而仅使用我迄今为止理解的概念来实现它。 任何帮助将不胜感激, 谢谢。

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], '

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.

; not sure whether I must terminate my string array with '

With the following relevant data:


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.

int 21h done: ret getCLargs endp

With the following relevant data:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲影 2024-12-28 04:47:44

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

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

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

There are several things wrong with your code. Rather than me describing how to fix it, you might consider that you don't have to copy the arguments. They're already in memory, so you could just store pointers to the arguments, and their lengths. And you don't even have to store the lengths if you don't want to. Instead, put a 0 byte in memory at the end of each argument.

The article at http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_13/CH13-9.html has a very good example of parsing the command line.

In the 16-bit edition of the online book Art of Assembly language, there's a section in Chapter 13 about parsing the command line. The book is available in several places on the Web. One good link (as of 05/04/2016) is http://www.plantation-productions.com/Webster/www.artofasm.com/DOS/ch13/CH13-9.html#HEADING9-1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文