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]
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}