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
remi2
Associate II
Posted on September 29, 2014 at 20:22

🙂

my function works this way

; try write H

CHKBZF

mov PD_ODR, #0b01000011

STRBLCD

CHKBZF

mov PD_ODR, #0b10000011

STRBLCD

;try write X

mov _lcdchar, #'X' ;                             <----- loads an immediate '' capital x ''

call _lcdwritechar  ;                             <----- works: i get X on the lcd

mov _varOne, #'a'

ld a,#_string_0

ld _charptr, a

so my fonction works with immediate values

thats why i try to pop up literals from a string.

Regards

zzdz2
Associate II
Posted on September 30, 2014 at 10:50

I think something like this would work:

.area  DATA

_lcdchar:

.ds 1

_charptr:

.ds 2

.area HOME

ldw x,#string_0 ; init pointer

ldw _charptr, x

main_loop:

        ldw x, _charptr ; load pointer

        ld a, (x) ; load char

tnz a ; test if zero

jreq 1$

ld _lcdchar, a

call _lcdwritechar

ldw x, _charptr ; increment pointer

incw x

ldw _charptr, x

jra main_loop

1$:

ret

string_0:

        .ascii ''toto\0''

remi2
Associate II
Posted on September 30, 2014 at 11:11

thank you ! it works 🙂

regards