Hi! I am trying to learn Assembly and cant seem to find the reason why it doesnt work properly… it should read numbers from trial.txt file and show them into trial2.txt file
bits 32
global start
extern exit, fread, fprintf, fopen, fclose
import exit msvcrt.dll
import fopen msvcrt.dll
import fclose msvcrt.dll
import fread msvcrt.dll
import fprintf msvcrt.dll
segment data use32 class=data
reading_file db "trial.txt", 0
access_mode1 db "r", 0
printing_file db "trial2.txt", 0
access_mode2 db "w", 0
read_descriptor resd 1
print_descriptor resd 1
number resb 1
print_format db "%d", 0
segment code use32 class=code
start:
push dword access_mode1
push dword reading_file
call [fopen]
add esp, 4*2
cmp eax, 0
je end_of_code
mov [read_descriptor], eax
push dword access_mode2
push dword printing_file
call [fopen]
add esp, 4*2
cmp eax, 0
je end_of_code
mov [print_descriptor], eax
read_loop:
push dword [read_descriptor]
push dword 1
push dword 1
push dword number
call [fread]
add esp, 4*4
cmp eax, 0
je end_of_code
push dword number
push dword print_format
push dword [print_descriptor]
call [fprintf]
add esp, 4*3
jmp read_loop
end_of_code:
push dword [read_descriptor]
call [fclose]
add esp, 4
push dword [print_descriptor]
call [fclose]
add esp, 4
push dword 0
call [exit]