Write a Little Man program that accepts three values as input and produces the l
ID: 3801915 • Letter: W
Question
Write a Little Man program that accepts three values as input and produces the largest of the three as output.
Please use the mnemonic code below.
Numeric code
Mnemonic code
Instruction
Description
1xx
ADD
ADD
Add the value stored in mailbox xx to whatever value is currently on the accumulator (calculator).
Note: the contents of the mailbox are not changed, and the actions of the accumulator (calculator) are not defined for add instructions that cause sums larger than 3 digits.
2xx
SUB
SUBTRACT
Subtract the value stored in mailbox xx from whatever value is currently on the accumulator (calculator).
Note: the contents of the mailbox are not changed, and the actions of the accumulator are not defined for subtract instructions that cause negative results - however, a negative flag will be set so that 8xx (BRP) can be used properly.
3xx
STA
STORE
Store the contents of the accumulator in mailbox xx (destructive).
Note: the contents of the accumulator (calculator) are not changed (non-destructive), but contents of mailbox are replaced regardless of what was in there (destructive)
5xx
LDA
LOAD
Load the value from mailbox xx (non-destructive) and enter it in the accumulator (destructive).
6xx
BRA
BRANCH(unconditional)
Set the program counter to the given address (value xx). That is, value xx will be the next instruction executed.
7xx
BRZ
BRANCH IF ZERO (conditional)
If the accumulator (calculator) contains the value 000, set the program counter to the value xx. Otherwise, do nothing.
Note: since the program is stored in memory, data and program instructions all have the same address/location format.
8xx
BRP
BRANCH IF POSITIVE (conditional)
If the accumulator (calculator) is 0 or positive, set the program counter to the value xx. Otherwise, do nothing.
Note: since the program is stored in memory, data and program instructions all have the same address/location format.
901
INP
INPUT
Go to the INBOX, fetch the value from the user, and put it in the accumulator (calculator)
Note: this will overwrite whatever value was in the accumulator (destructive)
902
OUT
OUTPUT
Copy the value from the accumulator (calculator) to the OUTBOX.
Note: the contents of the accumulator are not changed (non-destructive).
0
HLT
HALT
Stop working.
DAT
DATA
This is an assembler instruction which simply loads the value into the next available mailbox. DAT can also be used in conjunction with labels to declare variables. For example, DAT 984 will store the value 984 into a mailbox.
Numeric code
Mnemonic code
Instruction
Description
1xx
ADD
ADD
Add the value stored in mailbox xx to whatever value is currently on the accumulator (calculator).
Note: the contents of the mailbox are not changed, and the actions of the accumulator (calculator) are not defined for add instructions that cause sums larger than 3 digits.
2xx
SUB
SUBTRACT
Subtract the value stored in mailbox xx from whatever value is currently on the accumulator (calculator).
Note: the contents of the mailbox are not changed, and the actions of the accumulator are not defined for subtract instructions that cause negative results - however, a negative flag will be set so that 8xx (BRP) can be used properly.
3xx
STA
STORE
Store the contents of the accumulator in mailbox xx (destructive).
Note: the contents of the accumulator (calculator) are not changed (non-destructive), but contents of mailbox are replaced regardless of what was in there (destructive)
5xx
LDA
LOAD
Load the value from mailbox xx (non-destructive) and enter it in the accumulator (destructive).
6xx
BRA
BRANCH(unconditional)
Set the program counter to the given address (value xx). That is, value xx will be the next instruction executed.
7xx
BRZ
BRANCH IF ZERO (conditional)
If the accumulator (calculator) contains the value 000, set the program counter to the value xx. Otherwise, do nothing.
Note: since the program is stored in memory, data and program instructions all have the same address/location format.
8xx
BRP
BRANCH IF POSITIVE (conditional)
If the accumulator (calculator) is 0 or positive, set the program counter to the value xx. Otherwise, do nothing.
Note: since the program is stored in memory, data and program instructions all have the same address/location format.
901
INP
INPUT
Go to the INBOX, fetch the value from the user, and put it in the accumulator (calculator)
Note: this will overwrite whatever value was in the accumulator (destructive)
902
OUT
OUTPUT
Copy the value from the accumulator (calculator) to the OUTBOX.
Note: the contents of the accumulator are not changed (non-destructive).
0
HLT
HALT
Stop working.
DAT
DATA
This is an assembler instruction which simply loads the value into the next available mailbox. DAT can also be used in conjunction with labels to declare variables. For example, DAT 984 will store the value 984 into a mailbox.
Explanation / Answer
00 : 901 inp Get data from user and store it 01 : 390 sta 90 02 : 901 inp 03 : 391 sta 91 04 : 901 inp 05 : 392 sta 92 06 : 590 lda 90 Load First 07 : 291 sub 91 Sub Second 08 : 812 brp 12 If Positive, First is larger, go output First 09 : 391 lda 91 Load Second 10 : 902 out Output Second 11 : 614 br 14 Always Branch to compare Second and Third 12 : 390 lda 90 Load First 13 : 902 out Output First 14 : 591 lda 91 Load Second 15 : 292 sub 92 Sub Third 16 : 820 brp 20 If Positive, Second is larger, go output 17 : 392 lda 92 Load Third 18 : 902 out Output Third 19 : 622 br 22 Always Branch 20 : 391 lda 91 Load Second 21 : 902 out Output Second 22 : 590 lda 90 Load First 23 : 291 sub 91 Sub Second 24 : 827 brp 27 If Positive, First is larger, go output 25 : 591 lda 91 Load Second 26 : 902 out Output Second 27 : 590 lda 90 Load First 28 : 902 out Output First 29 : 000 hlt 90 : First
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.