Myke's Home Page

Book CD-ROM Home

File Copying/Harddrive Setup

Development Tools

Experiments

Projects

Useful Code Snippets and Macros

Introduction to Electronics

Introduction to Programming

Datasheets

PCBs

Links

McGraw-Hill Professional Publishing

"CondJump" Experiment

Conditional jumping in the PICmicro MCU is quite different than in other processors due to the lack of instructions like "jz"/"jc"/etc. which jump to an address based on the state of the STATUS flags. The PICmicro has the ability of skipping over an instruction based on the state of any bit in the PICmicro MCU's register space. This experiment demonstrates how to create traditional jumps on conditions using the skip instructions.

The standard form for comparing two values and jumping on conditions is:

  movf    Parameter1, w
  subwf   Parameter2, w
  btfss|c STATUS, Z|C		;  "Test" Entry in Table Below
   goto   ConditionalJump
              
where, the following conditions can be implemented:

Condition Parameter1 Parameter2 Test
A == B A B btfsc STATUS, Z
A != B A B btfss STATUS, Z
A > B A B btfss STATUS, C
A >= B B A btfsc STATUS, C
A < B B A btfss STATUS, C
A <= B A B btfsc STATUS, C

The source code is listed below, or it can be accessed from the CD-ROM by clicking Here.

 title  "CondJump - Conditional Jumping"
;
;  This application shows how conditional jumping can be
;   implemented in a variety of different situations, 
;   including interpage jumps.   
;
;  Myke Predko
;  99.12.29
;
;  Hardware Notes:
;  Simulated 16C73B
;  No I/O
;
 LIST P=16C73B, R=DEC
 INCLUDE "p16c73b.inc"

;  Registers
 CBLOCK 0x020
Flags
i, j
 ENDC

#define TestFlag Flags, 0	;  Define a File Register Flag

 __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC

  PAGE
;  Mainline of CondJump

  org 0

  clrf   Flags			;  No Flag is Set

  movlw  5			;  Setup Test Variables
  movwf  i
  movlw  7
  movwf  j

;  if (i < j) 
;   TestFlag = 1;

  movf   j, w			;  Subtract "j" from "i"
  subwf  i, w			;   And Look at Carry Result
  btfsc  STATUS, C
   goto  $ + 2
  bsf    TestFlag  

;  if (TestFlag == 1) 
;   goto LongJump

  movlw  HIGH LongJump		;  Set up PCLATH for the Long Jump
  movwf  PCLATH
  btfsc  TestFlag
   goto  LongJump & 0x07FF
  movlw  HIGH $			;  Restore PCLATH to the Current
  movwf  PCLATH			;   Page

  goto   $ 			;  Endless Loop if TestFlag == 0

 org     0x0800
LongJump

;  for (j = 0; j < 7; j++ )
;    i = i + 1;

  incf   i, f			;  Increment "i", "j" Times
  decfsz j, f
   goto  $ - 2

  goto   $


  end
              

Click Here to look at the eigth experiment - VarMani