LMC Branch Instructions (for implementing loops)

The following program will demonstrate how to use the branching instructions of the LMC to implement looping.  Note: The Branch Always instruction should only be used to connect paths indicated by your flowchart. 

Flowchart

The following is the flowchart for a program that will output the values from 1 to 10.

 

 

 

 

 

 

 

 

 

 

 

 


Program

LDA ONE
STA COUNT
OUT
LOOPTOP LDA COUNT
ADD ONE
OUT
STA COUNT
SUB TEN
BRP ENDLOOP
BRA LOOPTOP
ENDLOOP HLT
ONE DAT 001
TEN DAT 010
COUNT DAT

What you should do

  1. Click on the "LMC Simulator Applet" link to start the LMC simulator.
  2. Clear the Message Box and all of the LMC mailboxes -- click the "Clear Messages" button and the "Clear" button if necessary.
  3. Copy the fourteen line program above and paste it into the Message Box
  4. Click on the "Compile Program" button.
  5. Click on the "Run" button.
  6. When prompted, enter three-digit numbers in the "In-Box", and press the "Enter" button.

What you should see