AQA A-Level Computer Science 7517
Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation
Fundamentals of Data Representation
Fundamentals of Computer Systems
Fundamentals of Computer Organisation and Architecture
Fundamentals of Communication and Networking
Consequences of Uses of Computing
Systematic Approach to Problem Solving
Fundamentals of Databases
Big Data
Fundamentals of Computer Organisation and Architecture
Shifts, Halting and Assembly Language Programs
- 2 things to know
- Paper 2
Overview
Recall questions on logical shifts left and right and their arithmetic effect, the halt instruction, hand-tracing assembly language programs with loops and branches, and why labels are used.
What you need to know
Answer each one before you reveal it.
What does a halt instruction do?
Questions from this subtopic
Each one with the model answer underneath.
- 1
Describe a logical shift left and state its arithmetic effect.
Model answer
Every bit is moved one place towards the most significant end for each place shifted; zeros are fed in at the least significant end, and bits shifted off the most significant end are lost. For example LSL by 2 turns 00000101 into 00010100. The arithmetic effect is multiplication by 2 to the power of the number of places, so 5 becomes 20 here. That is only true, however, while no significant bit is lost off the top: shifting 10000001 left by one gives 00000010, which is nothing like double the original.
- 2
Describe a logical shift right and state its arithmetic effect.
Model answer
Every bit is moved one place towards the least significant end for each place shifted; zeros are fed in at the most significant end, and bits shifted off the least significant end are lost. For example LSR by 1 turns 00001011 into 00000101. The arithmetic effect is integer division by 2 to the power of the number of places, discarding any remainder, so 11 becomes 5 rather than 5.5. Because a logical shift always brings in zeros, it does not preserve the sign of a two's complement negative number, so it is only a correct division for unsigned values.
- 3
Why is 'logical' the important word in 'logical shift'?
Model answer
Because it says what is fed in at the vacated end: zeros, always, regardless of what the bits mean. The alternative kinds of shift treat the contents differently, for example preserving the sign bit or wrapping the bits round, and would give different answers for the same operand. Saying logical shift fixes the behaviour exactly and is why the answer to a shift question is never ambiguous.
- 4
What does a halt instruction do?
Model answer
It stops the Fetch-Execute cycle so that no further instructions are fetched or executed, ending the program. It is needed because the processor would otherwise carry straight on into whatever bytes follow the last instruction in memory and attempt to execute them, with unpredictable results. Every hand-written assembly program must end with one.
- 5
Trace this program by hand and state the final contents of registers and memory. Assume memory location 90 holds 12. LDR R0, 90; ADD R1, R0, #4; STR R1, 91; HALT.
Model answer
LDR R0, 90 uses direct addressing, so R0 receives the contents of location 90, which is 12. ADD R1, R0, #4 uses immediate addressing for the second operand, so R1 receives 12 + 4 = 16. STR R1, 91 writes the contents of R1 into memory location 91, so location 91 now holds 16. HALT stops the processor. Final state: R0 = 12, R1 = 16, location 90 still holds 12 because load only copies, and location 91 holds 16.
- 6
Hand-trace this loop and state what it computes. MOV R0, #0; MOV R1, #5; loop: ADD R0, R0, R1; SUB R1, R1, #1; CMP R1, #0; BNE loop; STR R0, 100; HALT.
Model answer
R0 starts at 0 and R1 at 5. Pass one: R0 = 0 + 5 = 5, R1 = 4, the compare finds R1 is not 0, so the branch is taken. Pass two: R0 = 5 + 4 = 9, R1 = 3, branch taken. Pass three: R0 = 9 + 3 = 12, R1 = 2, branch taken. Pass four: R0 = 12 + 2 = 14, R1 = 1, branch taken. Pass five: R0 = 14 + 1 = 15, R1 = 0, the compare sets the zero flag, so the branch is not taken and execution falls through. STR writes 15 into location 100 and HALT stops. The program computes the sum of the integers from 1 to 5, which is 15, using R0 as a running total and R1 as a counter.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Fundamentals of Computer Organisation and Architecture, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.