0

So this is for a school project: I need to design a program (using a branch loop) that stores 1 in memory location 91, 2 in 92 etc... to 5 is stored in 95. I am not very knowledgable of LMC and would like some advice on it. I use peterhigginson.co.uk/LMC for my code (if that helps). The program cannot be as simple as store 1 in 91, it has to be done using a finite loop. I can easily ace this in any other coding console, just not LMC. Any help mucho appreciated.

Thanks!

Sam Hockham
  • 23
  • 1
  • 6

1 Answers1

0

It's not such an easy question. For code that writes to different addresses, you have to construct the correct STA instructions, using the encoding that STA xx is 3xx.

Here's one way of doing it:

L LDA COUNT
  ADD INS
  STA X
  LDA COUNT
X HLT
  LDA COUNT
  ADD ONE
  STA COUNT
  LDA FIVE
  SUB COUNT
  BRP L
  HLT

COUNT DAT 1
ONE   DAT 1
FIVE  DAT 5
INS   STA 90

There's a counter (stored in COUNT) that goes from 1 to 5, and each time through the loop L, it's added to 390 (which is stored at INS) -- this constructs the instructions STA 91, STA 92, .., STA 95 on iterations 1, 2, 3, 4, 5. This instruction is written at X, and then executed with A having the value of COUNT. The rest is just incrementing COUNT, and stopping when it gets larger than 5.

Here's a live link, which you can see this code running on my own LMC emulator.

Paul Hankin
  • 54,811
  • 11
  • 92
  • 118