bits 32 global start extern exit, printf, scanf, fprintf, fopen, fclose import exit msvcrt.dll import printf msvcrt.dll import scanf msvcrt.dll import fopen msvcrt.dll import fclose msvcrt.dll import fprintf msvcrt.dll segment data use32 class=data file_name db "numbers.txt", 0 format db "%s", 0 access_mode db "w", 0 file_descriptor dd -1 count db 0 n resd 1 segment code use32 class=code start: ;A file name (defined in data segment) is given. ;Create a file with the given name, then read words from the keyboard until character '$' is read from the keyboard. ;Write only the words that contain at least one digit to file. ;Open the file push dword access_mode push dword file_name call [fopen] add esp, 4*2 ;Store the file descriptor mov [file_descriptor], eax ;Check if [fopen] has successfully created the file cmp eax, 0 je end_repeat ; Loop until we read $ ; Check if at least one byte is a digit ; Bag adresa lu n in esi ca sa pot da lodsb mov esi, n repeat: ; Reset counter (in counter o sa fie 1 daca am gasit digit si 0 daca nu) mov byte[count], 0 ; Read n push dword n push dword format call [scanf] add esp, 4*2 ; Compare n to $ cmp dword[n], '$' je end_repeat ; Loop through every byte of the dword repeat2: lodsb ; Daca ascii e intre 48 si 57 adaug 1 in count cmp al, 48 jl repeat2 cmp al, 57 jg repeat2 add byte[count], 1 cmp byte[count], 0 je do_not_write write: ; Write n to the file push esi push dword n push dword [file_descriptor] call [fprintf] add esp, 4*2 pop esi jmp repeat do_not_write: jmp repeat end_repeat: ;Close the file push dword [file_descriptor] call [fclose] add esp, 4 push dword 0 call [exit]