关于把内存最低端1k字节顺写入文件问题
题目是这样的:把内存区域最低端的1k字节作为256个双字,依次把每个双字转化成对应8字节16位的asc码串,顺序存放到文件mem.txt中,每存放8字节的asc码穿,再后面加上回车换行符
我是这样写的,但执行时老出现打印出,在debug里调试也不止到哪个地方出错了,望哪位老师指导指导~谢啦
DSEG SEGMENT
FNAME DB 'D:\MEM.TXT ',0
ERROR1 DB 'CAN,T CREAT FILE ', '$ '
ERROR2 DB 'WRITING ERROT ', '$ '
BUFFER DB 8 DUP(?),0DH,0AH
DSEG ENDS
;
stacksegment
db 256 dup(?)
stackends
CSEGSEGMENT
ASSUME CS:CSEG,DS:DSEG,ss:cseg
START:MOVAX,DSEG
MOVDS,AX
movax,stack
movss,ax
MOVAX,0
MOVES,AX
MOVSI,0
MOVDX,OFFSET FNAME
MOVCX,0
MOVAH,3CH
INT21H
JNCCREA_OK
MOVDX,OFFSET ERROR1
CALLDISPMESS
JMPOVER
CREA_OK:MOVBX,AX
MOVCX,255
NEXT:CALLCONASC1
MOVDX,OFFSET BUFFER
CALLWRITE
JCWERROR2
ADDSI,4
LOOPNEXT
WERROR2:MOVDX,OFFSET ERROR2
CALLDISPMESS
CLOSEF:MOVAH,3EH
INT21H
OVER:MOVAX,4C00H
INT21H
;子程序名:DISPMESS,作用是用来显示字符串,入口参数是dx
;
DISPMESSPROC
MOV AH,9
INT21H
RET
DISPMESSENDP
;子程序名:WRITE,作用是将缓冲区buffer的十个字节写入文件,入口参数dx,bx
;
WRITE PROC
PUSHCX
MOVCX,10
MOVAH,40H
INT21H
POPCX
RET
WRITE ENDP
;子程序名:conasc1,和子程序conasc2一起把一双字es:[si]转换为对应的8字节16进制的asc
;码,并存放到buffer中
CONASC1 PROC
PUSH BX
PUSH CX
MOV DI,3
MOV CX,4
NEXT1:MOV BX,SI
MOVAL,BYTE PTR ES:[BX+DI]
CALLCONASC2
DECDI
LOOPNEXT1
POPCX
POPBX
RET
CONASC1 ENDP
;子程序名:CONASC2,作用协同conasc1完成起功能
;
CONASC2 PROC
PUSHDI
PUSHCX
MOVBX,CX
MOVCL,4
ROLAX,CL
ANDAH,0FH
ADDAH,30H
CMPAH,39H
JBENEXT2
ADDAH,7
NEXT2:SHRAL,CL
ADDAL,30H
CMPAL,39H
JBENEXT3
ADDAL,7
NEXT3:ADDBX,BX
MOVCX,8
SUBCX,BX
XCHGCX,BX
MOVDI,OFFSET BUFFER
MOV[DI+BX],AH
INCBX
MOV[DI+BX],AL
RET
CONASC2ENDP
;
CSEGENDS
END START
[解决办法]
...
pop cx ;*+ 子程开始时有压栈保存, 这里应该出栈恢复吧?
pop di ;*+
MOV [DI+BX],AL
RET
CONASC2ENDP
...