cancel
Showing results for 
Search instead for 
Did you mean: 

2 dimensional pointer

marco32
Associate II
Posted on October 28, 2004 at 10:01

2 dimensional pointer

4 REPLIES 4
marco32
Associate II
Posted on October 27, 2004 at 04:55

I have a tabel with text strings.

Like:

Name, ETX

Version, ETX

etc.

Now i want to read each text seperate.

So 1 pointer for the text string and 1 pointer for each letter of th string.

HOW?

Assembler can only handle one pointer!

ld a(text,x)

Write A to sci, till ETX

I,ve tried to made text a pointer, but it doesn't work.

Problem with byte-word value.

Anybody made a 2 dimensional pointer?

Or have somebody a better idea?
fggnrc
Associate II
Posted on October 27, 2004 at 13:39

Moppie,

if you use assembler, take a look to the indirect addressing...

If you want 2 dimensional data access, you have to define a pointers' table (the address of the first character of a string) and use the X register to displace from the first character.

To access the 2nd char of the 3rd string you can write the following:

; put this declaration in the ram segment

ptr DS.w

; this declaration in in the rom segment

text DS.w

; addresses of the first character of each string

; select the 3rd string

LD X,#3

SLL X

LD A,(text,X)

LD ptr,A

LD A,({text+1},X)

LD {ptr+1},A

; select the 2nd character

LD X,#2

LD A,([ptr.w],X)

; Do whatever you want ...

I hope I was clear...

EtaPhi
marco32
Associate II
Posted on October 28, 2004 at 05:08

Thanks for you're reply.

I've copied you're code and it works fine, thanks.

But, i changed the DS.W to DC.W in the ROM segment.

I get errors from the compiler

Fatal 999: Cannot mix Storage and Static definitions in same segment! 'S->D'

In the ROM segment i only use DC.B/W. What is the big difference between these?
fggnrc
Associate II
Posted on October 28, 2004 at 10:01

I am sorry for the mistake, Moppie...

When I sketched the data structure I did not care too much to the DS (define storage, i.e. bytes readable and writeable) and DC (define constant) directives...

This explains the assembler error: the rom can not contain variables!

BTW, my example is useful when there are static strings whose lenght is not the same. These data object are typically expressed in C as:

#define MAX_STRINGS 10

const char *text[MAX_STRINGS];

If you want to reduce the clock cycles (at the price of some memory waste), you can use the following C data structure:

#define MAX_STRINGS 10

#define MAX_STR_LEN 8

const char text[MAX_STRINGS][MAX_STR_LEN];

The big difference is that in the latter you can use an expression to compute the position of the character to read.

Let's say you want read text[3][2], as in my first example.

here is what I'd write:

LD X,#3

LD A,#MAX_STR_LEN

MUL X,A

ADD A,#2

LD X,A

LD A,(text,X)

Pls, note that some cycles can be saved if MUL X,A can be replaced by a logical shift to left (i.e. MAX_STR_LEN is a power of 2).

Regards,

EtaPhi