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 finds the first 20 prime numbers and stores them in memory locations 0-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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | ; R1: current number to test ; R2: counter for found primes ; R3: divisor for primality test ; R4: result of division ; R5: remainder ; R6: temporary comparison ; R7: limit of 20 primes ; R8: temporary calculation ; Initialize SET R1 2 ; Start testing from 2 SET R2 0 ; Initialize prime counter SET R7 20 ; We want 20 primes mainloop: ; Test if R1 is prime SET R3 2 ; Start dividing by 2 SET R8 1 ; Assume it's prime until proven otherwise testprime: ; If divisor >= number, it's prime GTE R3 R1 JT isprime ; Divide and check remainder DIV R4 R1 R3 ; R4 = R1 / R3 MUL R6 R4 R3 ; R6 = R4 * R3 SUB R5 R1 R6 ; R5 = R1 - R6 (remainder) ; If remainder is 0, not prime EQ R5 0 JT notprime ; Try next divisor INC R3 JMP testprime notprime: SET R8 0 ; Mark as not prime isprime: ; If R8 is 0, number wasn't prime EQ R8 0 JT nextnumber ; Store prime in memory at position R2 STORE R1 R2 INC R2 ; Check if we have found 20 primes EQ R2 R7 JT done nextnumber: INC R1 JMP mainloop done: 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | ; R1: current number to test ; R2: counter for found primes ; R3: divisor for primality test ; R4: result of division ; R5: remainder ; R6: temporary comparison ; R7: limit of 20 primes ; R8: temporary calculation ; Initialize SET R1 2 ; Start testing from 2 SET R2 0 ; Initialize prime counter SET R7 20 ; We want 20 primes mainloop: ; Test if R1 is prime SET R3 2 ; Start dividing by 2 SET R8 1 ; Assume it's prime until proven otherwise testprime: ; If divisor >= number, it's prime GTE R3 R1 JT isprime ; Divide and check remainder DIV R4 R1 R3 ; R4 = R1 / R3 MUL R6 R4 R3 ; R6 = R4 * R3 SUB R5 R1 R6 ; R5 = R1 - R6 (remainder) ; If remainder is 0, not prime EQ R5 0 JT notprime ; Try next divisor INC R3 JMP testprime notprime: SET R8 0 ; Mark as not prime isprime: ; If R8 is 0, number wasn't prime EQ R8 0 JT nextnumber ; Store prime in memory at position R2 STORE R1 R2 INC R2 ; Check if we have found 20 primes EQ R2 R7 JT done nextnumber: INC R1 JMP mainloop done: HCF |
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 a program that finds the first 20 prime numbers and stores them in memory:
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 45 46 47 48 49 50 51 52 | # R1: current number we're testing for primeness # R2: counter for how many primes we've found # R3: potential divisor when testing primeness # R4: temporary result for division/mod # R5: loop limit for prime testing # R6: used for comparison # R7: mod result # Initialize SET R1 2 # Start with 2 (first prime) SET R2 0 # Counter for found primes mainloop: # Test if R1 is prime SET R3 2 # Start testing divisors from 2 SET R5 R1 # Set loop limit SET R6 1 # For comparison # If R1 is 2, skip division testing EQ R1 2 JT isprime primetest: # If divisor >= number, it's prime GTE R3 R1 JT isprime # Test if R3 divides R1 evenly MOD R7 R1 R3 EQ R7 0 JT notprime # Try next divisor INC R3 JMP primetest isprime: # Store the prime number STORE R1 R2 INC R2 # Check if we've found 20 primes EQ R2 20 JT done notprime: # Try next number INC R1 JMP mainloop done: 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | # R1: current number we're testing for primeness # R2: counter for how many primes we've found # R3: potential divisor when testing primeness # R4: temporary result for division/mod # R5: loop limit for prime testing # R6: used for comparison # R7: mod result # Initialize SET R1 2 # Start with 2 (first prime) SET R2 0 # Counter for found primes mainloop: # Test if R1 is prime SET R3 2 # Start testing divisors from 2 SET R5 R1 # Set loop limit SET R6 1 # For comparison # If R1 is 2, skip division testing EQ R1 2 JT isprime primetest: # If divisor >= number, it's prime GTE R3 R1 JT isprime # Test if R3 divides R1 evenly MOD R7 R1 R3 EQ R7 0 JT notprime # Try next divisor INC R3 JMP primetest isprime: # Store the prime number STORE R1 R2 INC R2 # Check if we've found 20 primes EQ R2 20 JT done notprime: # Try next number INC R1 JMP mainloop done: HCF |
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 a program that finds the first 20 prime numbers and stores them in memory:
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 | # R1: current number to test for primeness # R2: counter for found primes # R3: divisor for primality test # R4: temporary result for division # R5: remainder from division # R6: limit for primality testing # R7: temporary comparison # R8: constant 1 for comparisons SET R1 2 # Start with first prime SET R2 0 # Initialize prime counter SET R8 1 # Set constant 1 mainloop: # Test if R1 is prime SET R3 2 # Start dividing by 2 SET R6 R1 # Set limit to sqrt(R1) [simplified] DIV R6 R6 2 # R6 = R1/2 # Inner loop to test divisibility testprime: MOD R5 R1 R3 # R5 = R1 % R3 EQ R5 R0 # Check if remainder is 0 JT notprime # If divisible, not prime INC R3 # Try next divisor GT R3 R6 # Check if we've tested enough JF testprime # If not, continue testing # If we get here, number is prime STORE R1 R2 # Store prime in memory at position R2 INC R2 # Increment prime counter # Check if we have found 20 primes SET R7 20 EQ R2 R7 JT done notprime: INC R1 # Try next number JMP mainloop done: 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 36 37 38 39 40 41 42 43 44 | # R1: current number to test for primeness # R2: counter for found primes # R3: divisor for primality test # R4: temporary result for division # R5: remainder from division # R6: limit for primality testing # R7: temporary comparison # R8: constant 1 for comparisons SET R1 2 # Start with first prime SET R2 0 # Initialize prime counter SET R8 1 # Set constant 1 mainloop: # Test if R1 is prime SET R3 2 # Start dividing by 2 SET R6 R1 # Set limit to sqrt(R1) [simplified] DIV R6 R6 2 # R6 = R1/2 # Inner loop to test divisibility testprime: MOD R5 R1 R3 # R5 = R1 % R3 EQ R5 R0 # Check if remainder is 0 JT notprime # If divisible, not prime INC R3 # Try next divisor GT R3 R6 # Check if we've tested enough JF testprime # If not, continue testing # If we get here, number is prime STORE R1 R2 # Store prime in memory at position R2 INC R2 # Increment prime counter # Check if we have found 20 primes SET R7 20 EQ R2 R7 JT done notprime: INC R1 # Try next number JMP mainloop done: 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 a program that finds and stores the first 20 prime numbers in memory:
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 45 46 | SET R1 2 ; Current number to test for primeness SET R2 0 ; Counter for found primes SET R3 20 ; Target number of primes start: SET R4 2 ; Divisor to test with SET R8 1 ; Flag for prime (1=prime, 0=not prime) test_prime: ; If divisor >= number, it's prime GTE R4 R1 JT is_prime ; Test if R1 is divisible by R4 MOD R5 R1 R4 EQ R5 0 JT not_prime INC R4 JMP test_prime not_prime: SET R8 0 JMP check_result is_prime: SET R8 1 check_result: EQ R8 1 JF next_number ; Store prime number in memory at position R2 STORE R1 R2 INC R2 ; Check if we found enough primes EQ R2 R3 JT done next_number: INC R1 JMP start done: 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 36 37 38 39 40 41 42 43 44 45 46 | SET R1 2 ; Current number to test for primeness SET R2 0 ; Counter for found primes SET R3 20 ; Target number of primes start: SET R4 2 ; Divisor to test with SET R8 1 ; Flag for prime (1=prime, 0=not prime) test_prime: ; If divisor >= number, it's prime GTE R4 R1 JT is_prime ; Test if R1 is divisible by R4 MOD R5 R1 R4 EQ R5 0 JT not_prime INC R4 JMP test_prime not_prime: SET R8 0 JMP check_result is_prime: SET R8 1 check_result: EQ R8 1 JF next_number ; Store prime number in memory at position R2 STORE R1 R2 INC R2 ; Check if we found enough primes EQ R2 R3 JT done next_number: INC R1 JMP start done: HCF |
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 computes and stores the first 20 prime numbers:
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 45 46 47 48 | ; R1: current number to test ; R2: counter for found primes ; R3: divisor for primality test ; R4: remainder from division ; R5: temp register for comparisons ; R6: limit of found primes (20) ; R7: temp for division calculation SET R1 2 ; Start with first prime SET R2 0 ; Initialize prime counter SET R6 20 ; We want 20 primes mainloop: SET R3 2 ; Start divisor at 2 ; Store R1 in memory at position R2 if prime ; First assume it's prime SET R5 1 ; R5 = 1 means prime testprime: ; If divisor >= number, number is prime GTE R3 R1 JT isprime ; Test if R1 is divisible by R3 MOD R4 R1 R3 ; R4 = R1 % R3 SET R5 0 ; Assume not prime EQ R4 0 ; Check if remainder is 0 JT notprime ; If divisible, not prime INC R3 ; Try next divisor JMP testprime isprime: ; Store prime number in memory STORE R1 R2 ; Store at position R2 INC R2 ; Increment prime counter ; Check if we have found all primes EQ R2 R6 JT done notprime: INC R1 ; Try next number JMP mainloop done: 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 36 37 38 39 40 41 42 43 44 45 46 47 48 | ; R1: current number to test ; R2: counter for found primes ; R3: divisor for primality test ; R4: remainder from division ; R5: temp register for comparisons ; R6: limit of found primes (20) ; R7: temp for division calculation SET R1 2 ; Start with first prime SET R2 0 ; Initialize prime counter SET R6 20 ; We want 20 primes mainloop: SET R3 2 ; Start divisor at 2 ; Store R1 in memory at position R2 if prime ; First assume it's prime SET R5 1 ; R5 = 1 means prime testprime: ; If divisor >= number, number is prime GTE R3 R1 JT isprime ; Test if R1 is divisible by R3 MOD R4 R1 R3 ; R4 = R1 % R3 SET R5 0 ; Assume not prime EQ R4 0 ; Check if remainder is 0 JT notprime ; If divisible, not prime INC R3 ; Try next divisor JMP testprime isprime: ; Store prime number in memory STORE R1 R2 ; Store at position R2 INC R2 ; Increment prime counter ; Check if we have found all primes EQ R2 R6 JT done notprime: INC R1 ; Try next number JMP mainloop done: HCF |
Resulting in output: False