menu_top_normal
NeoLoch Home Page
Home Inquisitor Tester Learning Lab Consulting Shipping Policy Contact us Support
News
Coming soon! 9060 Blade.
ADDWF Command:
Syntax:
Status Flags Effected:
ADDWF
ADDWF f,d
C, DC, Z
The ADDWF command will add the contents of the w (working) register to the register specified by the label f. The result of the addition 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 add the value 0x0F to the current contents of TEMP.
CLRF         TEMP  
MOVLW    0x0F
ADDWF     TEMP,F
clear the contents of temp (temp = 0)
load w with the value 0x0F (decimal: 15)
add 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
ADDWF     TEMP,W
clear the contents of temp (temp = 0)
load w with the value 0x0F (decimal: 15)
add 0x0F to TEMP and store the result in W.


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

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


Code Exampe3: In this example, we’ll add 0xFF (decimal: 255) to TEMP, which will contain the value 0x01 (decimal: 1), and see how this operation effects the status flags.
MOVLW     0x01
MOVWF    TEMP 
MOVLW    0XFF 
ADDWF    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.
add the contents of w with the contents of TEMP and store the result back in TEMP.

Adding 1 to 255 gives us the value of 256, now since the maximum value an byte (eight bits) can store is 255, the value in w after the addition is equal to zero and the C flag in the status register is set to indicate that a carry has occured. This also means that the value stored back into TEMP is zero. In addition, since the end value is zero the Z (zero) flag will also be set to indicate that the result of the addition ended with a zero value.

So, by testing these flags we can determine that the addition resulted in the contenst in TEMP carried over and that the value in TEMP is zero.


Secured by PayPal
Official PayPal Seal







All contents of this website are copyrighted 2010-2017 NeoLoch, LLC