从键盘读取文件名并打开此文件 [英] Read File Name from Keyboard and Open This File

查看:91
本文介绍了从键盘读取文件名并打开此文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的目的是从键盘获取文件名,然后打开并在asm中写入此文件。实际上这是我第一次对这种语言感兴趣。



这是我的代码

Hi everyone,

My purpose is get file name from keyboard then open and write this file in asm. Actually it is first time i interested in this language.

Here is my code

.MODEL SMALL
        .DATA

                MSG  DB  0DH,0AH, ' ENTER THE FILE NAME :-----> :  $'
                STR1 DB  255 DUP('$')
                Buffer DB 10 dup(0)
                Handle dw ?
               ; ONE  DB ?
          .CODE

BEGIN:
          MOV AX,@DATA
          MOV DS,AX

          LEA DX,MSG
          MOV AH,09H
          INT 21H

          LEA SI,STR1
          MOV AH,01H

READ:
          INT 21H
          MOV [SI],AL
          INC SI
          CMP AL,0DH
          JNE READ

DISPLAY:
          LEA DX,STR1
          MOV AH,09H
          INT 21H
OPENFILE:
                mov     ah, 3dh         ;Open the file
                mov     al, 0           ;Open for reading
                mov     dx, STR1        ;Presume DS points at filename
                int     21h
                jc cant_open
                mov handle, ax              ; segment.

READFILE:
                mov     ah,3fh              ;Read data from the file
                mov     bx, handle
                lea     dx, offset Buffer      ;Address of data buffer
                mov     cx, 10         ;Get file handle value
                int     21h

EOF:
                mov bx, handle
                mov     ah, 3eh         ;Close file
                int     21h

cant_open:

 MOV AX, 4C00H
 INT 21H


        .EXIT
END BEGIN


I am getting A2070 error on "mov     dx, STR1        ;Presume DS points at filename" line. Could you help me?

推荐答案

'
STR1 DB 255 DUP('


')
缓冲区 DB 10 dup(0)
句柄 dw
; ONE DB?
.CODE

开始:
MOV AX ,@ DATA
MOV DS AX

LEA DX MSG
MOV AH ,09H
INT 21H

LEA SI ,STR1
MOV AH ,01H

READ:
INT 21H
MOV [ SI ], AL
INC SI
CMP AL ,0DH
JNE READ

显示:
LEA DX ,STR1
MOV AH ,09H
INT 21H
OPENFILE:
mov ,3dh ; 打开文件
mov al 0 ; 打开阅读
mov dx ,STR1 ; 在文件名中设定DS点数
int 21h
< span class =code-keyword> jc cant_open
mov handle, ax ; segment。

READFILE:
mov ,3fh ; 从文件中读取数据
mov bx ,处理
lea dx ,偏移缓冲区; 数据缓冲区的地址
mov cx 10 ; 获取文件句柄值
int 21h

EOF:
mov bx ,处理
< span class =code-keyword> mov ah ,3eh ; 关闭文件
int 21h

cant_open:

MOV AX ,4C00H
INT 21H


.EXIT
END BEGIN


我在 <上获得A2070错误/ span> mov dx,STR1;假定DS指向文件名行。你能帮帮我吗?
') Buffer DB 10 dup(0) Handle dw ? ; ONE DB ? .CODE BEGIN: MOV AX,@DATA MOV DS,AX LEA DX,MSG MOV AH,09H INT 21H LEA SI,STR1 MOV AH,01H READ: INT 21H MOV [SI],AL INC SI CMP AL,0DH JNE READ DISPLAY: LEA DX,STR1 MOV AH,09H INT 21H OPENFILE: mov ah, 3dh ;Open the file mov al, 0 ;Open for reading mov dx, STR1 ;Presume DS points at filename int 21h jc cant_open mov handle, ax ; segment. READFILE: mov ah,3fh ;Read data from the file mov bx, handle lea dx, offset Buffer ;Address of data buffer mov cx, 10 ;Get file handle value int 21h EOF: mov bx, handle mov ah, 3eh ;Close file int 21h cant_open: MOV AX, 4C00H INT 21H .EXIT END BEGIN I am getting A2070 error on "mov dx, STR1 ;Presume DS points at filename" line. Could you help me?


这看起来还行。



要打开文件,你需要 MOV 0x3d (打开文件)到 ah 寄存器, MOV DX 寄存器的(指向)文件名,以及 MOV 访问模式位掩码( 0x00 ==只读)到 al 寄存器,然后调用 INT errupt 0x21



对不起,我没有'没有使用MASM,但我猜测 STR1 不是有效指针。
This looks OK.

To open a file you need to MOV 0x3d (open file) to the ah register, MOV the (pointer to the) filename to the DX register, and MOV the access mode bitmask (0x00 == read-only) to the al register, then call INTerrupt 0x21.

Sorry, I haven''t used MASM, but I''m guessing that STR1 is not a valid pointer.


这篇关于从键盘读取文件名并打开此文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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