menu_top_normal
NeoLoch Home Page
Home Inquisitor Tester Learning Lab Consulting Shipping Policy Contact us Support ----------------------
News
Coming soon! 9060 Blade.
SUBWF Command:
Syntax:
Status Flags Effected:
SUBWF
SUBWF f,d
C, DC, Z
The SUBWF command will subtract the contents of the w (working) register from the register specified by the label f. The result of the subtraction is either stored in the working register or the register specified by d (if d = 0 then the result is stored in the working register. If d = 1 the result is stored in the register specified by f.)

Code Example 1: Assume we have a register labeled TEMP. The following sequence of commands will subtract the value 0x0F from the current contents of TEMP.
CLRF         TEMP  
MOVLW    0x0F
SUBWF     TEMP,F
clear the contents of temp (temp = 0)
load w with the value 0x0F (decimal: 15)
subtract 0x0F to TEMP and store the result in TEMP

Code Example 2: Same as above, but now the results are stored in the W register.
CLRF         TEMP  
MOVLW    0x0F
SUBWF     TEMP,W
clear the contents of temp (temp = 0)
load w with the value 0x0F (decimal: 15)
subtract 0x0F to TEMP and store the result in W.


After the SUBWF command has executed, status flags will be set or cleared depending on the result of the subtraction, these status flags are:

C (carry flag) Z (zero flag) DC (digit carry flag)
0 = A borrow did occur.
1 = A borrow did not occur.
0 = The result of the subtraction result is not zero.
1 = The result of the subtraction result is zero.
0 = A borrow from the low order 4 bits did occur.
1 = A borrow from the low order 4 bits did not occur.


Code Exampe3: In this example, we’ll subtract 0x01 (decimal: 1) from TEMP, which will contain the value 0x01 (decimal: 1), and see how this operation effects the status flags.
MOVLW     0x01
MOVWF    TEMP 
MOVLW    0XFF 
SUBWF    TEMP,f 
move the value 0x01 (decimal: 1) into the w register.
copy the contents of w into TEMP.
move the value 0xFF (decimal: 255) into the w register.
subtract the contents of w with the contents of TEMP and store the result back in TEMP.

Subtracting 1 from 1 leaves us with zero, now since the value is zero, this means the Z flag will be set and we can test this to see if one value is equal to another value. And, since we didn't do a digit carry nor a borrow, both C and DC will be set indicating that no borrowing happened.










All contents of this website are copyrighted 2010-2018 NeoLoch