Question: Write a RAM program to check if a positive number is prime. The input number is assumed to be in register R 1 when the
Write a RAM program to check if a positive number is prime. The input number is assumed to be in register R when the program starts running and the result, if input number is a prime and if the input number is not a prime is placed in register R at the end. Here are some sample runs:
ASCSCPPW:hw raj$ python RAM.py prime.ram
Input: R
R
R
R
Output: R
ASCSCPPW:hw raj$ python RAM.py prime.ram
Input: R
R
R
R
Output: R
ASCSCPPW:hw raj$
Use instructions from the instruction set below
The instruction set consists of the following instructions:
INC Ri increment the contents of register Ri by
DEC Ri decrement the contents of register Ri by ; keep Ri unchanged if Ri is
CLR Ri set the contents of register Ri to
MOV Ri Rj replace the contents of register Ri by the contents of Rj leaving Rj the same.
JMP N next instruction to execute is set to the one with label N
Rj JMP N if contents of Rj is the next instruction to execute is set to the one with label N otherwise the instruction that follows executes as usual.
CONTINUE, do nothing.... example ram
R
R
MOV R R
N: DEC R
R JMP N
MOV R R
MOV R R
N: DEC R
R JMP N
MOV R R
N: R JMP N
INC R
DEC R
JMP N
N: MOV R R
CONTINUE
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
