Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC Assembly: How to declare an Array?

Status
Not open for further replies.

neoaspilet11

Full Member level 5
Joined
Sep 29, 2005
Messages
277
Helped
29
Reputation
56
Reaction score
8
Trophy points
1,298
Location
Cebu, Philippines
Activity points
4,048
pic assembly array

Guys,

I have a problem in PIC assembly.

1.) Suppose I have variables like ARG00 ARG01, ARG02, ARG03, ...ARGN, how can I declare them as an array elements say ARG(0 to N)?

2.) How to access the nth element of the array say for example ARG(4)?

By the way it should not use indirect addressing mode via INDF and FSR registers.
Is array declaration possible withour using indirect addressing modes?

Thanks for any ideas.
 

jonw0224

Full Member level 4
Joined
Nov 22, 2004
Messages
211
Helped
45
Reputation
90
Reaction score
14
Trophy points
1,298
Location
USA
Activity points
2,528
pic asm array

1.) Suppose I have variables like ARG00 ARG01, ARG02, ARG03, ...ARGN, how can I declare them as an array elements say ARG(0 to N)?

You can declare and address of ARGARRAY that points to beginning of a bunch of register variables that make up your array, this way:

Code:
CBLOCK
         ARGARRAY : 0
         ARG00, ARG01, ARG02, ARG03, ARG04
ENDC

ARGARRAY has the same address as ARG00

2.) How to access the nth element of the array say for example ARG(4)?

Address the register ARG04 OR use indirect addressing this way:

Code:
movlw ARGARRAY + D'4'
movwf FSR         ;Now INDF returns ARG04

Is array declaration possible withour using indirect addressing modes?

It depends on what you are doing. Declaring an "array" as I suggest allows you to treat it like an array using conditional compiling without using indirect addressing. For example you can write

Code:
local i
i = 0
while i < 5
movf ARGARRAY + i, w   ;move ARG(i) to WREG
i++
endw

When you assemble this will generate the commands

Code:
movf ARGARRAY + 0, w  ;ARG00
movf ARGARRAY + 1, w ;ARG01
movf ARGARRAY + 2, w ;ARG02
movf ARGARRAY + 3, w ;ARG03
movf ARGARRAY + 4, w ;ARG04

Hope that answers your question. I'm sure it's not exactly what you want to hear, but that's the best I know how to do these things in PIC assembly.
 

neoaspilet11

Full Member level 5
Joined
Sep 29, 2005
Messages
277
Helped
29
Reputation
56
Reaction score
8
Trophy points
1,298
Location
Cebu, Philippines
Activity points
4,048
pic assembly arrays

Hello Jonw0224,

Thanks,

But I think I will be forced to use INDF and FSR registers because the array is too huge. at least 120 elements and at most 240 elements which occupy several banks of RAM registers. Its pretty tedious because of switching banks in the coding. However I made a code last night to cater 240 elements and it works perfectly fine.

Thanks you and happy new year
 

jonw0224

Full Member level 4
Joined
Nov 22, 2004
Messages
211
Helped
45
Reputation
90
Reaction score
14
Trophy points
1,298
Location
USA
Activity points
2,528
assembly declare array

neoaspilet11

I agree, generally it is easiest to use FSR and INDF registers for handling arrays. I'll admit, this is tricky with several banks and you definitely don't want to use the conditional compile loop I suggested.

Good luck and happy new year to you too

-jonathan
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top