Hello eveyone, I want to write a MARIE code to perform the following program excerpt:

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

Instactions given:

• The following labels and directives should be included at the end of your program:

X, Dec 4
Y, Dec 2
Z, Dec 5
One, Dec 1

I do not know how to use if statments in marie, all I know is how to add, subtract and multiply ( the basics)

any help would be really appreciated :)

The example code here should help. If you are still stuck then post your code here and we'll have a look.

Here's my code, the problem is the code excutes both if and else

``````ORG 200
Subt Y
Subt Z
Skipcond 000
Jump Else
Subt Y
Store X
Output
Store Z
Output
Subt One
Store Y
Output
Halt

X, DEC 4
Y, DEC 2
Z, DEC 5
One, DEC 1``````

Once you read that, I have written assembler for too many boards and CPUs, you have to write this one then share what you wrote and state where you think the problem is.

The hexadecimal representation of the MARIE machine language might be as follows

So this is what it is. Let's see your code.

Hi rproffitt, I included my code in my previous reply.

Regards,

I think I have solved it :)

``````ORG 200
Subt Y
Subt Z
Skipcond 000
Jump Else
Subt Y
Store X
Output
Store Z
Output
Jump Next
Subt One
Store Y
Output
Next, Halt

X, DEC 4
Y, DEC 2
Z, DEC 5
One, DEC 1``````

what do you think guys?

To debug your code, find an IDE that let's you single step your code to find where the problem is. As it's not on a CPU I currently work on, you have to learn this method.

Or add debug outputs so you can watch where it worked or failed.

Write MARIE code to: 1. Input a number and store it in X

1. Y will be equal to “

Write MARIE code to: 1. Input a number and store it in X . 2. Y will be equal to “

1. if Y>0 display the value of Y, otherwise display the value of X. (Hint: Use Skipcond instruction)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.