LMC Branch Instructions (for making decisions)

The following program will demonstrate how to use the branching instructions of the LMC to implement decision making.  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 largest of two input values.  Note: if the values are equal, both numbers represent the largest value, so either can be output.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Program

INP
STA FIRST
INP
STA SECOND
SUB FIRST
BRP SECONDBIG
LDA FIRST
OUT
BRA PROGRAMEND
SECONDBIG LDA SECOND
OUT
PROGRAMEND HLT
FIRST DAT
SECOND 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