levo

Fundamentals of Computer Organisation and Architecture

Shifts, Halting and Assembly Language Programs

  • 2 things to know
  • Paper 2
Start revising · £5/month

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.

Your recallNot started
Numbers

Describe a logical shift left and state its arithmetic effect.

Process

What does a halt instruction do?

Questions from this subtopic

Each one with the model answer underneath.

  1. 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. 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. 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. 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. 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. 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.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A driver is .
softwarehardwarestorage

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

Head means the first single element of a non-empty list.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Fundamentals of Computer Organisation and Architecture, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.