BEQ Instruction Property 2

The branch-on-equal (BEQ) instruction compares values in the left and right memory cells. If the values are not equal, then the Program Counter (PC) is incremented by 1. In other words, the computer simply moves to the next instruction. More formally:

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

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

In the following example, the PC is initially 0, so the computer will first execute instruction #0, which is a BEQ instruction. In this instruction, left is 1, so the computer looks up the value in memory cell #1, which is 7. Similarly, right is 2, and the value in memory cell #2 is 5. The values 7 and 5 are not equal. Since the values are not equal, the computer increments the PC by 1.
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
  • not (value of cell 1 at time 0 = value of cell 2 at time 0)

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


Comments

Please log in to add comments