208k views
2 votes
Write a MARIE program to implement following C code. Initialize g, h, and i variables using labels in MARIE. Define labels for f, k and sum variables:

int g=5;

int h=7;

int i=15;

int f;

int k;

int sum;

f = (g + h);

k = (i + i);

sum=f+k;

User Twibit
by
8.3k points

1 Answer

3 votes

Final answer:

The MARIE program uses Assembly language instructions to initialize and compute the sum of variables analogous to the given C code. It employs basic operations like Load, Add, and Store to calculate the results for f, k, and sum.

Step-by-step explanation:

Creating a MARIE program to emulate the given C code involving basic arithmetic operations and variable initialization requires using the Assembly language instructions provided by MARIE. We initialize variables g, h, and i and then perform the specified computations to get the results for variables f, k, and sum.

Example MARIE Program

ORG 100
g, DEC 5
h, DEC 7
i, DEC 15
f, DEC 0
k, DEC 0
sum, DEC 0

Load g
Add h
Store f
Load i
Add i
Store k
Load f
Add k
Store sum
Halt
END

This program initializes the variables at addresses they can be referred to in the program. Arithmetic operations are performed using Load, Add, and Store instructions. For instance, to calculate f we load g into the accumulator, add h to it, and then store the result in f. The same process is followed for calculating k and sum, where k is the sum of i with itself, and sum is the total of f and k. The Halt instruction is used to terminate the program.

User Sagar Gautam
by
7.0k points