36 www.ubicom.com IP2022 Data Sheet All of these instructions take one clock cycle for execution. Arithmetic and Shift Instructions Each arithmetic or shift instruction performs an operation
such as add, subtract, add with carry, subtract with carry,
rotate  left  or  right  through  carry,  increment,  decrement,
clear  to  zero,  or  swap  high/low  nibbles.  The  compare
(cmp)   instruction   performs   the   same   operation   as
subtract, but it only updates the C, DC, and Z flags of the
STATUS    register;    the    result    of    the    subtraction    is
discarded.
There  are  instructions  available  (incsz,  decsz)  that
increment  or  decrement  a  register  and  simultaneously
test the result. If the 8-bit result is zero, the next instruction
in the program is skipped. These instructions can be used
to make program loops. There are also compare-and-skip
instructions   (cse,   csne)   which   perform   the   same
operation  as  subtract,  but  perform  a  conditional  skip
without affecting either operand or the condition flags in
the STATUS register.
All of the arithmetic and shift instructions take one clock
cycle for execution, except in the case of the test-and-skip
instructions when the tested condition is true and a skip
occurs,  in  which  case  the  instruction  takes  at  least two
cycles. If a skip instruction is immediately followed by a
loadh,  loadl,  or  page  instruction  (and  the  tested condition is true) then two instructions are skipped and the
operation   consumes   three   cycles.   This   is   useful   for
skipping  over  a  conditional  branch  to  another  page,  in
which a  page  instruction precedes a jmp  instruction. If
several page or loadh/loadl instructions immediately
follow a skip instruction, then they are all skipped plus the
next instruction and a cycle is consumed for each. These
“extended skip instructions” are interruptible, so they do
not affect interrupt latency.
Bit Operation Instructions There are four bit operation instructions: setb—sets a single bit in a data register without af- fecting other bits clrb—clears a single bit in a data register without af- fecting other bits sb—tests a single bit in a data register and skips the next instruction if the bit is set snb—tests a single bit in a data register and skips the next instruction if the bit is clear All of the bit operation instructions take one clock cycle for
execution, except for test-and-skip instructions when the
tested condition is true and a skip occurs.
Data Movement Instructions A data movement instruction moves a byte of data from a
data memory location to either the W register or the top of
stack, or it moves the byte from either the W register or the
top  of  stack  to  a  data  memory  location.  The location  is
specified  by  the  “fr”  field.  The  SPH/SPL  register  pair
points to the top of stack. This stack is independent of the
hardware stack used for subroutine call and return.
Program Control Instructions A   program   control   instruction   alters   the   flow   of   the
program by changing the contents of the program counter.
Included in this category are the jump, call, return-from-
subroutine, and interrupt instructions.
The  jmp  instruction has a single operand that specifies
the entry point at which to continue execution. The entry
point  is  typically  specified  in  assembly  language  with  a
label, as in the following code example:
If the carry bit is set to 1, the jmp instruction is executed
and program execution continues where the do_carry
label appears in the program.
The  call  instruction works in a similar manner, except
that it saves the contents of the program counter before
jumping to the new address. It calls a subroutine that is
terminated by a ret instruction, as shown in the following
code example:
Returning from a subroutine restores the saved program
counter   contents,   which   causes   program   to   resume
execution  with  the  instruction  immediately  following  the
snb status,0   ;test the carry bit jmp do_carry   ;jump to do_carry routine ;if C = 1 ...
do_carry:
;jump destination label ... ;execution continues here call add_2bytes   ;call subroutine ;add_2bytes nop ;execution returns to
;here after the
;subroutine is finished
...
add_2bytes:
;subroutine label ... ;subroutine code goes
;here
ret ;return from subroutine