Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SECTION .data
- msg1: db "Enter the first number: ", 0
- msg2: db "Enter the second number: ", 0
- options: db "Options:", 0xA, \
- " 1. Command line input", 0xA, \
- " 2. File input (specify name)", 0xA, \
- 0xA, \
- "Please enter your choice: ", 0
- filechoice: db "Enter your filename: ", 0
- formatin: db "%d\n", 0
- filenamein: db "%s", 0
- formatout: db "The GCD of %d and %d is %d.", 0xA, 0
- readmode: db "r", 0
- errormsg: db "Reached the end of the file.", 0xA, 0
- num1: times 4 db 0
- num2: times 4 db 0
- choice: times 4 db 0
- filename: times 100 db 0
- isfilemode: times 4 db 0
- SECTION .text
- global main
- extern scanf
- extern fscanf
- extern printf
- extern fopen
- main:
- push options
- call printf
- push choice
- push formatin
- call scanf
- cmp dword [choice], 2
- jne cmdline
- ;
- mov dword [isfilemode], 1
- push filechoice
- call printf
- push filename
- push filenamein
- call scanf
- push readmode
- push filename
- call fopen
- add esp, 8
- mov esi, eax
- fileinput:
- mov dword [num1], 0
- mov dword [num2], 0
- push num1
- push formatin
- push esi
- call fscanf
- add esp, 12
- push num2
- push formatin
- push esi
- call fscanf
- add esp, 12
- jmp calculate
- cmdline:
- push msg1
- call printf
- push num1
- push formatin
- call scanf
- push msg2
- call printf
- push num2
- push formatin
- call scanf
- calculate:
- mov eax, dword [num1]
- mov ebx, dword [num2]
- test eax, eax
- jz error
- test ebx, ebx
- jz error
- gcd0:
- xor edx, edx
- div ebx
- mov eax, ebx
- mov ebx, edx
- test ebx, ebx
- jnz gcd0
- end:
- push eax
- push dword [num2]
- push dword [num1]
- push formatout
- call printf
- cmp dword [isfilemode], 0
- jne fileinput
- jmp exit
- error:
- push errormsg
- call printf
- exit:
- mov eax, 1
- mov ebx, 0
- int 0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement