[SOLVED] CS assembly ;; SIEVE.ASMProgram to compute number of primes <= 520000

$25

File Name: CS_assembly_;;_SIEVE.ASMProgram_to_compute_number_of_primes_<=_520000.zip
File Size: 649.98 KB

5/5 - (1 vote)

;; SIEVE.ASMProgram to compute number of primes <= 520000;;using the sieve of Eratosthenes and 80386+ bit;;instructions;;;;Program text from “Assembly Language for the IBM PC Family” by;; William B. Jones, (c) Copyright 1992, 1997, 2001, Scott/Jones Inc.;;INCLUDE PCMAC.INC.MODELSMALL .586.STACK100h.DATAMsg1DB’The number of primes less than $’Msg2DB’ is $’Msg3DB13, 10, ‘$’N EQU 520000 ;PrimesDD0AAAAAAA8h, (N/32 – 1) DUP (0AAAAAAAAh); 0, 1 and multiples of 2 already crossed outCURPRIME EQUedxMULTIPLES EQU ebxPrimeCount EQUedi.CODESieve PROCEXTRN PutDDec : NEAR_Beginsub esi, esimov cx, N/32 ;Number of DWORDs to processmov PrimeCount, 1 ; prime ‘2’ already countedProcessDWords:; We don’t really need two labelsFindNextPrime:bsf eax, [Primes + 4 * esi]jzNextDWord ; No more primes hereinc PrimeCount ;Count Prime; cross out multiplesmov CURPRIME, esi ; Compute CURPRIMEshl CURPRIME, 5 ;= esi * 32add CURPRIME, eax ; + eaxmov MULTIPLES, CURPRIME ; first cross out current primeshl CURPRIME, 1 ; Need only cross out odd multiplesCrossOffMultiples:btr Primes, MULTIPLES ; zero a multipleadd MULTIPLES, CURPRIMEcmp MULTIPLES, NjlCrossOffMultiplesjmp FindNextPrimeNextDWord:inc esidec cxjnz ProcessDWords_PutStr Msg1mov eax, NcallPutDDec_PutStr Msg2mov eax, PrimeCountcallPutDDec_PutStr Msg3_Exit 0Sieve ENDPEND Sieve

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS assembly ;; SIEVE.ASMProgram to compute number of primes <= 520000
$25