1 Write a LMC program that will take ANY three numbers in AN
1. Write a LMC program that will take ANY three numbers, in ANY order, between 0 and 10 as
i
nputs. The program will output the three numbers in order from smallest to largest. For example output using
10, 1, and 3 as inputs would be: 1, 3, 10
2. Write a LMC program that will take ANY two numbers as input between 00 and 99. The progra
m
will output all the odd numbers, in ascending order, that occur between the two numbers, but not including
the two numbers themselves. Example1: input: 1, 10 output: 3, 5, 7, 9 Example2: input: 88, 77 output: 79, 81,
83, 85, 87
Solution
Answer
1. Required LMC program is as below:
INP
STA A
STA B
STA C
LDA A
SUB B
BRP CHECKANOTHER
LDA B
SUB C
BRP BGREATEST
LDA C
SUB A
BRA CGREATEST
CGREATEST LDA C
STA LAST
LDA B
STA SECOND
LDA A
STA FIRST
BRA OUTPUT
BGREATEST LDA B
STA LAST
LDA A
SUB C
BRP AGREATER
AGREATER LDA A
STA SECOND
LDA C
STA FIRST
BRA OUTPUT
CHECKANOTHER LDA A
SUB B
BRP GREATEST
GREATEST LDA A
STA LAST
LDA B
SUB C
BRP GREATER
GREATER LDA B
STA SECOND
LDA C
OUTPUT STA FIRST
LDA FIRST
OUT
LDA SECOND
OUT
LDA LAST
OUT
HLT
2.
The required LMC program is as below:
INP
STA A
STA B
STA VAL
LDA ZERO
LDA A
LOOP STA TEMP
LDA TEMP
SUB VAL
BRZ DONE
BRP LOOP
LDA A
PRINTLOOP STA TEMP
ADD VAL
STA TEMP
LDA TEMP
OUT
LDA TEMP
ADD VAL
SUB B
BRZ DONE
LDA TEMP
BRA PRINTLOOP
DONE HLT
VAL DAT

