为什么使用“int 21h"在 Assembly x86 MASM 上导致我的程序崩溃? [英] Why does using "int 21h" on Assembly x86 MASM cause my program to crash?

查看:34
本文介绍了为什么使用“int 21h"在 Assembly x86 MASM 上导致我的程序崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的程序接受输入而无需用户按 Enter,所以我尝试了以下操作:

I was trying to make my program accept input without the user having to press enter, so I tried the following:

mov ah,01h
int 21h

但它只是因为一个未处理的异常而使我的程序崩溃.根据我读过的很多内容,这似乎是这样做的方法,那么为什么它不适合我呢?

But it just crashes my program over an unhandled exception. This seems to be the way to do it according to much that I have read, so why isn't it working for me?

现在,我对这门语言还很陌生,所以我仍然不完全理解这段代码的工作原理,所以我也很想知道通过按回车键接受输入并在没有用户的情况下接受输入背后的逻辑是什么必须按回车键.

Now, I am fairly new to this language so I still do not exactly understand the process of how this piece of code works, so I would also appreciate what the logic is behind accepting input by pressing enter and accepting input without the user having to press enter.

顺便说一下,我的操作系统是 Windows.

MY OS is Windows, by the way.

推荐答案

您的代码看起来像 MS-DOS 时代的程序集.VS2010 不支持生成 DOS 可执行文件,现代版本的 Windows(64 位)也不支持运行它们.看起来您正在浏览一些旧书或网站,这是在 80 年代末至 90 年代初写的.在那个时候,装配作为一种工作技能更具有相关性和市场价值.现在不是那么多,尽管一些组装知识不会有什么坏处.

Your code looks like MS-DOS-era assembly. VS2010 doesn't support generating DOS executables, and modern versions of Windows (the 64-bit kind) don't support running them, either. Looks like you were going by some old book or site, one that was written in late 80'es-early 90's. Back at that time, assembly was way more relevant and marketable as a job skill. Not so much these days, although some assembly knowledge won't hurt.

决定你想学习什么.如果您想学习现代汇编(和目标 Windows),请获取一些最新的指导.技术完全不同,int21h 不在其中 :) 如果您确实在使用 DOS 时代的程序集,请使用 DOSBox,并找到一些旧的免费汇编程序.Visual Studio 2010 不会在这里帮助你.生成 16 位可执行文件的 Visual C++ 的最新版本是 v1.5x.

Decide what do you want to learn. If you want to learn modern assembly (and target Windows), get some recent guidance. The techniques are quite different, and int21h isn't among them :) If you're indeed after DOS-era assembly, set up a DOS virtual machine with DOSBox, and find some old free assembler. Visual Studio 2010 won't help you here. The latest version of Visual C++ that generated 16-bit executables was v1.5x.

特别是为什么你的程序会崩溃.Int21h 是 MS-DOS 公开其应用程序接口 (API) 的方式.Windows 不支持 Windows 可执行文件 - 还有其他调用 API 的方法.当您使用 Visual Studio 2010 进行组装时,您最终会得到一个 Windows 可执行文件,而不是 DOS 可执行文件,并且没有生成 DOS 可执行文件的选项.至于 Windows 可执行文件,它们根本不应该调用中断 - 这是崩溃条件.

Specifically why does your program crash. Int21h was how MS-DOS exposed its applciation program interface (API). Windows doesn't support it for Windows executables - there are other ways of invoking the API. When you assemble with Visual Studio 2010, you end up with a Windows executable, not a DOS one, and there's no option to generate a DOS one. As for the Windows executables, they're not supposed to invoke interrupts at all - that's a crash condition.

这篇关于为什么使用“int 21h"在 Assembly x86 MASM 上导致我的程序崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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