IFEQ (0x99)


The IFEQ instruction is a conditional branch. The branch is successful if the value at the top of the stack is equal to zero. This instruction pops the top element from the stack and sends it to the ALU to see if it is zero. If the Z flag is set (Z=1 means the value is equal to 0) then the branch is successful; otherwise the branch fails.

The operand is a two-byte signed offset. If the branch is successful, this offset is added to the byte address at which the IFEQ opcode was found and the sum is placed into the PC as the address of the next opcode in the instruction stream. Otherwise, the PC is incremented by two in order to skip past the two-byte operand.

When writing assembly language code, the operand must be a program label within the same method. The assembler calculates the proper offset value.

Interpreter Microcode

The microinstructions are listed in the order in which they are executed; not the order in which they are stored in the control store.

0x099  SP=MAR=SP-1; rd; goto 0x38
...
0x038  OPC=TOS; goto 0x39
0x039  TOS=MDR; goto 0x3a
0x03a  ALU=OPC; if Z goto 0x101 else goto 0x1

then (Z Flag = 1)

0x101  OPC=PC-1; fetch; goto 0x2f
...
0x02f  PC=PC+1; fetch; goto 0x30
0x030  H=MBR<<8; goto 0x31
0x031  H=H OR MBRU; goto 0x32
0x032  PC=H+OPC; fetch; goto 0x33
0x033  ALU=0; goto 0x2

else (Z Flag = 0)

0x001  PC=PC+1; goto 0x40
...
0x040  PC=PC+1; fetch; goto 0x41
0x041  ALU=0; goto 0x2

If you compare this microcode with the code that interprets the IFLT and the IF_ICMPEQ instructions, you will notice that the 'then" code and the "else" code are exactly the same in all three.

Example Program

//---------------------------------------------
// Demonstrate the IFEQ instruction.
//
// 1. Clear Memory
// 2. Assemble this program.
// 3. Reset the computer.
// 4. Click the "Display Words" radio button
//    below the memory display.
// 5. Click the "Run" button.
//
// This program will display the letter 'T' in
// the input/output window indicating that the
// branch succeeded.
//
// If you bipush any value other than 0 in the
// first statement, the letter 'F' will be
// displayed indicating that the branch failed.
//---------------------------------------------
.main
    bipush 0
    ifeq a
    bipush 'F'
    goto b
a:  bipush 'T'
b:  out
    halt
.end-main