# Write in MARIE code..

#### Salem Alawi

Joined Apr 26, 2017
5
Hello, How can i write this code in MARIE? as i'm teaching myself to code I've been thinking about it for half an hour but i couldn't solve it.

If (x < y + z)
{
x = x – y;
z=z+1;
}
else y=y-1;

Any help appreciated !

#### WBahn

Joined Mar 31, 2012
29,472
You're giving up after just half an hour?

Simplify the problem down and tackle it in stages. Can you figure out how to write:

Code:
x = x - y;
Can you figure out how to write

Code:
if (x < y)
{
x = z;
}
Can you figure out how to write

Code:
if (x < y)
{
x = z;
}
else
{
y = x;
}

#### Salem Alawi

Joined Apr 26, 2017
5
You're giving up after just half an hour?

Simplify the problem down and tackle it in stages. Can you figure out how to write:

Code:
x = x - y;
Can you figure out how to write

Code:
if (x < y)
{
x = z;
}
Can you figure out how to write

Code:
if (x < y)
{
x = z;
}
else
{
y = x;
}
the first part is easy, x = x - y..

but when i get into the if else statement i keep getting confused on how to answer, that's why i picked this example and asked for help.. so i can follow the same steps and instructions to answer the list of examples i have

#### WBahn

Joined Mar 31, 2012
29,472
So work on just being able to implement

Code:
if (x < 0)
y = 2;

#### Salem Alawi

Joined Apr 26, 2017
5
Hello,

Do you have the MARIE guide?
marie.guide.pdf
Here is also an lecture:
lec16_Marie_ISA.pdf

Bertus
So work on just being able to implement

Code:
if (x < 0)
y = 2;

Thank you both! but i'm still confused i think i'll just give it up .. i need to see an example close to mine so i can start studying. Thanks again for your help

#### WBahn

Joined Mar 31, 2012
29,472
What constitutes "close to mine"?

There are only a few programming constructs and they are all quite simple. If you learn how to implement each of them, then you should be able to combine them to implement any program you need to, no matter how complex.

This might help:

http://tomkleen.com/CSCI280/CH04-MA...g high-level language statements in MARIE.htm

Converting high level code to assembly language is also greatly facilitated by drawing a flow chart for the high level code. Implementing the pieces of a flowchart then becomes quite mechanical.

But if your approach is that you have to have someone show you an example that is "close to" whatever you need to do at the moment, then giving up at this point is a very viable option.

#### Salem Alawi

Joined Apr 26, 2017
5
What constitutes "close to mine"?

There are only a few programming constructs and they are all quite simple. If you learn how to implement each of them, then you should be able to combine them to implement any program you need to, no matter how complex.

This might help:

http://tomkleen.com/CSCI280/CH04-MARIE/MARIE-LectureFiles/Implementing high-level language statements in MARIE.htm

Converting high level code to assembly language is also greatly facilitated by drawing a flow chart for the high level code. Implementing the pieces of a flowchart then becomes quite mechanical.

But if your approach is that you have to have someone show you an example that is "close to" whatever you need to do at the moment, then giving up at this point is a very viable option.
Ok, that link helped me a lot, here's what i figured out.. is it any good?

ORG 200
Subt y
Subt z
Skipcond 000
Jump Else
Subt y
Store x
Jump Next