为什么每当我尝试使用中断时,我的 masm32 程序就会崩溃?

发布于 2024-08-24 02:21:55 字数 815 浏览 9 评论 0 原文

这是代码:

.386 ;target for maximum compatibility
.model small,stdcall ;model
.code
    main:
        int 20h
    END main

结果: http://img705.imageshack.us/img705/3738/ resultom.png

“test.exe 已停止工作” - 当到达中断时始终正确。

这是我尝试使用的中断。 它应该简单地退出程序。我尝试过的其他方法包括字符输入/输出等。没有任何效果。

我使用的是 Windows 7,使用 masm32 和 WinAsm IDE。

有很多很酷的事情似乎我应该能够用中断来做...但是,每当我尝试使用中断时它就会崩溃 - 总是以同样的方式。

这似乎相关并且可能有用:DOS Interrupt in masm x86 assembly crashing

......但我还没有真正能够从中弄清楚任何事情。

有什么建议吗?

Here's the code:

.386 ;target for maximum compatibility
.model small,stdcall ;model
.code
    main:
        int 20h
    END main

Result: http://img705.imageshack.us/img705/3738/resultom.png

"test.exe has stopped working" - always right when it reaches the interrupt.

This is the interrupt I'm trying to use. It should simply exit the program. Others I've tried include character input/output, etc.. Nothing works.

I'm on windows 7, using masm32 with the WinAsm IDE.

There are so many cool things it seems I should be able to do with interrupts... however, it crashes whenever I try to use an interrupt - always the same way.

This seems related and possibly useful: DOS Interrupt in masm x86 assembly crashing

...but I haven't really been able to figure anything out from it.

Any suggestions?

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

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

发布评论

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

评论(4

终止放荡 2024-08-31 02:21:55

是的。这种性质的中断是专门针对 MS-DOS 的,因此在 Windows ME 和以前的版本中可以工作,但不能在 NT 体系结构上工作,除非在 DOS 模拟器 (command.com) 下。我不知道 Windows 7 是否仍然附带此功能 - 我知道 x64 版本的 Windows 默认情况下没有它。

如果您正在编写 Native NT 应用程序(如果您不知道它是什么,则不太可能这样做,但如果您想了解详情,请查看 MSDN 上 Mark Russinovich 的博客),这里有一个 NT 中断列表及其相应的函数:http://www.ctyme.com/intr/rb-4249。 htm

除此之外,您想要调用 Win32 API 中的函数: http://msdn.microsoft.com/en-us/library/aa383749%28VS.85%29.aspx

编辑:在该代码示例中,您没有指定任何中断选项,通过寄存器完成。哦,只要你为 DOS 而不是 Windows 进行汇编,你就可以让它工作。如果您使用链接器,您可能会创建一个 Windows PE 可执行文件。但是,如果您使用的是 64 位 Windows,正如我所说,请不要尝试。

您可以做的一件事是安装虚拟机系统,例如 VirtualBox 或 VMware,然后安装 FreeDOS。它根本不应该占用太多内存,并且可以让您自由地尝试汇编/dos。

Yep. Interrupts of this nature are specifically for MS-DOS, and as such worked in Windows ME and previous but will not work on the NT architecture except under the DOS emulator (command.com). I have no idea if this still ships with Windows 7 - I know x64 versions of Windows don't have it by default.

If you're writing Native NT Apps (you're unlikely to be doing this if you don't know what one is, but if you want to find out have a look at Mark Russinovich's Blog at MSDN) here's a list of NT interrupts and their corresponding functions: http://www.ctyme.com/intr/rb-4249.htm

Other than that, you want to call a function in the Win32 API: http://msdn.microsoft.com/en-us/library/aa383749%28VS.85%29.aspx

Edit: and in that code sample, you've not specified any options for the interrupt, done through the registers. Oh and you could get it working provided you assemble for DOS and not for Windows. If you use a Linker you'll likely be creating a Windows PE executable. However, if you're on 64-bit Windows, as I've said, don't try.

One thing you could do is install a virtual machine system such as VirtualBox or VMware and then install FreeDOS. It shouldn't take up much RAM at all and will let you experiment with assembly/dos freely.

亣腦蒛氧 2024-08-31 02:21:55

除了@ninefingers 的出色答案之外 - 我可以添加 int 20H 仅适用于 16 位程序吗?并且永远不能被 .exe 使用,

请参阅此处

In addition to @ninefingers excellent answer - can I add the int 20H will only work for 16 bit programs. And can never be used by a .exe

See here.

这个俗人 2024-08-31 02:21:55

你必须小心编程中断。如果您处于 RealMode(16 位)以外的任何模式,则通常无法在 CPU 级别达到中断。中断描述符表必须可用于索引中断向量表。

IVT 位于 Ring 0,您可以直接、不受阻碍地访问硬件(CPU、视频等)。所有应用程序都将在 Ring 3 中运行(包括操作系统)。 IDT 包含 IVT 的索引。这样做是为了保护您的硬件。如果您想从操作系统访问中断,您需要确保它们可用于您的 32 位源。

You have to be careful programming interrupts. If you are in anything other than RealMode (16-bit), you cannot typically reach the interrupts at the CPU level. An Interrupt Descriptor Table must be available for indexing the Interrupt Vector Table.

The IVT sits in Ring 0, where you have direct, unhindered access to hardware (CPU, Video, etc.) All applications will be running in Ring 3 (OS included). The IDT contains indexes to the IVT. This is done to protect your hardware. If you want to access interrupts from the OS, you will need to ensure that they are available to your 32-bit source.

以为你会在 2024-08-31 02:21:55

在 32 位 Windows 下,有一个虚拟 86 模式,通过这种模式,可以使用 DOS 中较旧的 RM 软件中断,因为 Windows 模拟了其中的很多中断。
此外,如果我们正确安装了图形卡的驱动程序,则可以使用一些 int 10h 软件中断,例如在我们的卡上获取 vesabios 的 vesamodelist。是的,它是一个仿真,但它从我们的卡中获取真实的模式编号及其环境参数,即使在 Windows 下不可能更改所有这些 vesa 模式。

16 位 DOS 应用程序也可以使用 *.exe 格式,但这是 MZ 格式,而不是 PE 格式。

短剑

Under 32 bit Windows there is a virtual 86 mode and with this mode it is possible to use the older RM-software interrupts from DOS, because Windows emulate a lot of them.
Also after if we have properly installed a driver for our grafikcard, then it is possible to use some of the int 10h software interupts, example for to get the vesamodelist of a vesabios on our card. Yes it is an emulation, but it get the real modenumbers and their enviroment parameters from our card, also if the changing to all those vesamodes is impossible under windows.

A 16 bit DOS application can also use the *.exe-format, but this is a MZ-format, not a PE-format.

Dirk

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