【发布时间】:2021-12-29 11:05:53
【问题描述】:
这是我将文本写入 txt 文件的方式。我使用了外部的 fclose、fopen、fprintf 函数。我的问题是如何分别引用每个字符,如果需要如何修改某些字符?
global start
extern exit, fopen, fclose, fprintf, printf
import exit msvcrt.dll
import fclose msvcrt.dll
import fopen msvcrt.dll
import fprintf msvcrt.dll
import printf msvcrt.dll
segment data use32 class=data
; ...
name_file db "newfile.txt",0
descriptor_file dd -1
mod_acces db "w",0
text db "Every letter and n9mber should be written out separetely.",0
error_message db "Something went wrong",0
segment code use32 class=code
start:
; ... eax= fopen(name_file,mod_acces)
push dword mod_acces
push dword name_file
call [fopen]
add esp, 4*2
cmp eax, 0
JE message_error
mov [descriptor_file], eax
; eax = fprintf(descriptor_file, text)
push dword text
push dword [descriptor_file]
call [fprintf]
add esp,4*2
push dword [descriptor_file]
call [fclose]
add esp,4
jmp end
message_error:
push dword error_message
call [printf]
add esp,4
end:
; exit(0)
push dword 0 ; push the parameter for exit onto the stack
call [exit] ; call exit to terminate the program ```
【问题讨论】: