Python · A Level 17
Build a Processor: the Little Man Computer
Name
Class
Date
Mark / 32
Section A
Circle the letter of the correct answer. One mark each.
- 1What does the program counter hold?1
- AThe instruction currently being executed
- BThe result of the last calculation
- CThe number of instructions executed so far
- DThe address of the next instruction to be fetched
- 2In the fetch stage, what is the first thing that happens?1
- AThe address in the PC is copied to the MAR
- BThe MDR is copied to the PC
- CThe instruction is decoded
- DThe result is written to the ACC
- 3Which register holds the data that has just been read from memory?1
- AMDR
- BPC
- CCIR
- DMAR
- 4What is the job of the ALU?1
- ATo control the buses
- BTo store the program counter
- CTo fetch instructions from memory
- DTo carry out arithmetic and logical operations
- 5In the LMC, what does the instruction 'BRP loop' do?1
- ABranches to loop if the accumulator is exactly zero
- BBranches to loop if the accumulator is zero or positive
- CBranches to loop if the accumulator is negative
- DBranches to loop every time
- 6What is the machine code for 'LDA 05' in the LMC?1
- A105
- B305
- C505
- D905
- 7Why does an assembler need two passes?1
- AThe first pass runs the program and the second checks it
- BThe first pass removes comments and the second compresses it
- CIt reads each line twice to be sure
- DA branch can refer to a label that appears later in the program
- 8Which addressing mode treats the operand as the data itself?1
- ADirect
- BImmediate
- CIndexed
- DIndirect
- 9Which addressing mode is most useful for stepping through the items in an array?1
- AIndirect
- BDirect
- CIndexed
- DImmediate
- 10What is the main benefit of pipelining?1
- AEach individual instruction is completed faster
- BMore instructions are completed in a given time
- CLess memory is needed
- DBranch instructions no longer cause delays
Section B
Answer in the space provided. The number of marks tells you how many separate points to make.
- 1DescribeDescribe the fetch stage of the fetch-decode-execute cycle, naming the registers that are used.4
- 2StateThe Little Man Computer program shown is run with the input 7. State the values that are output.3
INP STA num loop OUT LDA num SUB two STA num BRP loop HLT num DAT two DAT 2 - 3WriteWrite a Little Man Computer program that inputs two numbers and outputs the larger of the two. You may assume that the numbers are different. Use labels for the branch targets and the data locations.5
- 4ExplainExplain the difference between immediate addressing and direct addressing. Give an example of each.4
- 5DiscussDiscuss how pipelining improves the performance of a processor, and the problems it can introduce.6
Mark scheme
Section A
Section B
1 Describe the fetch stage of the fetch-decode-execute cycle, naming the registers that are used. 4
One mark for each of the following, to a maximum of 4.
- The address in the program counter (PC) is copied to the memory address register (MAR)
- The instruction at that address is fetched from memory (via the data bus) into the memory data register (MDR)
- The program counter is incremented
- The instruction is copied from the MDR to the current instruction register (CIR)
Model answer. The address held in the program counter is copied to the memory address register. The instruction stored at that address is then fetched from memory, along the data bus, into the memory data register. The program counter is incremented so that it points to the next instruction. Finally the instruction is copied from the memory data register to the current instruction register, ready to be decoded.
2 The Little Man Computer program shown is run with the input 7. State the values that are output. 3
One mark for each of the following, to a maximum of 3.
- Outputs 7 first (the input value)
- Each time round the loop 2 is subtracted from the value, so 5 and 3 are output
- The loop ends when the value becomes negative, after 1 has been output: 7, 5, 3, 1
Model answer. The outputs are 7, 5, 3 and 1. The input 7 is stored in num and output. Each time round the loop two is subtracted from num and, while the result is zero or positive, the new value is output. After 1 has been output, subtracting 2 gives -1, which is negative, so BRP does not branch and the program halts.
3 Write a Little Man Computer program that inputs two numbers and outputs the larger of the two. You may assume that the numbers are different. Use labels for the branch targets and the data locations. 5
One mark for each of the following, to a maximum of 5.
- Inputs both numbers and stores them (INP, STA) in labelled locations
- Subtracts one from the other (SUB) to compare them
- Uses a conditional branch (BRP) on the result of the subtraction
- Loads and outputs the correct number in each case (LDA, OUT)
- HLT at the end of each path, and DAT used to define the variables
Model answer.
INP
STA first
INP
STA second
SUB first
BRP secondbig
LDA first
OUT
HLT
secondbig LDA second
OUT
HLT
first DAT
second DATBoth numbers are input and stored. The first is subtracted from the second. If the result is positive the second is larger, so the program branches to secondbig, which loads and outputs it. Otherwise the first is larger and is output. Each path ends with HLT.
4 Explain the difference between immediate addressing and direct addressing. Give an example of each. 4
One mark for each of the following, to a maximum of 4.
- Immediate: the operand is the data itself
- Example of immediate, such as LDA #10 loads the number 10
- Direct: the operand is the address of the data (a memory location)
- Example of direct, such as LDA 10 loads the contents of address 10
Model answer. In immediate addressing the operand is the data itself, so LDA #10 loads the number 10 into the accumulator. In direct addressing the operand is the address of the data, so LDA 10 loads the number that is stored at memory address 10 into the accumulator.
5 Discuss how pipelining improves the performance of a processor, and the problems it can introduce. 6
One mark for each of the following, to a maximum of 6.
- Pipelining overlaps the stages of different instructions, so that one is fetched while another is decoded and another executed
- The processor can complete close to one instruction per cycle, increasing throughput
- Each stage of the processor is kept busy rather than waiting
- A branch instruction means that the instructions already fetched may be wrong, so the pipeline must be flushed
- An instruction may depend on the result of a previous one, causing delays (stalls)
- A reasoned conclusion: the benefits outweigh the problems, and so all modern processors use pipelines
Model answer. Pipelining overlaps the stages of consecutive instructions, so that while one instruction is being executed the next is being decoded and the one after that is being fetched. Each part of the processor is kept busy instead of waiting, and the processor can complete close to one instruction every clock cycle, so the throughput increases greatly, although an individual instruction takes the same time as before. There are problems. When there is a branch instruction the instructions already fetched behind it may be the wrong ones, so the pipeline has to be flushed and cycles are wasted. An instruction may also need the result of one in front of it, so it has to wait. Overall, however, the improvement in throughput outweighs these problems, and so all modern processors use pipelines.