I've been tasked to create a very basic text editor as a project. I'm currently trying to take an argument on the command line, open the file, read it, etc. The issue I'm having is either I'm not understanding where in memory the contents of the text file are being put, or I do understand but for some reason it's not being put there.
This is my code so far
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
So I'm confused about the read file. I'm a bit unsure what passing something called buffer to dx does. Is it an offset to give? I'm reading in documentation it says DS:DX is the pointer to read buffer. After I run my code, DS is 0700, and DX is 0112. So I look in the memory at 0700:0112 but I don't see the string from my file. It's just all 0's. Did I do something wrong? Am I forgetting something? Or am I not understanding at all where in memory this should be and I'm just looking at the wrong address. This is very frustrating and I'd appreciate the help. Thanks. I'm doing this in emu8086 by the way.