cancel
Showing results for 
Search instead for 
Did you mean: 

pointer problem (sdcc assembler)

remi2
Associate II
Posted on September 26, 2014 at 16:37

Hello

With the code below, i get returned an incremented caracter it self , the pointer is not,

is it normal ? meaning my code is wrong . i mean i get U not O ...

Or should I file a bug at sdcc comunity?

ldw X,&sharpstring_0

ldw _charptr, X

main_loop:

LDW X, &sharp0d50

CALL delay_m

CALL ledon

LDW X, &sharp0d50

CALL delay_m

CALL ledoff

ldw Y,[_charptr]                 ; <---- not returning what is at that address

ldw _lcdchar, Y

call _lcdwritechar

ldw Y, _charptr

incw Y

ldw _charptr, Y

JP main_loop

.area CODE

string_0:

        .ascii ''toto''

        .db 0x00

#stm8-sdcc-linux-sdasm-sdasstm8
12 REPLIES 12
zzdz2
Associate II
Posted on September 27, 2014 at 12:46

Yes when I assemble this I get some incorrect pointer.

I think the problem is caused by the ''.area CODE'', it all should be in

''.area HOME''

remi2
Associate II
Posted on September 27, 2014 at 13:02

Hi, thnx for the reply

What do you mean by all ?

I have put only 

....

.area HOME

string_0:

        .ascii ''toto''

        .db 0x00

.area INITIALIZER

.area CABS (ABS)

...

In .HOME and it did make changes , but still no luck

.....

--------------------------------------------------------

; Public variables in this module

;--------------------------------------------------------

.globl _main

;--------------------------------------------------------

; ram data

;--------------------------------------------------------

.area  DATA

_varOne:

.ds 1

_lcdchar:

.ds 1

_charptr:

.ds 1

...

;--------------------------------------------------------

; ram data

;--------------------------------------------------------

.area INITIALIZED

;--------------------------------------------------------

; Stack segment in internal ram 

;--------------------------------------------------------

.area SSEG

__start__stack:

.ds 1

....

zzdz2
Associate II
Posted on September 28, 2014 at 15:29

.area  DATA

 

_varOne:

 

.ds 1

 

_lcdchar:

 

.ds 1

 

_charptr:

 

.ds 1

 

This is not correct, _charptr should be ''.ds 2'' as pointer needs 2 bytes.

You use ldw to store the char which means you store two bytes in _lcdchar.

You need to use 2 byte _lcdchar variable (.ds 2) or use single byte write instruction.

remi2
Associate II
Posted on September 28, 2014 at 21:08

yes , true, I have fixed that

but still no luck, I am exchanging emails with Sdcc mailing list .

But if u have a little  example on how to use pointers / go thru an ascii string

in sdcc/asm would be so much help for me :)

perso. i have used pointers since the ninetees in C(gcc) and Asm(gpasm/mpasm)

but here, i am using a new arch. and new assembler , so all really I need

is a snipet to pickup the proper syntax in my case :)

regards

zzdz2
Associate II
Posted on September 29, 2014 at 10:49

I have looked at the opcode tables in PM044 and I think you found a bug in sdasstm8.

It loks like there is no ''ldw y,[longptr]'' instruction.

It gets assembled into 91 CE MS LS while 91 CE only takes one byte argument i.e. ''ldw y,[shortptr]''.

A workaround would be to use X reg instead.

remi2
Associate II
Posted on September 29, 2014 at 12:38

I my self get   72 CE MS LS ...

I am beeing asked by sdcc-user list to try to go thru C code and see the results from there

(sdcc delivering assebly to sdasstm8 ... ) I'll keep you informed on any news

zzdz2
Associate II
Posted on September 29, 2014 at 15:04

I my self get   72 CE MS LS ...

 

That would be X reg, but I wonder why you use 16-bit reg instead of A reg.

I am beeing asked by sdcc-user list to try to go thru C code and see the results from there

 

(sdcc delivering assebly to sdasstm8 ... ) I'll keep you informed on any news

 

Yes, it's the normal way of doing this. You write the code in C, compile to assembly and try to optimize the assembly code by hand, I mean brain.

remi2
Associate II
Posted on September 29, 2014 at 18:19

Well, i agree too, I have gone and used A reg. same problem ,

But, my problem is ...philosophical now , lol

I want to code in assembler in the first place -- hence, i dont need to optimise

any asm generated by anyother language (C, C++, Pascal or even Fortran lol ) .

i have already more than 200 lines of asm. code , all works fine, 

until i tryed some pointer stuff ... the whole meaning of real programming,

and bam ...

If someone , please, know how to code a pointer to a string in stm8 asm. please

do :)

regards -- i 'll keep you posted !

zzdz2
Associate II
Posted on September 29, 2014 at 18:42

But, my problem is ...philosophical now , lol

 

I want to code in assembler in the first place -- hence, i dont need to optimise

 

Well, some people think it's usless ;)

http://www.eevblog.com/forum/microcontrollers/anyone-else-think-assembly-is-%28mostly%29-useless/

If someone , please, know how to code a pointer to a string in stm8 asm. please

 

do :)

 

Does your print function work when you load lcdchar by hand?

ld a, #88

ld lcdchar, a

If you look at the compiled code, sdcc does it like this:

ldw x, _ptr1+0

ld a, (x)