Untitled

 avatar
unknown
plain_text
2 years ago
2.2 kB
3
Indexable
List p=18f4520
    #include<p18f4520.inc>
        CONFIG OSC = INTIO67
        CONFIG WDT = OFF
        org 0x00
	
	first equ 0xB5
	second equ 0xF8
	third equ 0x64
	fourth equ 0x7F
	fifth equ 0xA8
	sixth equ 0x15
	
	
	MOVLB 0x1
	MOVLW first
	MOVWF 0x00, 1
	MOVLW second
	MOVWF 0x01, 1
	MOVLW third
	MOVWF 0x02, 1
	MOVLW fourth 
	MOVWF 0x03, 1
	MOVLW fifth
	MOVWF 0x04, 1
	MOVLW sixth
	MOVWF 0x05, 1
	LFSR 0, 0x100 ; left
	LFSR 1, 0x105 ; right
	LFSR 2, 0x100 ; i 
	MOVLW 0x01 ; stores
	MOVWF 0xF0	
	
	whileloop:
	; first for loop 
	    for1: ; i = left , i < right , i++
		MOVFF POSTINC2, WREG ; stores arr[i] ; i++
		MOVFF POSTDEC2, 0x02 ; i-- 
		CPFSGT  0x02 
		    GOTO if1
		GOTO endif1
		if1: 
		    ;swap
		    MOVFF POSTINC2, 0x00
		    MOVFF POSTDEC2, 0x01
		    MOVFF 0x01, POSTINC2
		    MOVFF 0x00, POSTDEC2 ; i stays the same
		endif1:
		    ;continue for loop
		    COMF FSR2L, WREG
		    INCF WREG
		    MOVFF PREINC2, 0x20
		    ADDWF FSR1L, W 
		    CPFSLT 0xF0
			GOTO endfor1 ; goes here if the num is positive
		    GOTO for1
		endfor1:
		; right -- and i --
		MOVFF POSTDEC1, 0x20
		MOVFF POSTDEC2, 0x20
	; second for loop 
	    for2:
		MOVFF POSTDEC2, WREG ;stores arr[i]  ; i--
		MOVFF POSTINC2, 0x02 ; i++
		CPFSLT 0x02 
		    GOTO if2
		GOTO endif2
		if2:
		    ; need to reverse
		;swap
		    MOVFF POSTDEC2, 0x00
		    MOVFF INDF2, 0x01
		    MOVFF 0x00, INDF2
		    MOVFF 0x01, PREINC2 ; i stays the same
		endif2:
		    ;continue for loop
		    ; the problem is right here 
		    COMF FSR0L, WREG 
		    INCF WREG
		    ADDWF FSR2L, W 
		    MOVFF POSTDEC2, 0x20 
		    CPFSLT 0xF0
			GOTO endfor2 ; goes here if the num is positive
		    GOTO for2
		endfor2:
		; left++  and i ++
		    MOVFF POSTINC0, 0x20
		    MOVFF POSTINC2, 0x20
	    ;check zero 
	    COMF FSR0L, WREG 
	    INCF WREG
	    ADDWF FSR1L, W 
	    CPFSLT 0xF0 ; checker 
		GOTO last
	    GOTO whileloop
;	put everything in order
	last:
	MOVFF 0x100, 0x110
	MOVFF 0x101, 0x111
	MOVFF 0x102, 0x112
	MOVFF 0x103, 0x113
	MOVFF 0x104, 0x114
	MOVFF 0x105, 0x115
end
Editor is loading...