Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q70 #64

Open
Anding opened this issue Apr 5, 2018 · 1 comment
Open

Q70 #64

Anding opened this issue Apr 5, 2018 · 1 comment

Comments

@Anding
Copy link

Anding commented Apr 5, 2018

I would like to respectfully suggest an answer for question 70. But there are always better ways, even if this may work, and I'd be grateful for such thoughts.

%assign limit 15			; limit can be no higher than 63 with this code
%assign primestring 0		; bit-string holding our primes 1=prime; 0=composite
%assign n 3
%rep limit
	%assign primeflag 1		; 1 = n is prime; 0 = n is composite		
	%assign i 1
	%rep n/2
		%assign i i+1
		%if n % i = 0
			%assign primeflag 0
			%exitrep
		%endif
	%endrep
	%assign primestring primestring | (primeflag << n)
	%assign n n+1
%endrep
	dq primestring
		
%define isprime(n) (primestring >> n) & 1
; test the function with some outputs
	db 15, isprime(15) ; expect 0
	db 17, isprime(17) ; expect 1

produces

$ nasm -E primes.asm
%line 17+1 primes.asm
 dq 141480

 db 15, (141480 >> 15) & 1 ; expect 0
 db 17, (141480 >> 17) & 1 ; expect 1
@mopp
Copy link

mopp commented May 21, 2018

I have also solved Q70 and sent PR ! (#68)
Your answer is also nice 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants