Write in MARIE code..

Thread Starter

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;
}
 

Thread Starter

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
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.
 

Thread Starter

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
Load x
Subt y
Subt z
Skipcond 000
Jump Else
If, Load x
Subt y
Load Z
Add one
Store x
Jump Next
Else, Load y
subt one
Store y
Next, Halt

x, Dec 8
Y, Dec 10
Z, Dec 15
One, Dec 1
 
Top