; A Quick Introduction to PIC Assembler
; We assume the following declarations



; uncomment following two lines if using 16f627 or 16f628. config uses internal oscillator
	LIST	p=16F628		;tell assembler what chip we are using
	include "P16F628.inc"		;include the defaults for the chip
	__config 0x3D18			;sets the configuration settings (oscillator type etc.)

; Filename : Sample.asm

; DECLARE VARIABLES!!!!!!
; We are telling the assembler we want to start allocating symbolic variables starting
;    at machine location 0x20. Please refer to technical documents to see if this is OK!!

cblock 	0x20 			;start of general purpose registers
		count1 			;  count1 is symbolic name for location 0x20
		counta 			;  counta is symbolic name for location 0x21
		countb 			;  countb is symbolic name for location 0x22
	endc


; Change the contents of a register

	CLRF	count1		; set count1 to zeroes
	CLRW				; set the w register to zeroes
	
	COMF	count1,f	; complement the bits in count1 put result in count1  (f is defined as 1)
	COMF	count1,w	; complement the bits in count1 put results in w      ( w is defined as 0)
	
	DECF	count1,f	; subtract 1 from count1, put results in count1
	INCF	count1,f	; figure this out yourself
	
	BCF		count1,3	; sets bit 3 of count1 to zero
	BSF		count1,4	; sets bit 4 of count1 to one
	
	RLF		count1,f	; rotate left thru the carry flag
	RRF		count1,f	; rotate right thru the carry flag
	
	SWAPF	count1,f	; swap nibbles!!
	
; move data!!!!

	MOVLW	0xff		; set w register to all ones
	MOVF	count1,f	; move to count1 !! Why ?? Set flags
	MOVF	count1,w	; move count1 to w
	MOVWF	count1		; move w to count1
	
; program control

	GOTO here			; transfer execution to lable here
	CALL here			;call subroutine here
	RETURN				; return from subroutine
	RETLW	0xff		; return from subroutine. Load w with 0xff
	RETFIE				; return from interrupt
	BTFSC	count1,3	; test bit 3 in count1, skip next instruction if zero
	BTFSS	count1,4	; test bit 4 in count1, skip if set
	DECFSZ	count1		;decrement count1, skip next instruction if zero
	INCFSZ	count1		;increment count1, skip next instruction if zero
	
; do the doo-wa-diddy
	NOP
	
; Logic
	ANDLW	0x8f		;logical and of 0x8f and w register. results placed in w
	ANDWF	count1,f	;logical and of W and count1. result placed in count1
	IORLW	0x8f		;inclusive or
	IORWF	count1,f
	XORLW	0x8f
	XORWF	count1,f
	
; arithmetic
	ADDWF	count1,f	; add w and count1. result in count1
	ADDLW	0x1e		; add 0x1e to w. result in w
	SUBLW	0x1e		; WEIRD. SUBTRACT w from literal, result placed in w
	SUBWF	count1,f	; count1-W . results in count1
	
; some more instrutions later  (clrwdt , option , sleep , tris )





	end