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:

  • Use “ORG” instruction to start your program at address 200.
  • 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 
Load X
Subt Y
Subt Z
Skipcond 000
Jump Else
If, Load X
Subt Y
Store X
Output
Load Z
Add One
Store Z
Output
Else, Load Y
Subt One
Store Y
Output
Halt

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

Welcome new member. It's time to read the following link:
https://www.daniweb.com/programming/threads/435023/read-this-before-posting-a-question

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.

I read this about MARIE

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 
Load X
Subt Y
Subt Z
Skipcond 000
Jump Else
If, Load X
Subt Y
Store X
Output
Load Z
Add One
Store Z
Output
Jump Next
Else, Load Y
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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.