levo

Fundamentals of Computer Organisation and Architecture

Machine-Code Operations

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

Overview

Recall questions on the instruction set at this level and on the load, store, add and subtract instructions.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Evaluation

Explain the difference between an unconditional and a conditional branch.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Which basic machine-code operations make up the instruction set used at this level?

    Model answer

    Load, add, subtract, store, branching both conditional and unconditional, compare, the logical bitwise operators AND, OR, NOT and XOR, logical shift right, logical shift left, and halt.

  2. 2

    What does a load instruction do?

    Model answer

    It copies a value into a register in the processor. With direct addressing it copies the contents of a given memory location into the register, for example LDR R1, 100 puts the contents of location 100 into register 1. The value in memory is unchanged: load copies, it does not move. An instruction that puts an immediate constant into a register, such as MOV R1, #7, does the same job for a fixed value.

  3. 3

    What does a store instruction do, and how is it the opposite of load?

    Model answer

    It copies the contents of a register out to a memory location, for example STR R1, 100 writes the contents of register 1 into location 100, overwriting whatever was there. Load brings a value into the processor and store sends it back out. A program typically loads its variables into registers, works on them, and stores the results back before halting.

  4. 4

    Describe the add and subtract instructions.

    Model answer

    Add takes two operands, adds them in the arithmetic logic unit and places the result in a destination register, for example ADD R0, R1, #5 puts the contents of R1 plus 5 into R0, and ADD R0, R1, R2 puts the sum of the two registers into R0. Subtract works the same way and subtracts the second operand from the first, so SUB R0, R1, #5 puts the contents of R1 minus 5 into R0. Both set the flags in the status register according to the result.

  5. 5

    What does a compare instruction do?

    Model answer

    It compares two values, typically by subtracting the second from the first inside the arithmetic logic unit, and sets the flags in the status register according to the outcome, for example setting the zero flag if the two were equal and the negative flag if the first was smaller. Crucially it discards the result of the subtraction, so neither operand is changed: its only effect is on the flags. It is therefore always followed by a conditional branch, which reads those flags.

  6. 6

    Explain the difference between an unconditional and a conditional branch.

    Model answer

    An unconditional branch always transfers control: the branch address is copied into the program counter every time the instruction is executed, so the following instruction is never reached. A conditional branch first tests a flag in the status register, set by the preceding compare or arithmetic instruction, and copies the address into the program counter only if the condition is satisfied; otherwise the program counter keeps its incremented value and execution continues in sequence. Conditional branches are how selection and iteration are built in machine code, since the high-level IF and WHILE constructs have no direct equivalent.

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.