我的任务是创建一个非常基本的文本编辑器作为项目。我正在尝试在命令行上打一个参数,打开文件,阅读它等等。我遇到的问题是我不知道文本文件的内容放在内存的哪个位置,或者我明白,但由于某种原因,它没有被放在那里。
这是我目前的代码
org 100h
jmp start
inHandle dw ?
charAmount dw ?
buff db 100 dup (?)
start :
xor bx, bx
mov bl, [80h] ; length of string from command line
cmp bl, 126 ; check length
ja exit ; if above the length, exit
mov [bx+81h], 0 ; add 0 to the end of the string
;*** open file***
mov ah, 3Dh ; open existing file
mov al, 0 ; read only
mov dx, 82h ; offset of string
int 21h
mov inHandle, ax ; save the handle
jc err ; carry flag set, jump to error block
;**Note i wont include the err code block, it just displays an icon on a video window to tell me it went wrong;
jmp continue
;***I know this continue is probably redundant since it will go here on its own
continue: nop
mov ah, 42h ; Seek end of file
mov bx, inHandle ; Bx takes the handle
mov al, 2 ; end of file plus offset
mov cx, 0 ; Upper order of bytes to move
mov dx, 0 ; Lower order of bytes to move
int 21h
mov charAmount, ax ; store the length in charAmount (My file has 13 for example, so this returned 13 after seeking the end of file)
;*******READ FILE******
mov ah, 3Fh ; Read file
mov bx, inHandle ; Takes the handle
xor cx, cx
mov cx, charAmount ; Counter set to the length
mov dx, offset buff ; set to buffer I defined
int 21h
exit: nop ; (was used for the error code I didnt include)
end start
所以我对阅读文件感到困惑。我有点不确定什么叫做缓冲区到dx。这是一个补偿吗?我正在阅读文档,它说DS:DX是读取缓冲区的指针。运行我的代码后,DS为0700,DX为0112.所以我在0700:0112查看内存,但是我没有看到文件中的字符串。这只是全0。 我做错什么了吗?我忘记了什么吗?或者我完全不了解记忆中应该是什么,我只是看错了地址。这非常令人沮丧,我很感激帮助。谢谢。顺便说一句,我是在emu8086中这样做的。