0

so I am creating a thing in the LMC where I count from 5 to 17 and display the odd numbers. I've got the code done however when I try to branch at zero when the code hits 17 it won't work and it will keep outputting past 17. The way I'm trying to do this is by subtracting 17 before every iteration of the loop and eventually when the counting variable I'm using hit's 17, 17 will be subtracted and it will branch at 0, halting the program. Can anybody tell me why this isn't working, maybe its the order in which I'm doing it?

       lda third
print  out
       sub first
       brz done
       lda third
       add second
       sto third
       br  print
done   hlt

first  dat 0x17
second dat 0x02
third  dat 0x05
  • Just a small piece of advice. It makes your program more readable if you use variable names that convey meaning. For example `first` could be `end`, `second` could be `step`, `third` could be `start` . It makes it more readable and might be easier to understand why your program acted the way it did. – Michael Petch Feb 16 '16 at 22:26
  • 2
    One other comment is that 0x17 is hex, which is 23 decimal. If you are trying to count to 17 decimal then you should use 17 decimal not 0x17 hex. 0x11 is hex for 17 decimal, which is the reason it worked.Personally I think you have missed the fact that `0x` means values in hex (not decimal) – Michael Petch Feb 16 '16 at 22:29
  • 1
    Thank you very much for the clarification! I'll definitely use decimal values from now on unless I truly need hex values. – Michael DeMarco Feb 18 '16 at 04:10
  • Beware! Your professor reads these. – Bob Brown Feb 25 '16 at 00:46
  • I know Mr. Brown haha. I already knew the code worked, I just didn't understand why which is why I made the post. – Michael DeMarco Feb 25 '16 at 05:39

1 Answers1

-2

I don't know what caused the problem, however when I changed first to 11 it stopped at 17. I have no idea why the difference worked, but works for me :D