如何用汇编语言正确处理文件

时间:2019-05-26 14:07:20

标签: windows assembly file-handling x86-16 emu8086

我从互联网上尝试了一些github代码,但是当我在EXE Templete中编写相同的代码时,它不起作用。

data segment

selection db ?

;FILE I/O DATAS
dir1 db "c:\test1", 0
dir2 db "test2", 0
dir3 db "newname", 0

file1 db "c:\test1\file1.txt", 0
file2 db "c:\test1\newfile.txt", 0
file3 db "t1.txt", 0
handle dw ?

text db "lazy dog jumps over red fox."
text_size = $ - offset text
text2 db "hi!"
text2_size = $ - offset text2


ends

;;;;;;;;;;;;;;;;;;;;;;;;;;

; create c:\emu8086\vdrive\C\test1
mov dx, offset dir1
mov ah, 39h
int 21h

; create  c:\emu8086\MyBuild\test2
mov dx, offset dir2
mov ah, 39h
int 21h

; rename directory: c:\emu8086\MyBuild\test2 to c:\emu8086\MyBuild\newname
mov ah, 56h
mov dx, offset dir2   ; existing.
mov di, offset dir3   ; new.
int 21h



; create and open file: c:\emu8086\vdrive\C\test1\file1.txt
mov ah, 3ch
mov cx, 0
mov dx, offset file1
int 21h
jc err
mov handle, ax
; write to file:
mov ah, 40h
mov bx, handle
mov dx, offset text
mov cx, text_size
int 21h
; close c:\emu8086\vdrive\C\test1\file1.txt
mov ah, 3eh
mov bx, handle
int 21h
err:
nop

mov ah,0      ;wait for a key press
int 16h

仿真器说:“目录已存在:                  D:\ Programlar \ emu8086 \ MyBuild \“

但是我没有声明该目录位于MyBuild中,它应该位于vdrive / C中

1 个答案:

答案 0 :(得分:0)

您必须在这些代码行中使用COM文件模板。

.model small

.stack 64

.data

.code

mov ax,@data
mov ds,ax

;rest of the code