In: Computer Science
Input a number and store it in X;
if X > 1 then
Y := X + X;
X := 0;
endif;
Y := Y + 1;
Output the value of Y;
N.B: You should include the MARIE code in your Answer, with an explanation of each instruction in your code beside it.
Example: Subt One /Subtract 1 from AC
Instructions:
For example, if your ID is1915161678234, then you will use the number 4 as the value of x.
X, Dec 0
Y, Dec 12
One, DEC 1
MARIE PROGRAM
ORG 100 //start program at address 100
INPUT //Get input from user which stores in AC
STORE X //store AC value in input
SUBT One //subtract 1 from AC
SUBT One //subtract 1 from AC
SKIPCOND 000 //if AC < 0 skip next instruction
JUMP Cond //jump to Cond instructions
JUMP Done //jump to Done instructions
Cond, LOAD X //store X value in AC
ADD X //Add X and AC and store result in Ac
STORE Y //store AC value in Y
LOAD Zero //store 0 in AC
JUMP Done //jump to Done instructions
Done, LOAD Y //store Y value in AC
ADD One //add 1 to AC
OUTPUT //Dispaly AC
HALT //End Program
STORE X //store X value in Ac
X, DEC 0 //Initialize X with value 0
Y, DEC 12 //Initialize Y with value 12
One, DEC 1 //Initialize One with value 1
Zero, Dec 0 //Initialize Zero with value 0
MARIE PROGRAM SCREENSHOT
OUTPUT SCREENSHOT