- #1
DanjoJojo
- 8
- 2
- Homework Statement
- Write an LMC program (with instructions) which does the following.
The program will input two integers (ranging from 0 to 999). The program will output 0 if the first input is strictly greater than the second number, it will output 1 if the first input is equal to the second input, and output 2 if the first number is strictly less than the second number. The program will run continuously in that it will continue to accept pairs of inputs, provide outputs, and never halt.
- Relevant Equations
- https://www.101computing.net/LMC/
I've attempted and I can retrieve a 0 when the first input is greater than the second using BRP. I can't seem to get the output of 1 if the first input is equal to the second input. I also don't get a 2 output with the first input being less than the second. I also have no idea how to loop a program continuously. Any suggestions or comments would help? I'm a beginner.
INP
STA num1
INP
STA num2
LDA num1
SUB num2
BRP pos
LDA num2
SUB num1
BRZ equal
BRP lessthan
OUT
BRA exit
pos LDA 99
OUT
exit HLT
num1 DAT
num2 DAT
equal DAT 1
lessthan DAT 2
INP
STA num1
INP
STA num2
LDA num1
SUB num2
BRP pos
LDA num2
SUB num1
BRZ equal
BRP lessthan
OUT
BRA exit
pos LDA 99
OUT
exit HLT
num1 DAT
num2 DAT
equal DAT 1
lessthan DAT 2
Last edited by a moderator: