(DOCX, Unknown)

advertisement
Little Man Computer
Instruction Set
http://peterhigginson.co.uk/LMC/lmcgraphic_plh.gif
Task 1
Ask the user for 3 numbers. Print them out in reverse order:
Test data:
Inputs
Outputs
7,8,9
9,8,7
8 , 16 , 32
32 , 16 , 8
Finished Code:
INP
STA 99
INP
STA 98
INP
STA 97
LDA 97
OUT
LDA 98
OUT
LDA 99
OUT
HLT
Task 2
Ask the user for 3 numbers. Add them up and print out the answer.
Test data:
INP
STA 97
INP
STA 98
INP
STA 99
LDA 97
ADD 98
ADD 99
OUT
HLT
Inputs
Outputs
7, 8, 9
24
8 , 16 , 32
56
Task 3
Ask the user for 2 numbers. Print out the first – the second, then the second – the first.
Test data:
Inputs
Outputs
7,3
4 , -4
5 , 12
-7 , 7
INP
STA 97
INP
STA 98
LDA 97
SUB 98
OUT
LDA 98
SUB 97
OUT
HLT
Task 4
Ask the user for 2 numbers. If they are the same then double the number and print it out. If they are different
print them both out individually.
Finished Code:
INP
STA 97
INP
STA 98
LDA 97
SUB 98
BRZ 12
LDA 97
OUT
LDA 98
OUT
HLT
LDA 97
ADD 98
OUT
HLT
Task 5
Ask the user for 2 numbers.
Print out the biggest and then the smallest.
Finished Code:
INP
STA 97
INP
STA 98
LDA 97
SUB 98
BRP bigger
LDA 98
OUT 98
LDA 97
OUT 97
HLT
bigger LDA 97
OUT 97
LDA 98
OUT 98
HLT
Task 6
Ask the user for 2 numbers, print out the result of the biggest number minus the smallest number.
INP
STA 97
INP
STA 98
LDA 97
SUB 98
BRP bigger
LDA 98
SUB 97
OUT
HLT
bigger LDA 97
SUB 98
OUT
HLT
Task 7
Ask the user for a big number then a small number. Using only a BRP to loop round keep subtracting the
smaller number until you get past zero, then output the result.
Finished Code:
INP
STA 97
INP
STA 98
LDA 97
SUB 98
STA 97
BRP 04
OUT 97
HLT
Task 8
Adding to task 7, add a variable which counts how many times you can subtract the smaller number.
Task 9
Write a program which multiplies two numbers together.
INP
STA 99
INP
STA 98
LDA 98
BRZ zero
loop LDA 98
BRZ end
LDA 97
ADD 99
STA 97
LDA 98
SUB one
STA 98
BRA loop
end LDA 97
OUT
HLT
zero OUT 98
HLT
one DAT 01
Task 10
Write a program which can divide 2 numbers.
INP
STA 97
INP
STA 98
LDA 97
BRZ zero
LDA 98
BRZ zero
loop LDA 97
SUB 98
STA 97
LDA one
ADD two
STA one
LDA 97
BRP loop
LDA one
SUB two
OUT
LDA 97
ADD 98
OUT
HLT
zero LDA 96
OUT
one DAT 00
two DAT 01
Task 11
Write a program which can divide the biggest number that the user enters by the smaller number showing
the remainder.
INP
STA 97
INP
STA 98
LDA 97
BRZ zero
LDA 98
BRZ zero
LDA 97
SUB 98
BRP loop
loopTwo LDA 98
SUB 97
STA 98
LDA one
ADD two
STA one
LDA 98
BRP loopTwo
LDA one
SUB two
OUT
LDA 98
ADD 97
OUT
HLT
loop LDA 97
SUB 98
STA 97
LDA one
ADD two
STA one
LDA 97
BRP loop
LDA one
SUB two
OUT
LDA 97
ADD 98
OUT
HLT
zero LDA 96
OUT
one DAT 00
two DAT 01
Download