0

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 :)

3
Contributors
6
Replies
21
Views
3 Months
Discussion Span
Last Post by rproffitt
0

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
0

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.

Edited by rproffitt

0

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?

Edited by Reverend Jim: Corrected code formatting

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.