Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .data
- scanffmt: db "%d %d %d", 0
- printnfmt: db "%d ", 0
- printlnfmt: db "", 10, 0
- section .bss
- inputm: resd 1
- inputn: resd 1
- inputt: resd 1
- anscnt: resd 1
- maxnum: resd 1
- section .text
- global isPrime
- global asmMain
- extern scanf
- extern printf
- isPrime:
- push rbp
- mov rbp, rsp
- mov ecx, 2
- sqrt:
- mov [inputm], edi
- fild dword [inputm]
- fsqrt
- fistp dword [inputm]
- mov edi, [inputm]
- primeloop:
- cmp edi,ecx
- jl endwithtrue
- mov edx, 0
- mov eax, ebx
- div ecx
- cmp edx, 0
- je endwithfalse
- inc ecx
- jmp primeloop
- endwithtrue:
- mov eax, 1
- pop rbp
- ret
- endwithfalse:
- mov eax, 0
- pop rbp
- ret
- asmMain:
- push rbp
- mov rbp, rsp
- mov dword [anscnt], 0
- scan:
- ;SYSTEMV AMD64 ADI
- mov ecx, inputt
- mov edx, inputn
- mov esi, inputm
- mov edi, scanffmt
- xor eax, eax
- call scanf
- minmax:
- mov eax, [inputm]
- mov ebx, [inputn]
- cmp eax, ebx
- jle set_n_as_max
- set_m_as_max:
- mov eax, [inputm]
- mov [maxnum], eax
- mov ebx, [inputn]
- jmp loophead
- set_n_as_max:
- mov eax, [inputn]
- mov [maxnum], eax
- mov ebx, [inputm]
- loophead:
- mov edi, ebx
- call isPrime
- cmp eax, 1
- je print
- jmp looptail
- print:
- inc dword [anscnt]
- mov esi, ebx
- mov edi, printnfmt
- call printf
- mov edx, 0
- mov eax, [anscnt]
- div dword [inputt]
- cmp edx, 0
- je println
- jmp looptail
- println:
- mov edi, printlnfmt
- call printf
- looptail:
- inc ebx
- cmp ebx, [maxnum]
- jle loophead
- endprint:
- mov edi, printlnfmt
- call printf
- mov esi, [anscnt]
- mov edi, printnfmt
- call printf
- end:
- pop rbp
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement