2014-09-26 07:37 AM
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, Xmain_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-sdasstm82014-09-27 03:46 AM
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''2014-09-27 04:02 AM
Hi, thnx for the reply
What do you mean by all ?I have put only .... .area HOMEstring_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....2014-09-28 06:29 AM
.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.
2014-09-28 12:08 PM
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 stringin 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 needis a snipet to pickup the proper syntax in my case :)regards2014-09-29 01:49 AM
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.2014-09-29 03:38 AM
2014-09-29 06:04 AM
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.
2014-09-29 09:19 AM
Well, i agree too, I have gone and used A reg. same problem ,
But, my problem is ...philosophical now , lolI want to code in assembler in the first place -- hence, i dont need to optimiseany 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. pleasedo :)regards -- i 'll keep you posted !2014-09-29 09:42 AM
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. pleasedo :)
Does your print function work when you load lcdchar by hand? ld a, #88 ld lcdchar, aIf you look at the compiled code, sdcc does it like this: ldw x, _ptr1+0 ld a, (x)