- #1
DanjoJojo
- 8
- 2
New poster has been reminded to post schoolwork problems in the Homework Help forums
Summary:: So I'm trying to get more advanced with the lmc simulator, https://www.101computing.net/LMC/
But it's kind of hard to understand and keep track when it gets long.
Provide an LMC program that will provide a value in three digits ten's complement. The program will take two inputs, a sign and a magnitude.
A valid first input may be zero (0) if the input is positive or one (1) if the input is negative.
The second input is a value from 0 to 500. The program will provide two outputs. The first output is zero (0) if the inputs are invalid and one (1) if the inputs are valid. The second output will be 999 if the input is invalid or the correct result if the input is valid.
Hence, the inputs "0" and "123" will result in the outputs of "1" and "123". The inputs of "1" and "123" will result in the outputs of "1" and "877". The inputs of "2" and "123" will result in the outputs of "0" and "999" (since '2' is an invalid input).
Note: You may assume that 2 inputs will always be provided (i.e. you don't need to worry about a "lost" input ... also known as "an omission error").
This is what I've tried so far...
I'm not able to get the 1 or 0 output though, what am I doing wrong?
[Code tags added by a Mentor]
But it's kind of hard to understand and keep track when it gets long.
Provide an LMC program that will provide a value in three digits ten's complement. The program will take two inputs, a sign and a magnitude.
A valid first input may be zero (0) if the input is positive or one (1) if the input is negative.
The second input is a value from 0 to 500. The program will provide two outputs. The first output is zero (0) if the inputs are invalid and one (1) if the inputs are valid. The second output will be 999 if the input is invalid or the correct result if the input is valid.
Hence, the inputs "0" and "123" will result in the outputs of "1" and "123". The inputs of "1" and "123" will result in the outputs of "1" and "877". The inputs of "2" and "123" will result in the outputs of "0" and "999" (since '2' is an invalid input).
Note: You may assume that 2 inputs will always be provided (i.e. you don't need to worry about a "lost" input ... also known as "an omission error").
This is what I've tried so far...
Code:
INP
STA 99
INP
STA 98
LDA 99
BRZ POS
SUB ONE
BRZ 14
OUT ZERO
LDA 38
OUT
HLT
POS OUT ONE
BRA 16
OUT ONE
BRA 26
LDA 98
SUB 39
BRP 24
LDA 98
SUB 38
ADD ONE
OUT
HLT
OUT 38
HLT
LDA 98
SUB 40
BRP 34
LDA 98
SUB 38
ADD ONE
OUT
HLT
OUT 38
HLT
ONE DAT 1
ZERO DAT 0
38 DAT 999
39 DAT 499
40 DAT 500
I'm not able to get the 1 or 0 output though, what am I doing wrong?
[Code tags added by a Mentor]
Last edited by a moderator: