Re: [cc65] segment address arithmetic

From: David A. Lyons <dlyons1lyons42.com>
Date: 2008-09-21 08:33:06
The compiler is adding twice as much as you expect, because it's  
advancing by 1024 pointer-sized objects, and a pointer is 2 bytes --  
sizeof(char*) == 2.

If "char *" is the proper type for _DATA_LOAD__, then its value is  
already a pointer to your segment, and you can write _DATA_LOAD__+1024  
(no '&'), and it will add 1024, not 2048).

If instead _DATA_LOAD__ is located at the beginning of the segment,  
then declare it as "char _DATA_LOAD__" (no '*'), and then &_DATA_LOAD__ 
+1024 will add 1024 -- sizeof(char) == 1.

Cheers,

--Dave

On Sep 20, 2008, at 5:45 PM, Shawn Jefferson wrote:

> I’m trying to take the address of one of my segments (or memory  
> areas) and add 1024 to that address.  When I do that using the  
> following code:
>
> extern char *_DATA_LOAD__;
>
> void main(void) {
>   cprintf("%X", &_DATA_LOAD__+1024);
>
>   return;
> }
>
> The compiler produces:
>
> 000003r 1               .segment     "CODE"
> 000000r 1
> 000000r 1               .proc            _main: near
> 000000r 1
> 000000r 1               .segment     "CODE"
> 000000r 1
> 000000r 1               ;
> 000000r 1               ; cprintf("%X", &_DATA_LOAD__+1024);
> 000000r 1               ;
> 000000r 1  A9 rr             lda     #<(L0001)
> 000002r 1  A2 rr             ldx     #>(L0001)
> 000004r 1  20 rr rr          jsr     pushax
> 000007r 1  A9 rr             lda     #<(__DATA_LOAD__+2048)
> 000009r 1  A2 rr             ldx     #>(__DATA_LOAD__+2048)
> 00000Br 1  20 rr rr          jsr     pushax
> 00000Er 1  A0 04           ldy     #$04
> 000010r 1  4C rr rr          jmp     _cprintf
> 000013r 1
> 000013r 1               .endproc
> 000013r 1
> 000013r 1
>
> What am I doing wrong here?
>
> Thanks,
> Shawn


----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Sep 21 08:33:21 2008

This archive was generated by hypermail 2.1.8 : 2008-09-21 08:33:23 CEST