当前位置: 代码迷 >> 汇编语言 >> 汇编。程序正常执行到最后,结束前系统提示:“NTVDM遇到一个硬件异常”
  详细解决方案

汇编。程序正常执行到最后,结束前系统提示:“NTVDM遇到一个硬件异常”

热度:8856   发布时间:2013-02-26 00:00:00.0
汇编。程序正常执行到最后,结束前系统提示:“NTVDM遇到一个硬件错误”
代码如下:
(调试过了。一切正常。只是到了最后,执行完MOV AH,4CH,INT 21H,RET之后弹出“NTVDM遇到一个硬件错误”。)
(还有一个有趣的现象:将MAX设为1至5,则不弹出错误。)
(汇编代码是简单地将C++代码翻译而成的。)
望有大侠指点!急!
Assembly code
;#include<iostream>;using namespace std;ASSUME CS:CODE,DS:DATA,SS:STACKSTACK SEGMENT STACK        DB 256 DUP(?)STACK ENDS;;const int MAX = 10;//MAX>1!MAX = 20;int line[MAX] = {1};DATA SEGMENTLINE    DW MAX DUP(1)DATA ENDS;CODE SEGMENTSTART:;void main();{MAIN PROC FAR;    int row = 1;        MOV CX,1;    line[0] = 1;        MOV LINE[0],CX;    Body:BODY:;        if(row==MAX)goto Body_;        CMP CX,MAX        JZ BODY_;        int i=0;        MOV BX,0;        Spaces:SPACES:;            if(i==MAX-row)goto Spaces_;        MOV AX,BX        ADD AX,CX        CMP AX,MAX        JZ SPACES_;            cout<<'\t';        MOV AH,02H        MOV DL,9        INT 21H;            i++;        INC BX;            goto Spaces;        JMP SPACES;        Spaces_:SPACES_:;;        int j=0;        MOV BX,0;        Values:VALUES:;            if(j==row)goto Values_;        CMP BX,CX        JZ VALUES_;            cout<<line[j];        MOV SI,BX        SHL SI,1        MOV AX,LINE[SI]        CALL SHOW;            cout<<'\t'<<'\t';        MOV AH,02H        MOV DL,9        INT 21H        INT 21H;            j++;        INC BX;            goto Values;        JMP VALUES;        Values_:VALUES_:;;        cout<<'\n';        MOV AH,02H        MOV DL,10        INT 21H;;        line[row]=1;        MOV SI,CX        SHL SI,1        MOV LINE[SI],1;;        int k=row-1;        MOV BX,CX        DEC BX;        Assigns:ASSIGNS:;            if(k==0)goto Assigns_;        CMP BX,0        JZ ASSIGNS_;            line[k]+=line[k-1];        MOV SI,BX        SHL SI,1        MOV AX,LINE[SI-2]        ADD LINE[SI],AX;            k--;        DEC BX;            goto Assigns;        JMP ASSIGNS;        Assigns_:ASSIGNS_:;;        row++;        INC CX;        goto Body;        JMP BODY;    Body_:BODY_:;;    int l=0;        MOV BX,0;    Foot:FOOT:;        if(l==row)goto Foot_;        CMP BX,CX        JZ FOOT_;        cout<<line[l];        MOV SI,BX        SHL SI,1        MOV AX,LINE[SI]        CALL SHOW;            cout<<'\t'<<'\t';        MOV AH,02H        MOV DL,9        INT 21H        INT 21H;        l++;        INC BX;        goto Foot;        JMP FOOT;    Foot_:;FOOT_:            MOV AH,4CH        INT 21H        RET;}MAIN ENDP        ; 递沟地以10进中问狡输出AX; 方法很简单,就是求出余数,然后 AX = AX / 10; AX = 0时退出,开始逆序输出求出的各位余数SHOW PROC NEAR        PUSH AX        PUSH BX        PUSH DX        MOV BX,10        CALL _SHOW        POP DX        POP BX        POP AX        RETSHOW ENDP        _SHOW PROC NEAR        CMP AX,0        JZ RETURN        DIV BL        PUSH AX        AND AX,00FFH        CALL _SHOW        POP DX        MOV DL,DH        OR DL,30H        MOV AH,2        INT 21HRETURN:    RET_SHOW ENDPCODE ENDSEND START


------解决方案--------------------------------------------------------
没给 ds 赋值,将 psp 区给乱写了。应该在程序的开头加上:
Assembly code
  mov  ax, data  mov  ds, ax