assemblymarie

I cant figure out why this MARIE Sim code wont work properly


So, I'm running into an issue when working with the MARIE simulator. Here is the prompt:

define a decimal variable X and set X = 0    
define a decimal variable Y and set Y = 0

Input a number in decimal form from the keyboard
store the number in location X
Input a number in decimal form from the keyboard
store the number in location Y

If X > 0, then
  X = X + 5
Else
  X = Y - 2
Endif
Display X using the output instruction

EDIT: The current code:

          org 100
          input
          store X
          input
          store Y
          load X
          skipcond 800
          Jump Else
          load X
          Add A
          store X
          jump Endif
Else,     load Y
          Subt B
          store X
Endif,    Load X
          Output
          Halt

X,      dec 0
Y,      dec 0
A,      dec 5
B,      dec 2

My issue comes from the fact that when you run it, the math isn't coming out correctly. For example, if you input 4 for X, the answer comes out to be 7, when it should be 9. Could anyone point where I am going wrong?


Solution

  • Let me know if this works for you:

    org 100
        input
        store X
        input
        store Y
     load X
        skipcond 800
    
    Jump Else
        load X
        Add Addr
        store X
        jump Endif
    Else,   load Y
        Subt Subtr
        store X
    Endif,      Load X
        Output
        Halt
    X,      dec 0
    Y,      dec 0
    Addr,   dec 5
    Subtr,  dec 2