1

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?

Monobus
  • 137
  • 1
  • 2
  • 13

2 Answers2

1

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
Chef
  • 26
  • 1
  • Negative, unfortunately. It suffers from the same issue as what I have currently. The X portion of the if is fine, but if it goes to the else, the output is always 2, no matter what the input for Y is. – Monobus Nov 05 '14 at 03:39
  • What are you inputting and the results from said input? When ever I enter 4 for x and 10 for it outputs 9 on my marie sim. When i enter -5 for x and then input 7 for Y mt decimal output is 5. Have you saved correctly and made sure you updated your previous code or maybe try and create a new one blank edit and paste what I posted and save & assemble that, then test the inputs i provided to see if its the same. – Chef Nov 05 '14 at 17:38
  • Ill try directly copyong as soon as I get to my computer. – Monobus Nov 05 '14 at 21:09
  • Yeah copy the whole block directly but into a new blank one and save it as a new name, then click assemble then go back and reload it fresh & test it. Every new run i do i load it fresh each time to reset everything since The marie program is buggy as hell and wasn't updating my saved edits before so i thought you might have a similar issue and it still have your old saved assembled and running it instead of running any new saves you've done. IF anything report back/post your results of inputs and outputs and maybe we can get it straight. – Chef Nov 05 '14 at 21:38
  • No go. I copied it directly, no change, input -5 and 7, and the output is still 2 – Monobus Nov 06 '14 at 05:43
  • Oh. Oh dear. I feel so dumb for not realizing that. – Monobus Nov 06 '14 at 06:35
  • its been one of those kinds of weeks.. haha no prob though glad I could help – Chef Nov 06 '14 at 06:39
0

Your bug is how and when you use skipcond. Since you're using it right after reading Y, whatever the user enters is still in the AC, so for example if you enter 4 and 10 you'll end up with 15 (10+5), then jump right to the endif.

What you want to do is load X back into the AC, then check it with skipcond, and go into the rest of your logic. You probably also want to use more jumps to make sure you're executing the right blocks.

wmassingham
  • 381
  • 1
  • 5
  • 21
  • The X portion is working now(after properly loading X), but the Y is still incorrect. I double checked for proper loading, but still no cigar. – Monobus Nov 04 '14 at 20:26