Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bits 32 ; assembling for the 32 bits architecture
- ; declare the EntryPoint (a label defining the very first instruction of the program)
- global start
- ; declare external functions needed by our program
- extern exit,scanf,printf ; tell nasm that exit exists even if we won't be defining it
- import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
- import scanf msvcrt.dll ; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
- import printf msvcrt.dll
- ; our data is declared here (the variables needed by our program)
- segment data use32 class=data
- a dd 0
- b dd 0
- nr dd 0
- format_citire db "%u %u %u",0
- format_afisare db "%u",10,0
- ; our code starts here
- segment code use32 class=code
- interval:
- ;functie ce determina daca un nr apartine unui interval inchis (interpretare fara semn)
- ;input: nr, a, b - dword
- ;output: -
- ;post: eax 0 nu; eax 1 da
- mov eax, 1
- mov ebx, [esp+4];nr
- mov ecx, [esp+8];a
- mov edx, [esp+12];b
- cmp ebx,ecx
- jb .nu_e
- cmp ebx,edx
- ja .nu_e
- ret
- .nu_e:
- mov eax, 0
- ret
- start:
- .bucla:
- push dword b
- push dword a
- push dword nr
- push dword format_citire
- call [scanf]
- add esp,4*4
- cmp dword [nr],0
- je .gata
- push dword [b]
- push dword [a]
- push dword [nr]
- call interval
- add esp,4*3
- push eax
- push dword format_afisare
- call [printf]
- add esp, 4*2
- jmp .bucla
- .gata:
- push dword 0 ; push the parameter for exit onto the stack
- call [exit] ; call exit to terminate the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement