我正在用汇编语言写一个项目,我有一个问题,从一个文件中读取并在屏幕上打印它所写的内容。
我取了部分代码(这是读取和打印的部分),我试图修复它并重新编写它,我仍然有一个问题。
如果有人能帮我我会更开心
这是代码:
org 100h
mov ah,0ah
mov dx,offset place
int 21h ; getting the place(directory) of the file
mov si,offset place
inc si
mov dx,[si]
inc dx
mov si,dx
mov [si],0
mov ah,02
mov dl,13
int 21h
mov ah,02
mov dl,10
int 21h
mov ah,0ah
mov dx,offset filename
int 21h ;getting the file name
mov si,offset filename
inc si
mov dx,[si]
inc dx
mov si,dx
mov [si],0
mov ah,02
mov dl,13
int 21h
mov ah,02
mov dl,10
int 21h
call gotoplace ;go to the place of the file
;------------------
call openfile ;open the file
;------------------
mov ah,3fh
mov si,offset filehandle
mov bx,[si] ;move file adress to bx
mov cx,40000 ;numbers of bytes to read
mov dx,offset buff ;pointer to read buffer
int 21h
mov si,offset filesize ;move si pointer to filesize
mov [si],ax ;move to filesize how many bytes read
;------------------
;writing on the screen ->
mov bx,offset buff ;move bx pointer of buffer
mov si,offset filesize
mov cx,[si] ;move cx how many to write
startwrite:
mov ah,2
mov dl,[bx] ;move dl letter in place [bx]
int 21h
inc bx
dec cx
jnz startwrite
proc gotoplace
mov ah,3bh
mov dx,offset place ;move offset place to dx
add dx,2
int 21h
ret
endp gotoplace
proc openfile
mov ah,3d
mov al,2 ;open for read / write
mov dx,offset filename ;move dx offset filename
add dx,2
int 21h
;--------------------------
mov si,offset filehandle ;move offset filehandle(location in the memory) to si
mov [si],ax ;move the file adress to the 'filehandle'(location in the meory'
ret
endp openfile
ret
filehandle dd ?
filename db 40
db 42 dup (0)
place db 40
db 42 dup (0)
buff db 40000 dup (0)
filesize dd ?
这是读取和写入的函数:
proc readprint
call gotoplace ;go to the place of the file
;------------------
call openfile ;open the file
;------------------
mov ah,3fh
mov si,offset filehandle
mov bx,[si] ;move file adress to bx
mov cx,40000 ;numbers of bytes to read
mov dx,offset buff ;pointer to read buffer
int 21h
mov si,offset filesize ;move si pointer to filesize
mov [si],ax ;move to filesize how many bytes read
;------------------
mov ah,2
mov bh,0
mov dh,1
mov dl,1
int 10h ;Move the cursor to the start of the page
;writing on the screen ->
mov bx,offset buff ;move bx pointer of buffer
mov si,offset filesize
mov cx,[si] ;move cx how many to write
startwrite:
mov ah,2
mov dl,[bx] ;move dl letter in place [bx]
int 21h
inc bx
dec cx
jnz startwrite
;------------------
ret
endp readprint
1条答案
按热度按时间lvjbypge1#
以下是代码中的问题:
proc openfile
中,您使用的数字3d应该是3dH。mov dx,[si]
,这是一个错误,因为字符串(由[si]
指向)的长度是一个字节,而您将两个字节移动到dx
。cx
中使用此数字来写入屏幕,这就是它必须是DW的原因。还有另一个问题,这不是你的错。EMU8086在打开文件时有一个问题。EMU8086在子目录
c:\emu8086\mybuild
中运行程序,有时EMU8086不允许打开子目录mybuild
之外的文件。为了使用EMU8086中的文件,请将它们存储在c:\emu8086\mybuild
中。接下来是你的代码。我修正了问题,并注解了修改子目录的代码,修改由箭头〈========指出: