Here is the description of a new assembly language: * 8 registers (R1, R2, R3, R4, R5, R6, R7, R8) that can hold integers. * 1 flag that can hold a boolean value (True or False). * 100 memory addresses (0-99) that can hold integers. * 1 instruction pointer that points to the current instruction being executed. Each instruction is of the form OP ARG1 ARG2 ... where ARGn can be either a register (e.g., R1) or a constant (e.g., 10). Labels are written with a lowercase word followed by colon. The assembly language supports the following instructions: * SET Rx C: Assigns the value C to register Rx. * ADD Rx Ry Rz: Adds the values of Ry and Rz and stores the result in Rx. * (similarly for SUB, MUL, DIV, MOD) * EQ Rx Ry: Sets the flag to True if Rx and Ry are equal, False otherwise. * (similarly for NEQ, LT (Rx < Ry), LTE, GT, GTE) * INC/DEC Rx: Increments/Decrements the value of Rx by one. * JMP L: Jumps to label L unconditionally. * JT/JF (jump if true / jump if false) L: Jumps to label L if the is set or not set. * LOAD Rx M: Loads the value at memory address M into register Rx. * STORE Rx M: Stores the value of register Rx into memory address M. * HCF: Stops the program (with pizzazz) Given this assembly language, write a program that puts the first 20 prime numbers in memory cells 0..19
Here is the description of a new assembly language: * 8 registers (R1, R2, R3, R4, R5, R6, R7, R8) that can hold integers. * 1 flag that can hold a boolean value (True or False). * 100 memory addresses (0-99) that can hold integers. * 1 instruction pointer that points to the current instruction being executed. Each instruction is of the form OP ARG1 ARG2 ... where ARGn can be either a register (e.g., R1) or a constant (e.g., 10). Labels are written with a lowercase word followed by colon. The assembly language supports the following instructions: * SET Rx C: Assigns the value C to register Rx. * ADD Rx Ry Rz: Adds the values of Ry and Rz and stores the result in Rx. * (similarly for SUB, MUL, DIV, MOD) * EQ Rx Ry: Sets the flag to True if Rx and Ry are equal, False otherwise. * (similarly for NEQ, LT (Rx < Ry), LTE, GT, GTE) * INC/DEC Rx: Increments/Decrements the value of Rx by one. * JMP L: Jumps to label L unconditionally. * JT/JF (jump if true / jump if false) L: Jumps to label L if the is set or not set. * LOAD Rx M: Loads the value at memory address M into register Rx. * STORE Rx M: Stores the value of register Rx into memory address M. * HCF: Stops the program (with pizzazz) Given this assembly language, write a program that puts the first 20 prime numbers in memory cells 0..19
Here's an assembly program that calculates and stores the first 20 prime numbers in memory cells 0 to 19:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | SET R1 2 ; R1 is the current number we're checking SET R2 0 ; R2 is the count of primes found SET R3 0 ; R3 is the divisor we're testing SET R4 20 ; R4 is our target (20 primes) SET R5 0 ; R5 is temporary storage SET R6 2 ; R6 is constant 2 for comparison start: SET R3 2 ; Reset divisor to 2 check_prime: EQ R1 R3 JT is_prime ; If R1 == R3, it's prime MOD R5 R1 R3 ; R5 = R1 % R3 EQ R5 R0 ; Check if R5 == 0 JT not_prime ; If divisible, not prime INC R3 ; Increment divisor JMP check_prime ; Continue checking is_prime: STORE R1 R2 ; Store prime in memory at address R2 INC R2 ; Increment prime count EQ R2 R4 JT end ; If we've found 20 primes, end not_prime: INC R1 ; Move to next number JMP start ; Restart the process end: HCF ; Halt and Catch Fire |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | SET R1 2 ; R1 is the current number we're checking SET R2 0 ; R2 is the count of primes found SET R3 0 ; R3 is the divisor we're testing SET R4 20 ; R4 is our target (20 primes) SET R5 0 ; R5 is temporary storage SET R6 2 ; R6 is constant 2 for comparison start: SET R3 2 ; Reset divisor to 2 check_prime: EQ R1 R3 JT is_prime ; If R1 == R3, it's prime MOD R5 R1 R3 ; R5 = R1 % R3 EQ R5 R0 ; Check if R5 == 0 JT not_prime ; If divisible, not prime INC R3 ; Increment divisor JMP check_prime ; Continue checking is_prime: STORE R1 R2 ; Store prime in memory at address R2 INC R2 ; Increment prime count EQ R2 R4 JT end ; If we've found 20 primes, end not_prime: INC R1 ; Move to next number JMP start ; Restart the process end: HCF ; Halt and Catch Fire |
'R0' Resulting in output: False
Here is the description of a new assembly language: * 8 registers (R1, R2, R3, R4, R5, R6, R7, R8) that can hold integers. * 1 flag that can hold a boolean value (True or False). * 100 memory addresses (0-99) that can hold integers. * 1 instruction pointer that points to the current instruction being executed. Each instruction is of the form OP ARG1 ARG2 ... where ARGn can be either a register (e.g., R1) or a constant (e.g., 10). Labels are written with a lowercase word followed by colon. The assembly language supports the following instructions: * SET Rx C: Assigns the value C to register Rx. * ADD Rx Ry Rz: Adds the values of Ry and Rz and stores the result in Rx. * (similarly for SUB, MUL, DIV, MOD) * EQ Rx Ry: Sets the flag to True if Rx and Ry are equal, False otherwise. * (similarly for NEQ, LT (Rx < Ry), LTE, GT, GTE) * INC/DEC Rx: Increments/Decrements the value of Rx by one. * JMP L: Jumps to label L unconditionally. * JT/JF (jump if true / jump if false) L: Jumps to label L if the is set or not set. * LOAD Rx M: Loads the value at memory address M into register Rx. * STORE Rx M: Stores the value of register Rx into memory address M. * HCF: Stops the program (with pizzazz) Given this assembly language, write a program that puts the first 20 prime numbers in memory cells 0..19
Here is the description of a new assembly language: * 8 registers (R1, R2, R3, R4, R5, R6, R7, R8) that can hold integers. * 1 flag that can hold a boolean value (True or False). * 100 memory addresses (0-99) that can hold integers. * 1 instruction pointer that points to the current instruction being executed. Each instruction is of the form OP ARG1 ARG2 ... where ARGn can be either a register (e.g., R1) or a constant (e.g., 10). Labels are written with a lowercase word followed by colon. The assembly language supports the following instructions: * SET Rx C: Assigns the value C to register Rx. * ADD Rx Ry Rz: Adds the values of Ry and Rz and stores the result in Rx. * (similarly for SUB, MUL, DIV, MOD) * EQ Rx Ry: Sets the flag to True if Rx and Ry are equal, False otherwise. * (similarly for NEQ, LT (Rx < Ry), LTE, GT, GTE) * INC/DEC Rx: Increments/Decrements the value of Rx by one. * JMP L: Jumps to label L unconditionally. * JT/JF (jump if true / jump if false) L: Jumps to label L if the is set or not set. * LOAD Rx M: Loads the value at memory address M into register Rx. * STORE Rx M: Stores the value of register Rx into memory address M. * HCF: Stops the program (with pizzazz) Given this assembly language, write a program that puts the first 20 prime numbers in memory cells 0..19
Here's an assembly program that calculates the first 20 prime numbers and stores them in memory cells 0 to 19:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | SET R1 2 ; R1 is the current number we're checking SET R2 0 ; R2 is the count of primes found SET R3 2 ; R3 is the divisor we're checking SET R4 0 ; R4 is used for division SET R5 0 ; R5 is used to store the remainder SET R6 20 ; R6 is the target number of primes start: SET R3 2 ; Reset divisor to 2 SET R7 R1 ; R7 = R1 (number to check) SUB R7 R7 1 ; R7 = R7 - 1 (upper bound for divisor check) check_prime: LTE R3 R7 JF prime_found ; If R3 > R7, number is prime SET R4 R1 ; Set up division: R4 = R1 / R3 SET R5 R1 ; R5 will be the remainder divide: LT R4 R3 JT div_done ; If R4 < R3, division is done SUB R4 R4 R3 INC R5 JMP divide div_done: EQ R5 0 JT not_prime ; If remainder is 0, not prime INC R3 ; Increment divisor JMP check_prime prime_found: STORE R1 R2 ; Store prime in memory at address R2 INC R2 ; Increment prime count EQ R2 R6 JT done ; If we've found 20 primes, we're done not_prime: INC R1 ; Move to next number JMP start done: HCF ; Halt and Catch Fire |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | SET R1 2 ; R1 is the current number we're checking SET R2 0 ; R2 is the count of primes found SET R3 2 ; R3 is the divisor we're checking SET R4 0 ; R4 is used for division SET R5 0 ; R5 is used to store the remainder SET R6 20 ; R6 is the target number of primes start: SET R3 2 ; Reset divisor to 2 SET R7 R1 ; R7 = R1 (number to check) SUB R7 R7 1 ; R7 = R7 - 1 (upper bound for divisor check) check_prime: LTE R3 R7 JF prime_found ; If R3 > R7, number is prime SET R4 R1 ; Set up division: R4 = R1 / R3 SET R5 R1 ; R5 will be the remainder divide: LT R4 R3 JT div_done ; If R4 < R3, division is done SUB R4 R4 R3 INC R5 JMP divide div_done: EQ R5 0 JT not_prime ; If remainder is 0, not prime INC R3 ; Increment divisor JMP check_prime prime_found: STORE R1 R2 ; Store prime in memory at address R2 INC R2 ; Increment prime count EQ R2 R6 JT done ; If we've found 20 primes, we're done not_prime: INC R1 ; Move to next number JMP start done: HCF ; Halt and Catch Fire |
Resulting in output: False
Here is the description of a new assembly language: * 8 registers (R1, R2, R3, R4, R5, R6, R7, R8) that can hold integers. * 1 flag that can hold a boolean value (True or False). * 100 memory addresses (0-99) that can hold integers. * 1 instruction pointer that points to the current instruction being executed. Each instruction is of the form OP ARG1 ARG2 ... where ARGn can be either a register (e.g., R1) or a constant (e.g., 10). Labels are written with a lowercase word followed by colon. The assembly language supports the following instructions: * SET Rx C: Assigns the value C to register Rx. * ADD Rx Ry Rz: Adds the values of Ry and Rz and stores the result in Rx. * (similarly for SUB, MUL, DIV, MOD) * EQ Rx Ry: Sets the flag to True if Rx and Ry are equal, False otherwise. * (similarly for NEQ, LT (Rx < Ry), LTE, GT, GTE) * INC/DEC Rx: Increments/Decrements the value of Rx by one. * JMP L: Jumps to label L unconditionally. * JT/JF (jump if true / jump if false) L: Jumps to label L if the is set or not set. * LOAD Rx M: Loads the value at memory address M into register Rx. * STORE Rx M: Stores the value of register Rx into memory address M. * HCF: Stops the program (with pizzazz) Given this assembly language, write a program that puts the first 20 prime numbers in memory cells 0..19
Here is the description of a new assembly language: * 8 registers (R1, R2, R3, R4, R5, R6, R7, R8) that can hold integers. * 1 flag that can hold a boolean value (True or False). * 100 memory addresses (0-99) that can hold integers. * 1 instruction pointer that points to the current instruction being executed. Each instruction is of the form OP ARG1 ARG2 ... where ARGn can be either a register (e.g., R1) or a constant (e.g., 10). Labels are written with a lowercase word followed by colon. The assembly language supports the following instructions: * SET Rx C: Assigns the value C to register Rx. * ADD Rx Ry Rz: Adds the values of Ry and Rz and stores the result in Rx. * (similarly for SUB, MUL, DIV, MOD) * EQ Rx Ry: Sets the flag to True if Rx and Ry are equal, False otherwise. * (similarly for NEQ, LT (Rx < Ry), LTE, GT, GTE) * INC/DEC Rx: Increments/Decrements the value of Rx by one. * JMP L: Jumps to label L unconditionally. * JT/JF (jump if true / jump if false) L: Jumps to label L if the is set or not set. * LOAD Rx M: Loads the value at memory address M into register Rx. * STORE Rx M: Stores the value of register Rx into memory address M. * HCF: Stops the program (with pizzazz) Given this assembly language, write a program that puts the first 20 prime numbers in memory cells 0..19
Here's an assembly program that calculates the first 20 prime numbers and stores them in memory addresses 0 to 19:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | SET R1 2 ; R1 is the current number we're checking SET R2 0 ; R2 is the count of primes found SET R3 2 ; R3 is the divisor we're checking SET R4 0 ; R4 is used for division result SET R5 0 ; R5 is used for division remainder SET R6 20 ; R6 is the target number of primes start: SET R3 2 ; Reset divisor to 2 JMP check_prime check_prime: DIV R4 R1 R3 ; Divide R1 by R3 MOD R5 R1 R3 ; Get remainder of R1 / R3 EQ R5 0 ; Check if remainder is 0 JT not_prime ; If divisible, it's not prime INC R3 ; Increment divisor MUL R7 R3 R3 ; Square the divisor GT R7 R1 ; Check if divisor^2 > number JT prime_found ; If so, it's prime JMP check_prime ; Otherwise, continue checking not_prime: INC R1 ; Move to next number JMP start prime_found: STORE R1 R2 ; Store prime in memory at address R2 INC R2 ; Increment prime count EQ R2 R6 ; Check if we've found 20 primes JT end ; If so, end the program INC R1 ; Move to next number JMP start end: HCF ; Halt and Catch Fire |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | SET R1 2 ; R1 is the current number we're checking SET R2 0 ; R2 is the count of primes found SET R3 2 ; R3 is the divisor we're checking SET R4 0 ; R4 is used for division result SET R5 0 ; R5 is used for division remainder SET R6 20 ; R6 is the target number of primes start: SET R3 2 ; Reset divisor to 2 JMP check_prime check_prime: DIV R4 R1 R3 ; Divide R1 by R3 MOD R5 R1 R3 ; Get remainder of R1 / R3 EQ R5 0 ; Check if remainder is 0 JT not_prime ; If divisible, it's not prime INC R3 ; Increment divisor MUL R7 R3 R3 ; Square the divisor GT R7 R1 ; Check if divisor^2 > number JT prime_found ; If so, it's prime JMP check_prime ; Otherwise, continue checking not_prime: INC R1 ; Move to next number JMP start prime_found: STORE R1 R2 ; Store prime in memory at address R2 INC R2 ; Increment prime count EQ R2 R6 ; Check if we've found 20 primes JT end ; If so, end the program INC R1 ; Move to next number JMP start end: HCF ; Halt and Catch Fire |
Resulting in output: False
Here is the description of a new assembly language: * 8 registers (R1, R2, R3, R4, R5, R6, R7, R8) that can hold integers. * 1 flag that can hold a boolean value (True or False). * 100 memory addresses (0-99) that can hold integers. * 1 instruction pointer that points to the current instruction being executed. Each instruction is of the form OP ARG1 ARG2 ... where ARGn can be either a register (e.g., R1) or a constant (e.g., 10). Labels are written with a lowercase word followed by colon. The assembly language supports the following instructions: * SET Rx C: Assigns the value C to register Rx. * ADD Rx Ry Rz: Adds the values of Ry and Rz and stores the result in Rx. * (similarly for SUB, MUL, DIV, MOD) * EQ Rx Ry: Sets the flag to True if Rx and Ry are equal, False otherwise. * (similarly for NEQ, LT (Rx < Ry), LTE, GT, GTE) * INC/DEC Rx: Increments/Decrements the value of Rx by one. * JMP L: Jumps to label L unconditionally. * JT/JF (jump if true / jump if false) L: Jumps to label L if the is set or not set. * LOAD Rx M: Loads the value at memory address M into register Rx. * STORE Rx M: Stores the value of register Rx into memory address M. * HCF: Stops the program (with pizzazz) Given this assembly language, write a program that puts the first 20 prime numbers in memory cells 0..19
Here is the description of a new assembly language: * 8 registers (R1, R2, R3, R4, R5, R6, R7, R8) that can hold integers. * 1 flag that can hold a boolean value (True or False). * 100 memory addresses (0-99) that can hold integers. * 1 instruction pointer that points to the current instruction being executed. Each instruction is of the form OP ARG1 ARG2 ... where ARGn can be either a register (e.g., R1) or a constant (e.g., 10). Labels are written with a lowercase word followed by colon. The assembly language supports the following instructions: * SET Rx C: Assigns the value C to register Rx. * ADD Rx Ry Rz: Adds the values of Ry and Rz and stores the result in Rx. * (similarly for SUB, MUL, DIV, MOD) * EQ Rx Ry: Sets the flag to True if Rx and Ry are equal, False otherwise. * (similarly for NEQ, LT (Rx < Ry), LTE, GT, GTE) * INC/DEC Rx: Increments/Decrements the value of Rx by one. * JMP L: Jumps to label L unconditionally. * JT/JF (jump if true / jump if false) L: Jumps to label L if the is set or not set. * LOAD Rx M: Loads the value at memory address M into register Rx. * STORE Rx M: Stores the value of register Rx into memory address M. * HCF: Stops the program (with pizzazz) Given this assembly language, write a program that puts the first 20 prime numbers in memory cells 0..19
Here's an assembly program that calculates the first 20 prime numbers and stores them in memory addresses 0 to 19:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | SET R1 2 ; R1 is our current number to check SET R2 0 ; R2 is our prime counter SET R3 0 ; R3 is our divisor SET R4 20 ; R4 is our target (20 primes) SET R5 0 ; R5 is our temporary remainder SET R6 2 ; R6 is constant 2 for comparison SET R7 0 ; R7 is our memory address counter main_loop: SET R3 2 ; Reset divisor to 2 EQ R2 R4 JT end ; If we have 20 primes, end is_prime_loop: EQ R3 R1 JT prime_found ; If divisor == number, it's prime MOD R5 R1 R3 ; Check if R1 is divisible by R3 EQ R5 R0 JT not_prime ; If divisible, not prime INC R3 ; Increment divisor JMP is_prime_loop prime_found: STORE R1 R7 ; Store prime in memory INC R7 ; Increment memory address INC R2 ; Increment prime counter not_prime: INC R1 ; Move to next number JMP main_loop end: HCF |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | SET R1 2 ; R1 is our current number to check SET R2 0 ; R2 is our prime counter SET R3 0 ; R3 is our divisor SET R4 20 ; R4 is our target (20 primes) SET R5 0 ; R5 is our temporary remainder SET R6 2 ; R6 is constant 2 for comparison SET R7 0 ; R7 is our memory address counter main_loop: SET R3 2 ; Reset divisor to 2 EQ R2 R4 JT end ; If we have 20 primes, end is_prime_loop: EQ R3 R1 JT prime_found ; If divisor == number, it's prime MOD R5 R1 R3 ; Check if R1 is divisible by R3 EQ R5 R0 JT not_prime ; If divisible, not prime INC R3 ; Increment divisor JMP is_prime_loop prime_found: STORE R1 R7 ; Store prime in memory INC R7 ; Increment memory address INC R2 ; Increment prime counter not_prime: INC R1 ; Move to next number JMP main_loop end: HCF |
'R0' Resulting in output: False
Here is the description of a new assembly language: * 8 registers (R1, R2, R3, R4, R5, R6, R7, R8) that can hold integers. * 1 flag that can hold a boolean value (True or False). * 100 memory addresses (0-99) that can hold integers. * 1 instruction pointer that points to the current instruction being executed. Each instruction is of the form OP ARG1 ARG2 ... where ARGn can be either a register (e.g., R1) or a constant (e.g., 10). Labels are written with a lowercase word followed by colon. The assembly language supports the following instructions: * SET Rx C: Assigns the value C to register Rx. * ADD Rx Ry Rz: Adds the values of Ry and Rz and stores the result in Rx. * (similarly for SUB, MUL, DIV, MOD) * EQ Rx Ry: Sets the flag to True if Rx and Ry are equal, False otherwise. * (similarly for NEQ, LT (Rx < Ry), LTE, GT, GTE) * INC/DEC Rx: Increments/Decrements the value of Rx by one. * JMP L: Jumps to label L unconditionally. * JT/JF (jump if true / jump if false) L: Jumps to label L if the is set or not set. * LOAD Rx M: Loads the value at memory address M into register Rx. * STORE Rx M: Stores the value of register Rx into memory address M. * HCF: Stops the program (with pizzazz) Given this assembly language, write a program that puts the first 20 prime numbers in memory cells 0..19
Here is the description of a new assembly language: * 8 registers (R1, R2, R3, R4, R5, R6, R7, R8) that can hold integers. * 1 flag that can hold a boolean value (True or False). * 100 memory addresses (0-99) that can hold integers. * 1 instruction pointer that points to the current instruction being executed. Each instruction is of the form OP ARG1 ARG2 ... where ARGn can be either a register (e.g., R1) or a constant (e.g., 10). Labels are written with a lowercase word followed by colon. The assembly language supports the following instructions: * SET Rx C: Assigns the value C to register Rx. * ADD Rx Ry Rz: Adds the values of Ry and Rz and stores the result in Rx. * (similarly for SUB, MUL, DIV, MOD) * EQ Rx Ry: Sets the flag to True if Rx and Ry are equal, False otherwise. * (similarly for NEQ, LT (Rx < Ry), LTE, GT, GTE) * INC/DEC Rx: Increments/Decrements the value of Rx by one. * JMP L: Jumps to label L unconditionally. * JT/JF (jump if true / jump if false) L: Jumps to label L if the is set or not set. * LOAD Rx M: Loads the value at memory address M into register Rx. * STORE Rx M: Stores the value of register Rx into memory address M. * HCF: Stops the program (with pizzazz) Given this assembly language, write a program that puts the first 20 prime numbers in memory cells 0..19
Here's an assembly program that calculates and stores the first 20 prime numbers in memory cells 0 to 19:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | SET R1 2 ; R1 is the current number we're checking SET R2 0 ; R2 is the count of primes found SET R3 2 ; R3 is the divisor we're checking SET R4 0 ; R4 is used for division result SET R5 0 ; R5 is used for division remainder SET R6 20 ; R6 is the target number of primes main_loop: SET R3 2 ; Reset divisor to 2 JMP check_prime check_prime: DIV R4 R1 R3 ; Divide R1 by R3 MOD R5 R1 R3 ; Get remainder of R1 / R3 EQ R5 0 ; Check if remainder is 0 JT not_prime ; If divisible, not prime INC R3 ; Increment divisor MUL R7 R3 R3 ; Square the divisor GT R7 R1 ; Check if divisor^2 > number JT prime_found ; If so, it's prime JMP check_prime ; Otherwise, continue checking not_prime: INC R1 ; Move to next number JMP main_loop prime_found: STORE R1 R2 ; Store prime in memory at index R2 INC R2 ; Increment prime count EQ R2 R6 ; Check if we've found 20 primes JT end ; If so, end the program INC R1 ; Move to next number JMP main_loop end: HCF ; Halt and Catch Fire |
I extracted the following code from that output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | SET R1 2 ; R1 is the current number we're checking SET R2 0 ; R2 is the count of primes found SET R3 2 ; R3 is the divisor we're checking SET R4 0 ; R4 is used for division result SET R5 0 ; R5 is used for division remainder SET R6 20 ; R6 is the target number of primes main_loop: SET R3 2 ; Reset divisor to 2 JMP check_prime check_prime: DIV R4 R1 R3 ; Divide R1 by R3 MOD R5 R1 R3 ; Get remainder of R1 / R3 EQ R5 0 ; Check if remainder is 0 JT not_prime ; If divisible, not prime INC R3 ; Increment divisor MUL R7 R3 R3 ; Square the divisor GT R7 R1 ; Check if divisor^2 > number JT prime_found ; If so, it's prime JMP check_prime ; Otherwise, continue checking not_prime: INC R1 ; Move to next number JMP main_loop prime_found: STORE R1 R2 ; Store prime in memory at index R2 INC R2 ; Increment prime count EQ R2 R6 ; Check if we've found 20 primes JT end ; If so, end the program INC R1 ; Move to next number JMP main_loop end: HCF ; Halt and Catch Fire |
Resulting in output: False