173k views
1 vote
Write an assembly program that will find out the prime numbers between 200 and 240 , and store them in an array (define the array element as byte).

1 Answer

2 votes

Final answer:

Here is an example of an assembly program that finds prime numbers between 200 and 240 and stores them in an array.

Step-by-step explanation:

Prime Numbers Assembly Program

Here is an example of an assembly program that finds the prime numbers between 200 and 240 and stores them in an array:

.data
array db 40 dup(0)
.code
main proc
mov cx, 200
mov di, 0

check_prime:
mov bx, 2
mov ax, cx

div bx ; divide by 2

jc not_prime ; if remainder is 0, go to not_prime

mov bx, 3
mov ax, cx

div bx ; divide by 3

jc not_prime ; if remainder is 0, go to not_prime

mov bx, 5
mov ax, cx

div bx ; divide by 5

jc not_prime ; if remainder is 0, go to not_prime

mov bx, 7
mov ax, cx

div bx ; divide by 7

jc not_prime ; if remainder is 0, go to not_prime

mov word ptr array[di], cx ; store prime number
inc di

not_prime:
inc cx
loop check_prime

endp
end main

This program starts checking if each number between 200 and 240 is prime by dividing it by 2, 3, 5, and 7. If the number is not divisible by any of these, it is considered prime and stored in the 'array'. The array elements are defined as bytes.

User Jack M
by
6.5k points