The LMC is a simplified assembly language designed for teaching about the Fetch-Execute cycle, computer architecture and assembly. It was created by Dr. Stuart Madnick in 1965. See 101 Computing for details and challenges. See Peter Higginson's page for even more details.
There are two simulators that we'll use:
Peter Higginson has also made a version that is close to the AQA exam board specifications.
Exercises:
This is to practice using pseudocode to design algorithms; translation (compilation) into Assembly; Executing & debugging code at the level of the Fetch-(Decode)-Execute cycle.Notes:
Remember that one High-Level-Language instruction can translate to many Low-Level-Language instructions.
Declare & initialize a variable
num ← 4Is equivalent to allocating memory with a label
num DAT 4Input a variable
INPUT numIs equivalent to inputting and then storing (assume num is a valid data label)
INPSTA numOutput a variable
OUTPUT numIs equivalent to loading and then printing (assume num is a valid data label)
LDA numOUTAdd one to a variable
num ← num + 1Is equivalent to Load, Modify, Store (assume num and one are valid data labels)
LDA numADD oneSTA numIn assembly, all selection and iteration flow control is implemented using branch commands that can depend on the ALU flags. In the LMC we have:
IF Statement / Binary Selection
IF num1 > num2 THEN PRINT num1ELSE PRINT num2END IFTranslates to (assuming num1 and num2 already valid data labels)
LDA num1 SUB num2 BRP biggersmaller LDA num2 OUT BRA endifbigger LDA num1 OUTendif HLTWhile-Do and Repeat-Until loops: See count down examples below.
INPSTA 99 // AINPSTA 98 // BADD 99OUTHLTINPSTA 99 // AINPSTA 98 // BSUB 99OUTHLTINPSTA 99 // AINPSTA 98 // BLDA 99SUB 98OUTHLTNote that in A-B we had to store both A and B then load A back into the Accumulator before subtracting B
Simple version with a WHILE loop
INPUT countWHILE count <> 0 DO OUTPUT count count ← count - 1END WHILEHere is an equivalent LMC assembly program with a manually referenced memory address for the count
INP STA 99 // countloop BRZ end LDA 99 OUT SUB one STA 99 BRA loopend HLTone DAT 1Note that as only count is ever in the Accumulator, we can simplify to get
INPloop BRZ end OUT SUB one BRA loopend HLTone DAT 1But in most cases you'd do more inside the loop and such a simplification is not possible
Simple version with a REPEAT-UNTIL loop
INPUT countREPEAT OUTPUT count count ← count - 1UNTIL count <= 0Here is an equivalent LMC assembly program with a labelled memory address for the count
INP STA count loop OUT LDA count SUB one STA count BRP loop HLT one DAT 1 count DAT Note that as only count is ever in the Accumulator, we can simplify to get
INP loop OUT SUB one BRP loop HLT one DAT 1 But in most cases you'd do more inside the loop and such a simplification is not possible