1. Title: Find the Top 100 primes.
2. Requirements: Identify and display values for the first 100 primes, requiring 5 primes per line.
The C + + code that asks for 100 primes is listed first
Then it is relatively easy to write assembler code according to C + + code.
1//the program was to find the primes from 1 to with C + + 2//by karllen 3//time:05/19/2014 4 5 #include <iost ream> 6 int main (void) 7 {8 9 int number = 2;10 int flag = 1;11 while (number<=100) {13
int i = 2;14 while (I<=number) ( number%i==0) + break;19 }20 Else21 { ++i;23 }24 }25 if (i==number) [std::cout<<] number<< ""; if (flag%5==0) { std::cout<<std::endl;32 }33 ++flag; }35 ++number;36 }37 System ("pause"); return 0;39}
The assembly code is as follows:
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 18; Reserve storage for Data19 mm DWORD? DWORD Flai DWORD? Flaj DWORD promot BYTE "The programer is to find all primes from 1 to", cr,lf,024 answer byte "Al L Prime is "cr,lf,0" CRLF byte cr,lf,0 value byte one-by-one DUP (?) 28 29. CODE; Start of main program Code30 _start:31 output promot32 mov mm,533 mov number,234 mov ecx,235 mov flaj,0; counting, unificationCount the number of DOWHILE:37 mov flai,238 mov ecx,number39 cmp ecx,10040 JG endWhile41 dofindwhile:42 cmp flai,ecx43 JE findprime EAX,ECX45 mov cdq46 idiv flai47 CMP edx,048 JE EndFindWhile49 Inc. flai51 jmp Dofindwhile findprime:54 mov eax,flaj55 cdq56 idiv mm57 cmp edx, 058 jne Printnocrlf Output crlf60 printnocrlf:61 Dtoa value,ecx62 Output VALUE63 Inc flaj64 65 ENDFINDWHILE:66 Inc number67 JMP doWhile68 endwhile:69 70 INVOKE exitprocess, 0; Exit with return code 071 _start; Make entry point public73 the END; End of source code
Test results:
Assembly language-Judging primes: finding primes within the first 100