从汇编文件中读取文件时为什么会出现打开错误?

时间:2013-12-19 12:57:05

标签: file assembly error-handling x86 x86-16

我正在尝试从文件中读取一个字符串并将其打印在屏幕上,但是在打开文件时我总是遇到错误。为什么会这样?代码或文件有什么问题? PS:该文件与.asm文件位于同一文件夹中。

ASSUME cs: code, ds:data
data SEGMENT
        inputFile db "D:\AC\input.txt", 0
        openingError db 'An error has occured at opening the file!$'
        readingError db 'An error has occured at reading the file!$'
        s1 db 10 dup(?)
        ls db 0
        handle dw ?
data ENDS
code SEGMENT
start:
       mov ax,data
       mov ds,ax
                 ;open the file
       mov ah, 3dh
       mov al, 0
       mov dx, offset inputFile
       int 21h
       mov handle, ax
       jc openError
                ;read 10 bytes from the file into s1
       mov ah, 3fh
       mov bx, handle
       mov cx, 10
       mov dx, offset s1
       int 21h
       jc readError

       openError:
            mov ah, 09h
            mov dx, offset openingError
            int 21h
            jmp the_end

      readError:
            mov ah, 09h
            mov dx, offset readingError
            int 21h
            jmp the_end

            ;close file
     mov ah, 3eh
     mov bx, handle
     int 21h
            ;print string on the screen
     lea dx, s1
     mov ah, 09h
     int 21h

     the_end:
     mov ax,4C00h
     int 21h
code ENDS
END start

1 个答案:

答案 0 :(得分:1)

您是否忘记了实际打开文件? int 21在哪里?

mov ah, 3dh
mov al, 0
lea dx, inputFile
int 21h
jc openingError
mov handle, ax