Skip to main content
remi2
Associate II
September 26, 2014
Question

pointer problem (sdcc assembler)

  • September 26, 2014
  • 12 replies
  • 4164 views
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
    This topic has been closed for replies.

    12 replies

    zzdz2
    Associate
    September 30, 2014
    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
    remi2Author
    Associate II
    September 30, 2014
    Posted on September 30, 2014 at 11:11

    thank you ! it works :)

    regards