write a program that generates all prime numbers between 2 and 100 assembly language code example
Example 1: Write a program that prints all prime numbers less than 1,000,000
public class Main {
public static void main(String[] args) {
for (int i = 2; i < 1_000_000; ++i) {
boolean isPrime = true;
int sqrt = (int)Math.ceil(Math.sqrt(i));
for (int divisor = 2; divisor <= sqrt; ++divisor) {
if (i % divisor == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.println(i);
}
}
}
}
Example 2: easy code for print 10 prime number in assembly
Data Segment
arrprime db 20 dup (?)
i db 02h
Data Ends
Code Segment
Assume cs:code, ds:data
Begin:
mov ax, data
mov ds, ax
mov es, ax
mov dl, 01h
mov cx, 10h
lea di, arrprime
L1:
mov bl, 02
add dl, 01h
cmp dl, 02h
je Insert
cmp dl, 03h
je Insert
cmp dl, 04h
jge Logic
Logic:
mov ah, 00
mov al, dl
div bl
cmp ah, 00
je L1
add bl, 01h
cmp bl, al
jle Logic
jmp insert
Insert:
mov [di], dl
inc di
loop L1
Exit:
mov ax, 4c00h
int 21h
Code Ends
End Begin