Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Assembler programing and arrays

Status
Not open for further replies.

gatoruss

New Member
Noobie question here - Is it possible to use arrays in assembler language with baseline +/or midrange pics? If so, can someone provide a link(s) that might explain how that would be done...I have tried searching (Google) and do not seem to come up with anything specific to pics?
 
Depends what you mean by 'arrays', you can make lookup tables in program memory (ROM), or small sequences of GPR's in RAM - limitation is really the very small amount of RAM available.
 
A single byte or an array makes no difference. Bytes become an array only in your mind and only when you use indirect addressing or computed offsets.

The technique is to declare the base of the array at a distance from other variables or declare the base of the array as consuming contiguous locations in RAM using CBLOCK or EQU

Code:
	CBLOCK 0X20
	LED0, LED1, LED2, LED3, LED4, LED5, LED6, LED7
	LIVEBUFF:16
	END


	;--ACCUMULATE LIVE BUFFER ARRAY
	LOADF	LIVE_CNT, .8
	LOADF	FSR, LIVEBUFF		;POINT TO LIVEBUFF[0].

LOOP1	BTFSS	PIR1, RCIF		;WAIT UNTIL RS232 BYTE RECEIVED.
	GOTO	$ - 1
	MOVF_F	RCREG, INDF		;NOW STORE RS232 BYTE INTO LIVEBUFF[X]
	INCF	FSR, F			;POINT TO LIVEBUFF[X+1].
	DECFSZ	LIVE_CNT, F		;EXIT LOOP WHEN AT LIVEBUFF[7].
	GOTO	LOOP1


	;--COPY LIVE BUFFER TO LED[0-7]
	MOVF_F	LIVEBUFF+0, LED0
	MOVF_F	LIVEBUFF+1, LED1
	MOVF_F	LIVEBUFF+2, LED2
	MOVF_F	LIVEBUFF+3, LED3
	MOVF_F	LIVEBUFF+4, LED4
	MOVF_F	LIVEBUFF+5, LED5
	MOVF_F	LIVEBUFF+6, LED6
	MOVF_F	LIVEBUFF+7, LED7
 
This is how I would access an array in RAM.
Code:
		cblock	0xa0	;use area in bank 1
Array:20
		endc

;the 9th bit of the indirect register has to be cleared 
;to access 00-0xff
		bcf	STATUS,IRP

;store 0x23 in Array[6]
		movlw	.6	;array element
		addlw	Array	;add start of array
		movwf	FSR	;move to indirect register
		movlw	0x23	;value to store
		movwf	INDF	;store in location pointed to by FSR

;get contents of Array[9]
		movlw	.9	;array element
		addlw	Array	;add start of array
		movwf	FSR	;move to indirect register
		movfw	INDF	;read contents of location pointed to be FSR
;W=Array[9]

Mike.
 
thanks to all for the replies. These got me started...refining my Google search, I have found a lot of info!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top