Assembly language-sub-function finding prime number

Source: Internet
Author: User

1. Title: Find all the primes within the 100~200.

2. Requirements: To find and display the value of all primes in the 100~200, which requires 5 primes per line.

3. The algorithm for determining the prime number is implemented by subroutines, and the subroutine has different return parameters after determining whether the numbers are primes.

 1; Example assembly Language Program--adds, numbers 2; Author:karllen 3; Date:revised 05/2014 4 5.386 6. MODEL FLAT 7 8 exitprocess PROTO NEAR32 stdcall, Dwexitcode:dword 9 INCLUDE io.h; Header file for input/output11-cr EQU 0DH; Carriage return character13 Lf EQU 0ah; Line Feed14 15. STACK 4096; Reserve 4096-byte stack16 17. DATA;      Reserve storage for Data18 Promot BYTE "The program was to find primes from + to", cr,lf,019 CMM Byte "", 020 CRLF byte cr,lf,021 number DWORD? Flai DWORD? TE one-to-one DUP (?) public _start; Make entry point public 25. CODE;        Start of main program Code26 _start:27 output PROMOT28 mov number,9929 mov flai,030 DOFIRSTWHILE:32 Inc NUMBER33 CMP number,20034 JG ENDFIRSTWHILE35 mov eax,number36 push eax37                      Call FindPrime38 add esp,439; eax,041 CMP                      Je endSecond42 inc flai43 Dtoa VALUE,NUMBER44 Output value45 output CMM46 mov eax,flai47 mov EC                         x,548 cdq49 idiv ecx50 cmp edx,051 Je printCrlf52 endsecond:54 jmp dofirstwhile              printcrlf:56 Output crlf57 jmp doFirstWhile58 Endfirstwhile:60 INVOKE exitprocess, 0; Exit with return code 061 findprime PROC NEAR3264 push EBP65              mov ebp,esp66 ebx,268 mov eax,[ebp+8]69                     MOV ecx,eax70 docuwhile:71 cmp ebx,ecx72 JE found73                     mov eax,ecx74 cdq75 idiv ebx76 cmp edx,077                     Je noFound78 inc ebx79 jmp docuWhile80 found:81 mov eax,182 jmp endcuWhile83 nofound:84 mov eax,0 8                             5 endcuwhile:86 pop ebp87 ret88 findprime ENDP89 END ; End of source code

Test results

Assembly language-sub-function finding prime number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.