BEQ Instruction Property

The branch-on-equal (BEQ) instruction compares values in the left and right memory cells. If the values are equal, then the computer adds imm + 1 to the current Program Counter (PC). In other words, BEQ allows us to skip some instructions if the condition is met. More formally:

if the following are true:
  • instruction #i is beq left=left right=right imm=imm
  • the PC at time t = i
  • value of cell left at time t = value of cell right at time t

then the PC at time (t + 1) = (i + 1) + imm

In the following example, the BEQ instruction is in instruction #1. In the instruction, left is 1 so the computer looks up the value in memory cell #1, which is 4. Similarly, right is 2, and the value in memory cell #2 is also 4. The value on both cells is 4, so they are equal. Since the values are equal, the computer adds imm + 1 to the current PC:

next PC = current PC + imm + 1

next PC = 0 + 2 + 1

next PC = 3

Instructions
Memory Cells
Program Counter Time
0 0
LW Computer Simulator

This example can be expressed as:

if the following are true:

  • instruction #0 is beq left=1 right=2 imm=2
  • the PC at time 0 = 0
  • value of cell 1 at time 0 = value of cell 2 at time 0

then the PC at time (0 + 1) = (0 + 1) + 2


Comments

Please log in to add comments