此代码是从现有文件中读取我的名字,然后创建一个新文件并将其写入。由于某些原因,新文件中的前两个字符是垃圾(\ 00,\ 00)。当我更改缓冲区长度时,它似乎并没有改变,除了长度超过我的名字+2的缓冲区长度最后会产生man'\ 00'。
section .data
inFile db 'fileIN.txt', 0
outFile db 'fileOUT.txt', 0
;length equ $-msg
msgA db 'File Read', 10, 0
lenMsgA equ $-msgA
section .bss
fileHandle_out resb 1
fileHandle_in resb 1
buff resb 10
section .text
global main ;declare for gcc
main:
;open fileIN.txt
mov eax, 5
mov ebx, inFile
mov ecx, 0 ;read only
int 80h
mov [fileHandle_in], eax ; stores file handle invariable
;read from fileIN.txt
mov eax, 3
mov ebx, [fileHandle_in]
mov ecx, buff
mov edx, 10
int 80h
;message to CLI
mov eax, 4
mov ebx, 1
mov ecx, msgA
mov edx, 10
int 80h
;close fileIn.txt
mov eax, 6
mov ebx, [fileHandle_in]
int 80h
;create fileOUT.txt
mov eax, 8
mov ebx, outFile
mov ecx, 0444 ;write
int 80h ; call kernel
mov [fileHandle_out], eax ; mov file handle to variable
;write to fileOut.txt
mov eax, 4
mov ebx, [fileHandle_out]
mov ecx, buff
mov edx, 10
int 80h
;close fileOUT.txt
mov eax, 6
mov ebx, [fileHandle_out]