题目是这样的:把内存区域最低端的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
;
stack segment
db 256 dup(?)
stack ends
CSEG SEGMENT
ASSUME CS:CSEG,DS:DSEG,ss:cseg
START: MOV AX,DSEG
MOV DS,AX
mov ax,stack
mov ss,ax
MOV AX,0
MOV ES,AX
MOV SI,0
MOV DX,OFFSET FNAME
MOV CX,0
MOV AH,3CH
INT 21H
JNC CREA_OK
MOV DX,OFFSET ERROR1
CALL DISPMESS
JMP OVER
CREA_OK:MOV BX,AX
MOV CX,255
NEXT: CALL CONASC1
MOV DX,OFFSET BUFFER
CALL WRITE
JC WERROR2
ADD SI,4
LOOP NEXT
WERROR2:MOV DX,OFFSET ERROR2
CALL DISPMESS
CLOSEF: MOV AH,3EH
INT 21H
OVER: MOV AX,4C00H
INT 21H
;子程序名:DISPMESS,作用是用来显示字符串,入口参数是dx
;
DISPMESS PROC
MOV AH,9
INT 21H
RET
DISPMESS ENDP
;子程序名:WRITE,作用是将缓冲区buffer的十个字节写入文件,入口参数dx,bx
;
WRITE PROC
PUSH CX
MOV CX,10
MOV AH,40H
INT 21H
POP CX
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
MOV AL,BYTE PTR ES:[BX+DI]
CALL CONASC2
DEC DI
LOOP NEXT1
POP CX
POP BX
RET
CONASC1 ENDP
;子程序名:CONASC2,作用协同conasc1完成起功能
;
CONASC2 PROC
PUSH DI
PUSH CX
MOV BX,CX
MOV CL,4
ROL AX,CL
AND AH,0FH
ADD AH,30H
CMP AH,39H
JBE NEXT2
ADD AH,7
NEXT2: SHR AL,CL
ADD AL,30H
CMP AL,39H
JBE NEXT3
ADD AL,7
NEXT3: ADD BX,BX
MOV CX,8
SUB CX,BX
XCHG CX,BX
MOV DI,OFFSET BUFFER
MOV [DI+BX],AH
INC BX
MOV [DI+BX],AL
RET
CONASC2 ENDP
;
CSEG ENDS
END START
------解决方案--------------------------------------------------------
...
pop cx ;*+ 子程开始时有压栈保存, 这里应该出栈恢复吧?
pop di ;*+
MOV [DI+BX],AL
RET
CONASC2 ENDP
...