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 cells 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 | SET R1 2 ; Start checking from 2 SET R2 0 ; Memory address counter SET R3 0 ; Number of primes found start: SET R4 2 ; Divisor start SET R5 1 ; Assume prime is true check_prime: ; Check if R4 * R4 > R1 MUL R6 R4 R4 GT R7 R6 R1 JT R7 is_prime ; Check if R1 is divisible by R4 MOD R7 R1 R4 EQ R8 R7 0 JT R8 not_prime ; Try next divisor INC R4 JMP check_prime not_prime: SET R5 0 ; Mark as not prime is_prime: ; If R5 is 1, it's prime EQ R7 R5 1 JF R7 next_num ; Store prime and increment counters STORE R1 R2 INC R2 INC R3 next_num: ; Check if we've found 20 primes EQ R7 R3 20 JT R7 done ; Move to 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 47 | SET R1 2 ; Start checking from 2 SET R2 0 ; Memory address counter SET R3 0 ; Number of primes found start: SET R4 2 ; Divisor start SET R5 1 ; Assume prime is true check_prime: ; Check if R4 * R4 > R1 MUL R6 R4 R4 GT R7 R6 R1 JT R7 is_prime ; Check if R1 is divisible by R4 MOD R7 R1 R4 EQ R8 R7 0 JT R8 not_prime ; Try next divisor INC R4 JMP check_prime not_prime: SET R5 0 ; Mark as not prime is_prime: ; If R5 is 1, it's prime EQ R7 R5 1 JF R7 next_num ; Store prime and increment counters STORE R1 R2 INC R2 INC R3 next_num: ; Check if we've found 20 primes EQ R7 R3 20 JT R7 done ; Move to 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 language program that stores the first 20 prime numbers in memory cells 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 | SET R1 2 # Start with first prime number SET R2 0 # Memory address counter SET R3 20 # Number of primes to find primes_loop: # Check if R1 is prime SET R4 2 # Divisor starts at 2 SET R5 1 # Assume prime (R5 = is_prime flag) check_divisor: # If divisor reaches R1, number is prime EQ R4 R1 JT is_prime # Check if R1 is divisible by R4 MOD R6 R1 R4 EQ R6 0 JT not_prime # Increment divisor and continue checking INC R4 JMP check_divisor not_prime: SET R5 0 # Not a prime number is_prime: # If prime, store in memory EQ R5 1 JF skip_store STORE R1 R2 INC R2 skip_store: # Next number to check INC R1 # Check if we've found 20 primes EQ R2 R3 JF primes_loop 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 | SET R1 2 # Start with first prime number SET R2 0 # Memory address counter SET R3 20 # Number of primes to find primes_loop: # Check if R1 is prime SET R4 2 # Divisor starts at 2 SET R5 1 # Assume prime (R5 = is_prime flag) check_divisor: # If divisor reaches R1, number is prime EQ R4 R1 JT is_prime # Check if R1 is divisible by R4 MOD R6 R1 R4 EQ R6 0 JT not_prime # Increment divisor and continue checking INC R4 JMP check_divisor not_prime: SET R5 0 # Not a prime number is_prime: # If prime, store in memory EQ R5 1 JF skip_store STORE R1 R2 INC R2 skip_store: # Next number to check INC R1 # Check if we've found 20 primes EQ R2 R3 JF primes_loop 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 and stores the first 20 prime numbers in memory cells 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 | SET R1 2 # start checking from 2 SET R2 0 # memory index to store primes SET R3 20 # count of primes to find prime_loop: SET R4 2 # divisor to check SET R5 1 # is_prime flag check_divisor: # If divisor > sqrt of R1, it's prime MUL R6 R4 R4 # R6 = divisor^2 GT R7 R6 R1 JT R7 is_prime # Check if R1 is divisible by current divisor MOD R8 R1 R4 EQ R7 R8 0 JT R7 not_prime # Try next divisor INC R4 JMP check_divisor is_prime: # Store prime number in memory STORE R1 R2 INC R2 # Decrement prime count DEC R3 JT R3 next_num JMP end not_prime: # Move to next number JMP next_num next_num: INC R1 JMP prime_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 36 37 38 39 40 41 42 43 | SET R1 2 # start checking from 2 SET R2 0 # memory index to store primes SET R3 20 # count of primes to find prime_loop: SET R4 2 # divisor to check SET R5 1 # is_prime flag check_divisor: # If divisor > sqrt of R1, it's prime MUL R6 R4 R4 # R6 = divisor^2 GT R7 R6 R1 JT R7 is_prime # Check if R1 is divisible by current divisor MOD R8 R1 R4 EQ R7 R8 0 JT R7 not_prime # Try next divisor INC R4 JMP check_divisor is_prime: # Store prime number in memory STORE R1 R2 INC R2 # Decrement prime count DEC R3 JT R3 next_num JMP end not_prime: # Move to next number JMP next_num next_num: INC R1 JMP prime_loop end: 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 and stores the first 20 prime numbers in memory cells 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 | SET R1 2 # Start checking from 2 SET R2 0 # Memory address counter SET R3 20 # Number of primes to find find_primes: SET R4 2 # Divisor to test SET R5 1 # Assume prime test_divisor: # If divisor >= number being tested, it's prime EQ R4 R1 JT is_prime # Check if number is divisible MOD R6 R1 R4 SET R7 0 EQ R6 R7 JT not_prime # Increment divisor and continue testing INC R4 JMP test_divisor not_prime: SET R5 0 # Mark as not prime is_prime: # If prime, store in memory and increment counters EQ R5 1 JF skip_store STORE R1 R2 INC R2 skip_store: # Increment number being tested INC R1 # Check if we've found 20 primes EQ R2 R3 JF find_primes HCF # Halt |
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 | SET R1 2 # Start checking from 2 SET R2 0 # Memory address counter SET R3 20 # Number of primes to find find_primes: SET R4 2 # Divisor to test SET R5 1 # Assume prime test_divisor: # If divisor >= number being tested, it's prime EQ R4 R1 JT is_prime # Check if number is divisible MOD R6 R1 R4 SET R7 0 EQ R6 R7 JT not_prime # Increment divisor and continue testing INC R4 JMP test_divisor not_prime: SET R5 0 # Mark as not prime is_prime: # If prime, store in memory and increment counters EQ R5 1 JF skip_store STORE R1 R2 INC R2 skip_store: # Increment number being tested INC R1 # Check if we've found 20 primes EQ R2 R3 JF find_primes HCF # Halt |
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 language program that finds and stores the first 20 prime numbers in memory cells 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 | SET R1 2 # Start checking from 2 SET R2 0 # Memory index for storing primes SET R3 20 # Counter for number of primes found check_prime: SET R4 2 # Divisor start SET R5 1 # Prime flag (assume prime) divisor_loop: # Check if current divisor is less than current number LT R6 R4 R1 JF not_prime # If divisor >= number, it's prime # Check if number is divisible MOD R7 R1 R4 EQ R8 R7 0 JT not_prime # If divisible, not prime # Increment divisor INC R4 JMP divisor_loop not_prime: # If divisor reached number, it's prime EQ R8 R4 R1 JT store_prime # Not prime, move to next number INC R1 JMP check_prime store_prime: # Store prime number in memory STORE R1 R2 INC R2 # Increment number and decrement prime counter INC R1 DEC R3 JT check_prime # Continue if more primes needed HCF # Stop program |
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 | SET R1 2 # Start checking from 2 SET R2 0 # Memory index for storing primes SET R3 20 # Counter for number of primes found check_prime: SET R4 2 # Divisor start SET R5 1 # Prime flag (assume prime) divisor_loop: # Check if current divisor is less than current number LT R6 R4 R1 JF not_prime # If divisor >= number, it's prime # Check if number is divisible MOD R7 R1 R4 EQ R8 R7 0 JT not_prime # If divisible, not prime # Increment divisor INC R4 JMP divisor_loop not_prime: # If divisor reached number, it's prime EQ R8 R4 R1 JT store_prime # Not prime, move to next number INC R1 JMP check_prime store_prime: # Store prime number in memory STORE R1 R2 INC R2 # Increment number and decrement prime counter INC R1 DEC R3 JT check_prime # Continue if more primes needed HCF # Stop program |
Infinite loop detected Resulting in output: False