【发布时间】:2012-07-14 16:26:22
【问题描述】:
;the code read 4 bytes from file and print it on screen
bits 16
org 100h
jmp start
filename db 'example.file',0
handle dw 0
buffer db 255
start:
mov ah,3dh
mov al,0
mov dx,filename
int 0x21
mov handle,ax
mov ah,3fh
mov cx,4
mov dx,buffer
mov bx,handle
int 21h
mov dx,buffer
add dx,ax
mov bx,dx
mov byte[bx],'$'
mov dx,buffer
mov ah,9
int 21h
mov ah,4ch
int 21h
【问题讨论】:
-
代码正在打印垃圾。我认为问题出在指令 mov handle, ax .... 但我无法弄清楚。
-
使用
mov [handle],ax可能会更好。然后是mov BX,[handle]。我们必须要么获取内存地址,要么获取存储在该地址的值。 -
单步执行代码。是否将正确的数据读入缓冲区?
-
DOS 程序只能使用 8.3 文件名。
example.file超出了扩展名的最大 3 个字符。您确定您的代码不会因此而无法打开文件吗?打开函数返回失败吗?