Sign in

username:

password:



Not a member?

Search c6x



Search tips

Subscribe to c6x



c6x by Keywords

AD535 | BIOS | Booting | Bootloader | C621 | C6211 | C6415 | C671 | C6711 | C6711DSK | C6713 | CCS | Chassaing | COFF | DAT | DM64 | DM642 | DMA | DSK671 | DSK6711 | EDM | EDMA | EMIF | Emulator | EVM | EVM620 | FFT | FIR | GPIO | Halting | HPI | HWI | IDK | JTAG | LDB | LDH | LDW | Linker | LMS | LOG_printf | Matlab | McBSP | MEM_alloc | MIPS | PCI | PCM3003 | Pipeline | Profiling | QDM | Reset | ROM | RTDX | Sampling | SDRAM | Stack | TEB | THS1206 | TMS320C621 | TMS320C6416 | TMS320C6711 | TMS320C6713 | UART | Vector Table | XBUS | XDS560

Sponsor

Industry's highest performing at the lowest power DSPs now as low as $5.00*
Start development today!
*volume pricing for 10ku

Discussion Groups

See Also

Embedded SystemsFPGAElectronics

Discussion Groups | TMS320C6x | accessing 2-d array element in linear assembly

Technical discussions about the TI C6000 DSPs (including the c62x, c64x and c67x DSPs).

  

Post a new Thread

accessing 2-d array element in linear assembly - Chong Chuan Foong - Nov 7 2:09:00 2001

Hi all, I have a C function which needs to be re-written in Linear Assembly.

My problem goes as follows:
1. How do I access a 2-dimensional array in linear assembly? For example,
if i have an 2-d array : array_table1[2][3].
how do I access array element array_table[1][1]?

I am currently using Code Composer Studio V2.0.

TIA.

regards,
chuan foong, chong



______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: accessing 2-d array element in linear assembly - Andrew Elder - Nov 7 16:11:00 2001


Chong,

The first step should always be to re-write in optimized C.
Have you tried that yet ?

What is it that the C compiler fails to optimize ?

You can easily get the C compiler to use LDDWs, so in general you can get
very close to linear assembler performance just by re-writing the C code.

Andrew E

At 10:09 AM 11/7/01 +0800, Chong Chuan Foong wrote:
>Hi all, > I have a C function which needs to be re-written in Linear Assembly.
>
> My problem goes as follows:
> 1. How do I access a 2-dimensional array in linear assembly? For example,
>if i have an 2-d array : array_table1[2][3].
> how do I access array element array_table[1][1]?
>
> I am currently using Code Composer Studio V2.0.
>
> TIA.
>
>regards,
>chuan foong, chong >
>_____________________________________






(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: accessing 2-d array element in linear assembly - Andrew V. Nesterov - Nov 8 16:28:00 2001


> Date: Wed, 7 Nov 2001 10:09:56 +0800
> From: "Chong Chuan Foong" <>
> Subject: accessing 2-d array element in linear assembly
>
> I have a C function which needs to be re-written in Linear Assembly.
>
> My problem goes as follows:
> 1. How do I access a 2-dimensional array in linear assembly? For example,
> if i have an 2-d array : array_table1[2][3].
> how do I access array element array_table[1][1]? Generally there are two ways, absolutely similar in either C, linear
assembly or assembly, to access an entry in multidimensional array.

Both way depend on how an array has been defined:

float table1[2][3]; // defines a single pointer
// or
float *(table2[2]); // defines an array of two poiters to float or
float **table3; // equivalently, defines a pointer to a pointer to a
// a float

in the first case table1[1][1] is *(table1+3*1+1)
or generally table1[i][k] is *(table1+num_of_cols*i+k)

in the second case table2[1][1] is *(*(table2+1)+1)
table3[1][1] is *(*(table3+1)+1)
or generally table2[i][k] is *(*(table2+i)+k), so as table3[i][k]

In linear assembly this would be coded as (far data model):

CASE1: MVKL _table1, ptr_table1
MVKH _table1, prt_table1 ; points to table1[0][0]
ADDAW ptr_table1, 4, ptr_table1 ; points to table1[1][1]
LDW *ptr_table1, table1_11 ; load table1[1][1]

CASE2: MVKL _table2, ptr_table2
MVKH _table2, ptr_table2 ; points to *table2[0]
ADDAW ptr_table2, 1, ptr_table2 ; points to *table2[1]
LDW *ptr_table2, ptr_table2 ; points to table2[1][0]
LDW *+ptr_table2[1], table2_11 ; load table2[1][1]

In assembly code one have to take care about the corresponding
delay slots and assign execution units.

As it seen, the only difference is whether there has been defined
a pointer to or an array of pointers to pointers to an integrals
or structures. Well, in the case of multidimentional array of
structures there must be pointer modification to access an element
in the structure.

Have fun,

Andrew


______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )