SX User’s Manual Rev. 3.1 122 © 2000 Scenix Semiconductor, Inc. All rights reserved. www.scenix.com Chapter 3 Instruction Set 3.6.52 SUB fr,W Subtract W from fr Operation: fr = fr - W Bits affected: C, DC, Z Opcode: 0000 101f ffff Description: This instruction subtracts the contents of W from the contents of the specified file
register and writes the 8-bit result into the same file register. W is left unchanged.
The register contents are treated as unsigned values.
If the result of subtraction is negative (W is larger than fr), the C bit is cleared to 0
and the lower eight bits of the result are written to the file register. Otherwise, the
C bit is set to 1.
If there  is a  borrow from bit 3 to  bit  4, the  DC  (digit carry)  bit is  cleared to 0.
Otherwise, the bit is set to 1.
If the result of subtraction is 00h, the Z bit is set. Otherwise, the bit is cleared. Config. Option: If the CF bit in the FUSEX configuration register has been programmed to 0, this
instruction also subtracts the complement of the C bit as a borrow-in input:
fr = fr - W - /C See  Example  2  below  for  a  program  example  of  multiple-byte  subtraction  with
borrow.
Cycles: 1 Example 1: sub $0D,W This example subtracts the contents of W from file register 0Dh. For example, if the
file register contains 35h and W contains 06h, this instruction subtracts 06h from
35h and writes the result, 2Fh, into the file register. It also sets the C bit, clears the
DC bit, and clears the Z bit.
Example 2: set $03.0 ;set carry bit for no borrow in mov W,$0A  ;load W from 0Ah (low-order byte)
sub $0C,W  ;low-order subtraction, C=0 for borrow out
mov W,$0B  ;load W from 0Bh (high-order byte)
sub $0D,W  ;high-order subtraction, borrow in & out