======================================================
Assignment #06 - Little Man Computer Basics
======================================================
- Ian! D. Allen - idallen@idallen.ca - www.idallen.com
0. What is the date of your second Midterm Test?
Thursday November 4 - Week 9 - Midterm #2 of 2 (20%)
Calculators *are* permitted but will not be necessary.
1. List the Instruction Cycle activities for the Little Man Computer (LMC).
1. Read and remember the value in the mailbox located at the address
shown on the counter.
2. Increment the counter.
3. Look up the remembered value on the chart and perform the
indicated action.
Repeat from step 1 until HALT
2. With reference to the full extended LMC opcode table (LMC_opcodes.html),
which LMC instruction(s) would not work "properly" if the LM incremented
the counter *after* performing the instruction instead of before?
JMP and CALL would not work properly.
JMP would go to the wrong location (one after), and CALL would both
save the wrong return address (one before) and then jump to the
wrong location (one after).
3. What is the purpose of the LMC mnemonic pseudo-instruction DAT?
DAT: reserve and possibly initialize memory (a mailbox) at the
current address - i.e. put values into mailboxes (memory)
4. Which LMC instructions set the values of the three LMC light flags?
Only ADD and SUB.
5. What is the only way that the N (negative) flag can come on?
Give an example.
Subtract a larger number from the Calculator, e.g. subtract 4 from 3.
Only SUB can do this.
6. Can the N flag and P (positive) flag ever both be on at the same time?
Give an example.
Never on at the same time. No examples.
7. Can the N flag and Z (zero) flag ever both be on at the same time?
Give an example.
Never on at the same time. No examples.
8. a) What value appears in the Calculator if you start with 999 and
then add one?
9. b) What are the on/off states of the three lights N,Z,P afterward?
999+001=000 N:off Z:on P:on
10. a) What value appears in the Calculator if you start with zero and
then subtract one?
11. b) What are the on/off states of the three lights N,Z,P afterward?
000-001=999 N:on Z:off P:off
For each of the following nine actions, give the final value in the
Calculator and indicate the on/off state of the three indicator
lights N, Z, and P. Assume that no lights are on to begin with.
Note: no lights change for input or output, only for ADD and SUB
12. a) Input 400 into Calculator. ANSWER: 400 N:off Z:off P:off
13. b) 600 is subtracted. ANSWER: 800, N:on Z:off P:off
14. c) 600 is subtracted again. ANSWER: 200, N:off Z:off P:on
15. d) 600 is subtracted again. ANSWER: 600, N:on Z:off P:off
16. e) 600 is subtracted again. ANSWER: 000, N:off Z:on P:on
17. f) 600 is subtracted again. ANSWER: 400, N:on Z:off P:off
18. g) 600 is added. ANSWER: 000, N:off Z:on P:on
19. h) 600 is added again. ANSWER: 600, N:off Z:off P:on
20. i) 600 is added again. ANSWER: 200, N:off Z:off P:on
21. a) List all the outputs that would be generated if the following numeric
code were entered into the LMC mailboxes starting at mailbox 00, and
then the LM was awakened. (You should translate this numeric program
into more readable LMC mnemonics and labels before tracing it!)
Mailbox values - read across each line left to right in memory dump format:
117 216 118 416 800 911 116 418 216 600
902 116 418 418 600 700 600 010 002 000
Translation into readable mnemonics:
00 117 LDA TEN
01 216 STO X
02 118 WHILE LDA TWO
03 416 SUB X
04 800 SKN ; skip *into* loop if X > 2
05 911 JMP ENDWH ; exit while loop if X <= 2
06 116 LDA X
07 418 SUB TWO
08 216 STO X
09 600 OUT
10 902 JMP WHILE ; keep looping
11 116 ENDWH LDA X ; after loop
12 418 SUB TWO
13 418 SUB TWO
14 600 OUT
15 700 HLT
16 600 X DAT 600 ; variable
17 010 TEN DAT 010 ; constant
18 002 TWO DAT 002 ; constant
a) Output (five values are output): 8 6 4 2 998
22. b) What is the final value left in memory location 16 at program end?
Mailbox 16 contains 002 at program halt.
c) Optional: After tracing the above program by hand, enter it into
the LMC simulator and verify your answer.
23. a) Translate the following LMC mnemonic code ("assembly language") into
LMC numeric code ("machine language") starting in mailbox 00.
Use the five-column listing format described in the notes:
00 120 LDA ZERO
01 218 STO SUM
02 121 LDA ONE
03 219 STO COUNT
04 123 WHILE LDA FIFTY
05 419 SUB COUNT
06 802 SKP ; skip *into* loop if COUNT <= 50
07 915 JMP ENDWH ; exit while loop if COUNT > 50
08 118 LDA SUM
09 319 ADD COUNT
10 218 STO SUM
11 119 LDA COUNT
12 322 ADD TWO
13 219 STO COUNT
14 904 JMP WHILE ; keep looping
15 118 ENDWH LDA SUM ; after loop
16 600 OUT
17 700 HLT
18 600 SUM DAT 600 ; variable
19 700 COUNT DAT 700 ; variable
20 000 ZERO DAT 000 ; constant
21 001 ONE DAT 001 ; constant
22 002 TWO DAT 002 ; constant
23 050 FIFTY DAT 050 ; constant
24. b) Show the "Label Table" for the above program, linking labels with
mailbox addresses.
Label Table
-----------
WHILE = 04
ENDWH = 15
SUM = 18
COUNT = 19
ZERO = 20
ONE = 21
TWO = 22
FIFTY = 23
25. c) Re-code the above program into a Java or C++ program or pseudocode
that performs, as closely as possible, the same operations in the
same order. Do not optimize your program or re-order the
statements. Do a direct translation.
int sum = 600
int count = 700
sum = 0
count = 1
while ( count <= 50 ) {
sum += count
count += 2
}
output sum
26. d) In simple English, what does the above program do?
Sums every second integer from 1 to 50, inclusive, and outputs the sum.
--
| Ian! D. Allen - idallen@idallen.ca - Ottawa, Ontario, Canada
| Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/
| College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/
| Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/