For 6-7, convert the C code to equivalent MARIE code. You may reference literal values using an immediate datum mode as in #1, or assume the value is in a variable of the same name (e.g., one).
6) scanf(“%d”, &x);
z=0;
for(i=0;i<x;i++)
scanf(“%d”, &y);
if(y==0) z++;
}
printf(“%d”, z);
Below is the solution in Marie. You can go through the solution for this I am considering ORG as 100.Read the comments for your better understanding.
SOLUTION
ORG 100
Input //Taking input
Store x //Initializing x
Load x
Load z //Loading the stored variable z=0
Top(Loop), Load i //Loading Loopconstant
Subt x //Checking condition in loop i<x
Skipcond 800 //if i<x it will stop loop
Jump LoopEnd //quit the loop
Input //Taking input
Store y //Initializing y
if, Load y
y EQ #0 //Checking if(y==0)
Load z
Add One //z = z+1
Jump Top
EndLoop, Halt //Loop End
Load z
Output //Printing z
z, Dec 0 //Storing z =0 initially
i, Dec 0 //Storing i =0 initially
Get Answers For Free
Most questions answered within 1 hours.