+ -
当前位置:首页 → 问答吧 → 几行汇编程序,一运行dos就弹出程序崩溃提示框。错在哪里?

几行汇编程序,一运行dos就弹出程序崩溃提示框。错在哪里?

时间:2010-12-24

来源:互联网

masm5编译没有问题,但是一运行就提示错误:

Assembly code

.386
prognam segment use16
assume cs:prognam
org 100h
sub1 proc near
mov dl,33h
mov ah,2h
int 21h
int 20h
sub1 endp
start:
call near ptr sub1
prognam ends
end start



错误信息:
C:\WINDOWS\system32\cmd.exe - helloworld
The NTVDM CPU has encountered an illegal instruction.
CS:0000 IP:0077 OP:f0 37 05 0e 02 Choose 'Close' to terminate the application.

这到底是怎么回事?

作者: yeahcallus1   发布时间: 2010-12-24

把CMD.EXE换成COMMAND.EXE试一下。

作者: asmlearn   发布时间: 2010-12-24

Masm 的语法规定,如果使用了 .386 语句的话,对 dos16 类的程序,必须在此前有 .model 语句来说明内存模式:[code=Assembly.model small
.386
prognam segment use16
assume cs:prognam
org 100h
sub1 proc near
mov dl,33h
mov ah,2h
int 21h
ret
sub1 endp
start:
call near ptr sub1
mov ah, 4ch
int 21h
prognam ends
end start[/code]
另外,使用 int20h 结束程序的话,cs 必须指向 psp,所以这个功能调用往往只对 com 类型的程序合适。还是建议使用 int21h 的 ah=4ch 功能。对子程,还是正常地 ret 返回比较好。

作者: zara   发布时间: 2010-12-24

我知道了,int 20h是com程序结束的时候用的。对于非com程序而言,必须用
mov ah, 4ch
int 21h
来结束程序,否则就弹出我之前的那个错误提示框

但是.386后面的
.model small
似乎不是必需的啊,我去掉了.model small似乎也可以运行。这样会有什么风险么?

谢谢!

作者: yeahcallus1   发布时间: 2010-12-24

你的程序段说明语句里加了 use16 选项,对该段所起的作用和 .model 语句的使用是一样的;这对该段就没有风险了。如果是简单的程序,每个段都加这个说明,有些冗余了,还是用 .model 语句更简洁。

作者: zara   发布时间: 2010-12-24

热门下载

更多