如何在16位汇编程序中传递/检索DOS命令行参数? [英] How to pass/retrieve DOS command-line parameters in a 16-bit assembly program?

查看:130
本文介绍了如何在16位汇编程序中传递/检索DOS命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为MS-DOS写一些小工具.现在,我正在编写Shutdown.com,例如对于Windows XP和更高版本.我已经写了完整的代码,现在只需要从DOS传递参数即可.

I am writing some little tools for MS-DOS. Now I'm writing a Shutdown.com, like for Windows XP and greater. I have already written the entire code, now I just need to pass the argument from DOS.

我需要传递参数"-r"以重新引导,传递参数"-s"以关闭.

I need to pass the parameters "-r" to reboot and "-s" to shutdown.

我该怎么办?

我在Windows 98上使用 TASM(Turbo汇编器4.1)进行链接和编译.我正在寻找一种非常简单的方法,并且如果可能的话,仍然是一个.COM程序.我看起来完全像C语言中的ARGV和ARGC,但是对于汇编16位...

I'm using TASM(Turbo Assembler 4.1) on Windows 98 to link and compile. I'm looking for a very simple way to do it, and if possible, still a .COM program. I'm looking exactly like the ARGV and ARGC from C language, but for Assembly 16-bits...

  • shutdown -r将重新启动
  • shutdown -s将关闭
  • shutdown -r will reboot
  • shutdown -s will shutdown

请记住,我已经知道如何重新启动以及如何关闭PC.
我只需要学习如何将参数从MS-DOS命令行传递到我的程序即可.

Remember that I already know how to reboot and how to shutdown the PC.
I just need to learn how to pass the parameters from the MS-DOS command line to my program.

推荐答案

没有特定的API来检索MS-DOS中的命令行.相反,您必须从程序段前缀(a)的适当偏移量中读取值,这是DOS用于存储程序特定数据的数据结构.

There is no specific API to retrieve the command-line in MS-DOS. Instead, you have to read the value from the appropriate offset of the Program Segment Prefix (PSP), which is a data structure that DOS uses to store program-specific data.

在偏移量80h处,有一个1字节的值给出了命令行参数的长度.实际的命令行参数字符串从偏移量81h开始,并且最大长度为127个字节.您知道它基于偏移量80h的值有多长时间,但是它也将以回车(0Dh)终止.

At offset 80h, there is a 1-byte value that gives the length of the command-line arguments. The actual command-line argument string starts at offset 81h, and can be up to 127 bytes in length. You know how long it is based on the value at offset 80h, but it will also be terminated with a carriage return (0Dh).

您可以在首次执行程序时使用相对于DS寄存器中指针的偏移量.否则,在AH设置为62h的情况下调用INT 21h,以检索指向BX寄存器中当前PSP的指针. (功能62h需要DOS 3或更高版本;在DOS 2上,可以使用未记录的功能51h.)

You can use these offsets relative to the pointer in the DS register when the program is first executed. Otherwise, you call INT 21h with AH set to 62h to retrieve a pointer to the current PSP in the BX register. (Function 62h requires DOS 3 or later; on DOS 2, you can use the undocumented function 51h).

Randall Hyde的装配艺术的旧的16位DOS版本可免费在线获得(位于第13章的第13.3节中.图11说明了PSP,随后的两节(13.3.12–13)说明了如何访问和解析命令行参数,包括示例代码.

The old, 16-bit DOS version of Randall Hyde's Art of Assembly is available for free online (in HTML and PDF formats). In Chapter 13, section 13.3.11 describes the PSP, and the following two sections (13.3.12–13) explain how to access and parse command-line parameters, including sample code.

这篇关于如何在16位汇编程序中传递/检索DOS命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆