Section 9.4: A program with a loop (Frame 7)                     [prev][home][next]

Remember that x-y was performed and the condition bits set. Since we got this far, we know that Z != 1, which means they are not equal. But is x > y? If x is greater than y, then x-y would be positive. If it is positive then we should execute the THEN clause. This can be negated logically to say that if x-y is negative then we should go to the ELSE clause, giving rise to JN ELSE. Had we insisted on using the other form, i.e. jumping to the THEN clause, then we would have needed another instruction:

   3:  IF:        JP    THEN      ;      if (x > y)
   4:             JMP   ELSE
   5:  THEN:      STD   X         ;           x = x - y;
   6:             JMP   ENDIF     ;
   7:  ELSE:      LOD   Y         ;      else
   8:             SUB   X         ;
   9:             STD   Y         ;           y = y - x;
  10:  ENDIF:     NOP             ;