| CODE |
| CBLOCK 0x020 ; Start of RAM for the PIC16F877 Reg_8 ; Define the 8 Bit Register Reg_16:2 ; Define the first 16 Bit Register Reg2_16:2 ; Define the 2nd 16 Bit Register ENDC |
| CODE |
| incf Reg, f ; Increment the Low byte btfsc STATUS, Z ; Do we have Zero (Multiple of 256)? incf Reg + 1, f ; Increment High byte (if necessary) |
| CODE |
| infsnz Reg, f ; Increment "Reg's" Low Byte and Skip incf Reg + 1, f ; High Byte Increment if Result is Not ; Equal to Zero |
| CODE |
| movf Reg, f ; Set "Z" if LOW "Reg" == 0 btfsc STATUS, Z decf Reg + 1, f ; If Low byte is Zero, Decrement High decf Reg, f |
| CODE |
| movlw HIGH 0x01234 ; Add the high byte first addwf Reg + 1, f movlw LOW 0x01234 ; Add the Low Byte Next addwf Reg, f btfsc STATUS, C ; Don't Inc high byte if carry Reset incf Reg + 1, f |
| CODE |
movlw LOW 0x01234 ; Add Low Byte First addwf Reg, f movlw HIGH 0x01234 ; Add High Byte Next addwfc Reg + 1, f |
| CODE |
movlw HIGH 0x01234 ; Subtract the High Byte First subwf Reg + 1, f movlw LOW 0x01234 ; Subtract the Low Byte Next subwf Reg, f btfss STATUS, C ; Don't Dec high byte if carry Set decf Reg + 1, f |
| CODE |
movlw LOW 0x01234 ; Subtract the Low Byte First bsf STATUS, C ; Don't pass any "Borrow" subwfb Reg, f ; Reg = Reg – w - !C movlw HIGH 0x01234 subwfb Reg + 1, f ; Reg + 1 = Reg + 1 – w - !C |
| CODE |
movlw HIGH 0x05678 ; Add High Byte First addwf Source + 1, w movwf Destination + 1, f ; Store Result in Destination movlw LOW 0x05678 ; Add Low Byte Next addwf Source, w movwf Destination, f ; Store Result btfsc STATUS, C ; Is the Carry Flag Set? incf Destination + 1, f ; Yes, Increment High Byte |
| CODE |
movf a + 1, w ; Add the High Bytes addwf b + 1, w movwf c + 1 movf a, w ; Add the Low Bytes addwf b, w movwf c btfsc STATUS, C ; Increment due to Carry incf c + 1 |
| CODE |
movf b + 1, w ; Get Value to be subtracted subwf a + 1, w ; Do the High Byte movwf c + 1 movf b, w ; Get the Value to be Subbed subwf a, w movwf c btfss STATUS, C ; Look for the Carry decf c + 1 |
| CODE |
movlw 0x0A5 ; Get Value for ANDING andwf Reg + 1, f ; Do the High Byte andwf Reg, f ; Do the Low Byte |
| CODE |
bcf STATUS, C ; Clear the Carry Flag for new bit rlf Reg, f ; Shift the Low Byte rlf Reg + 1, f ; Shift High Byte with Low Carry |
| CODE |
bcf STATUS, C ; Clear Carry Flag for the New bit rrf Reg + 1, f ; Shift down the High Byte rrf Reg, f ; Shift Low Byte with Valid Carry |
| CODE |
movf Reg2 + 1, w ; Get the High Byte of the Result subwf Reg1 + 1, w movwf _2 ; Store in a Temporary Register movf Reg2, w ; Get the Low Byte subwf Reg1, w btfss STATUS, C ; Decrement High if Necessary decf _2 |
| CODE |
iorwf _2, w ; Is the Result == 0? |
| CODE |
btfss STATUS, Z ; Execute following Code if == 0 goto Zero_Skip ; Else, Code != 0, Skip Over |
| CODE |
btfsc STATUS, Z ; Execute following if != 0 goto NotZero_Skip ; Else, Code == 0, Skip Over |
| CODE |
btfsc _2, 7 ; Not Negative, 16 Bit is Greater goto NotGreater_Skip ; Else, Skip if Not Greater than iorwf _2, w ; Is it Equal to Zero? btfsc STATUS, z ; No, It is Greater than Goto NotGreater_Skip ; Else, if Zero, Not Greater than |
| CODE |
btfss _2, 7 ; Negative, 16 Bit is Less Than goto NotLess_Skip ; Else, Skip because Not Less Than |
| CODE |
movf Reg2 + 1, w ; Get the High Byte of the Result subwf Reg1 + 1, w movwf _2 ; Store in a Temporary Register movf Reg2, w ; Get the Low Byte subwf Reg1, w btfss STATUS, C ; Decrement High if Necessary decf _2 iorwf _2, w ; Check for Equal to Zero btfsc STATUS, Z ; If Not Zero, Jump Over goto EqualLess_Skip ; Equals, Jump to the Code btfsc _2, 7 ; If Number is Negative, execute goto EqualLess_Skip ; Else, Jump Over |
| CODE |
clrf Product clrf Product + 1 movlw 16 ; Operating on 16 Bits movwf BitCount Loop ; Loop Here for Each Bit rrf Multiplier + 1, f ; Shift the Multiplier down rrf Multiplier, f ; by one btfss STATUS, C ; If the bit is set, add goto Skip ; the Multiplicand to the ; "Product" movf Multiplicand + 1, w addwf Product + 1, f movf Multiplicand, w addwf Product, f btfsc STATUS, C incf Product + 1, f Skip ; Shift up Multiplicand and bcf STATUS, C ; Loop Around rlf Multiplicand, f rlf Multiplicand + 1, f decfsz BitCount goto Loop |
| CODE |
clrf Product + 2 ; "Product" will be the clrf Product + 3 ; Result of the Operation movlw 16 ; Operating on 16 Bits movwf BitCount Loop ; Loop Here for Each Bit rrf Multiplier + 1, f ; Shift the Multiplier down rrf Multiplier, f ; by one btfss STATUS, C ; If the bit is set, add goto Skip ; the Multiplicand to the ; "Product" clrf Product + 4 movf Multiplicand + 1, w addwf Product + 3, f btfsc STATUS, C ; Make Sure the Carry is Passed incf Product + 4, f ; to the Next Byte movf Multiplicand, w addwf Product + 2, f btfsc STATUS, C incfsz Product + 3, f ; Make Sure Carry is Passed with goto $ + 2 ; the Shift incf Product + 4, f Skip ; Shift "Product" Down with bcf STATUS, C rrf Product + 4, f rrf Product + 3, f ; the Reset Carry from the rrf Product + 2, f ; Multiplier shift down or rrf Product + 1, f ; the result of the sixteen rrf Product, f ; bit addition. decfsz BitCount goto Loop |
| CODE |
clrf Product + 2 ; Clear the High-Order Bits clrf Product + 3 movf Al, w ; Do the "L" Multiplication first mulwf Bl movf PRODL, w ; Save result movwf Product movf PRODH, w movwf Product + 1 movf Al, w ; Do the "I" Multiplication mulwf Bh movf PRODL, w ; Save the Most Significant Byte First addwf Product + 1, f movf PRODH, w addwfc Product + 2, f ; Add to the Last Result movf Ah, w ; Do the "O" Multiplication mulwf Bl movf PRODL, w ; Add the Lower Byte Next addwf Product + 1, f movf PRODH, w ; Add the High Byte First addwfc Product + 2, f btfsc STATUS, C ; Add the Carry incf Product + 3, f movf Ah, w ; Do the "F" Multiplication mulwf Bh movf PORDL, w addwf Product + 2, f movf PRODH, w addwfc Product + 3, f |
| CODE |
clrf Quotient clrf Quotient + 1 movlw 1 ; Initialize Count movwf Count clrf Count + 1 StartLoop ; Find How Large "Divisor" can ; be btfsc Divisor + 1, 7 ; If at the "top", then do goto Loop ; the Division bcf STATUS, C ; Shift Count and Divisor Up rlf Count, f rlf Count + 1, f rlf Divisor, f rlf Divisor + 1, f goto StartLoop Loop ; Now, Take Away "Divisor" ; from "Dividend" movf Divisor, w ; If Dividend => Divisor then subwf Dividend, w ; Take Away movwf Temp movlw 0 btfss STATUS, C movlw 1 addwf Divisor + 1, w subwf Dividend + 1, w btfss STATUS, C goto Skip ; Divisor < Dividend movwf Dividend + 1 ; Save the New Dividend movf Temp, w movwf Dividend movf Count, w ; Add Count to the Quotient addwf Quotient, f movf Count + 1, w addwf Quotient + 1, f ; No Opportunity for Carry Skip ; Shift Divisor/Count Down bcf STATUS, C rrf Divisor + 1, f rrf Divisor, f rrf Count + 1, f ; If Carry Set after Count rrf Count, f ; Shift, Finished btfss STATUS, C ; If Carry NOT Set, then goto Loop ; Process next Bit |