Untitled

 avatar
unknown
plain_text
a year ago
1.4 kB
10
Indexable
#include"xc.inc"
GLOBAL _lcm

PSECT mytest, local, class=CODE,reloc=2

_lcm:
    init:
	MOVFF 0x01, 0x10
	MOVFF 0x03, 0x11
	start:
	    ;find GCD
	    MOVFF 0x11, WREG
	    CPFSGT 0x10 ; skip if 0x10 is greater 
		GOTO oneGreater
	    GOTO zeroGreater
	    oneGreater:
		MOVFF 0x10, WREG
		SUBWF 0x11
		CPFSGT 0x11 ; skip if 0x11 is greater
		    GOTO thispartend
		GOTO oneGreater
	    zeroGreater:
		MOVFF 0x11, WREG
		SUBWF 0x10
		CPFSGT 0x10
		    GOTO thispartend
		GOTO zeroGreater
	    thispartend:
		TSTFSZ 0x10 ; skip if zero  
		    GOTO next
		MOVFF 0x11, 0x20
		next:
		TSTFSZ 0x11 
		    GOTO next2
		MOVFF 0x10, 0x20 
		next2:
		TSTFSZ 0x20
		    GOTO ending
		GOTO start
		
	;use 0x12 as first num, 0x13 as second num
	ending:
	endinginit:
	    MOVFF 0x20, WREG
	    MOVFF 0x01, 0x10
	    MOVFF 0x03, 0x11
	    loop1:
		TSTFSZ 0x10 ;skip if zero
		    GOTO nextt
		GOTO loop2
		nextt:
		    SUBWF 0x10
		    INCF 0x12
		    GOTO loop1
	    loop2:
		TSTFSZ 0x11 
		    GOTO nextt2
		GOTO nexttt
		nextt2:
		    SUBWF 0x11
		    INCF 0x13
		    GOTO loop2
	    nexttt:
		MOVFF 0x12, WREG
		MULWF 0x13
		;store 
		MOVFF PRODL, 0x31
		MOVFF PRODH, 0x30
		MOVFF 0x20, WREG
		MULWF 0x31
		MOVFF PRODL, 0x41
		MOVFF PRODH, 0x40
		MULWF 0x30
		MOVFF PRODL, WREG
		ADDWF 0x40
		MOVFF 0x40,0x02
		MOVFF 0x41, 0x01
		RETURN
	    
Editor is loading...