logo

Question detail

Write a mnemonic instruction sequence that loads the value at memory location 10, compares it with the immediate value 0, and branches to the label ZERO when the values are equal. If they are not equal, the sequence must store the immediate value 1 in memory location 20 and then halt. At ZERO, it must store the immediate value 0 in memory location 20 and then halt. Explain how the compare and conditional branch work.

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

Question

Type

practice

Style

Topic

Structure and role of the processor and its components

Exam-style question

Try this first

Write a mnemonic instruction sequence that loads the value at memory location 10, compares it with the immediate value 0, and branches to the label ZERO when the values are equal. If they are not equal, the sequence must store the immediate value 1 in memory location 20 and then halt. At ZERO, it must store the immediate value 0 in memory location 20 and then halt. Explain how the compare and conditional branch work.

Model answer

What a good answer should say

  • One valid sequence is: LOAD 10 COMPARE #0 BRANCH_IF_EQUAL ZERO LOAD #1 STORE 20 HALT ZERO: LOAD #0 STORE 20 HALT LOAD 10 uses direct addressing to obtain the value in memory location 10.
  • COMPARE #0 compares that value with the immediate value 0.
  • If they are equal, BRANCH_IF_EQUAL ZERO transfers control to the instruction labelled ZERO.
  • If they are not equal, execution continues with LOAD #1, which loads the immediate value 1, and STORE 20 writes it to memory location 20.

Explanation

Why this works

The sequence uses compare followed by a conditional branch. The instruction immediately after the conditional branch is the not-equal path, while the label identifies the equal path.

Direct addressing is used for memory locations 10 and 20, and immediate addressing is used for the constants 0 and 1.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.