please dont rip this site

PIC Microcontoller Subtraction Math Method

32 bit unsigned substraction from Eddy Gora



;------------------------------------------------------------------------
; This is simple routine for full unsigned 32 bit substract
; a - b and result back in a ( initially a is lost )
; on exit success, CARRY = 0, on fail ( substraction negative ) CARRY = 1
; can be easly reduced / increased for 8 / 16 / 32 / 64 bits
; no optimisations ( tricks ) are made
; enjoy, eddy@hcv.ro from HCV Grup Ltd.,

      __Config   3FF1h

       include    <p16f877a.inc>



a1    equ       0x20
a2    equ       0x21
a3    equ       0x22
a4    equ       0x23

b1    equ       0x24
b2    equ       0x25
b3    equ       0x26
b4    equ       0x27

        org    0
  
START 
        clrf     a1  
        clrf     a2
        clrf     a3
        clrf     a4
        clrf     b1
        clrf     b2
        clrf     b3
        clrf     b4

        movlw   0x9c                 
        movwf   a1 
        movlw   0x00                 
        movwf   a2 
        movlw   0x00                  
        movwf   a3 
        movlw   0xE2
        movwf   a4 			; MSB

        movlw   0x9d
        movwf   b1 
        movlw   0xff
        movwf   b2 
        movlw   0x4f
        movwf   b3 
        movlw   0xc0
        movwf   b4 			; MSB

        nop
		call	SUBB_32
		nop


SELF
	goto	SELF

;------------------------------------------------------------------------
; This is simple routine for full unsigned 32 bit substract
; a - b and result back in a ( initially a is lost )
; on exit success, CARRY = 0, on fail ( substraction negative ) CARRY = 1
; can be easly reduced / increased for 8 / 16 / 32 / 64 bits
; no optimisations ( tricks ) are made
; enjoy, eddy@hcv.ro from HCV Grup Ltd.,

SUBB_32
	bcf		STATUS,C	; clear our routine return flag	

	movf    b1,W    	; substract first LSB bytes
    subwf   a1,F    	; a1 - b1 --&gt; a1
						; a > b --&gt; c=1
						; a = b --&gt; c=1
						; a < b --&gt; c=0 we have BORROW
	btfsc	STATUS,C	; have BORROW ?
	goto	NO_BORROW1	; 1 NO
						; 0 YES, so substract 1 from the next LSB
	movlw	.1
	subwf	a2,F
	btfsc	STATUS,C	; have also BORROW here ?
	goto	NO_BORROW1	; 1
						; 0 YES, so substract more, 1 from next
	movlw	.1
	subwf	a3,F
	btfsc	STATUS,C	; still BORROW ?
	goto	NO_BORROW1	; 1
						; 0 YES, substract 1 from the last
	movlw	.1
	subwf	a4,F		

	btfsc	STATUS,C	
	goto	NO_BORROW1
	bsf		STATUS,C	; if another BORROW, the substraction result is negative
						; so return quick with CARRY = 1
	return
NO_BORROW1

	movf    b2,w     	; the same manner ...	
    subwf   a2,f     	
	btfsc	STATUS,C	
	goto	NO_BORROW2	
	movlw	.1
	subwf	a3,F
	btfsc	STATUS,C	
	goto	NO_BORROW2	
	movlw	.1
	subwf	a4,F		
	btfsc	STATUS,C	
	goto	NO_BORROW2
	bsf		STATUS,C	
	return
NO_BORROW2
	movf    b3,w     	
    subwf   a3,f     	
	btfsc	STATUS,C	
	goto	NO_BORROW3	
	movlw	.1
	subwf	a4,F
	btfsc	STATUS,C
	goto	NO_BORROW3
	bsf		STATUS,C
	return
NO_BORROW3
	movf    b4,w    
    subwf   a4,f    
	btfsc	STATUS,C
	goto	NO_BORROW4
	bsf		STATUS,C
	return
NO_BORROW4
	bcf		STATUS,C
	return
;-----------------------------------------------------------------------	

	end


file: /Techref/microchip/math/sub/32bb-eg.htm, 4KB, , updated: 2009/2/13 15:12, local time: 2024/11/25 18:06,
TOP NEW HELP FIND: 
3.144.116.195:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/Techref/microchip/math/sub/32bb-eg.htm"> PIC Microcontoller Subtraction Math Method </A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .