Dear Philipp,

Apologies for bumping into this conversation (and thank you very much for
all the work!), but I think the assembler does what it should do.

Please consider the following:

                              116 ;     Assembler test (r10380): loading
0xhhmmll (high, mid, low) bytes into x and a.
                     332211   117       pattern = 0x332211

                              118 ;     Load mid and low.
008045 AE 22 11         [ 2]  119       ldw     x, #pattern

                              120 ;     Load low byte (xh is set to 0).
008048 AE 00 11         [ 2]  121       ldw     x, #<pattern

                              122 ;     Load mid byte (xl is set to 0).
00804B AE 00 22         [ 2]  123       ldw     x, #>pattern

                              124 ;     Load high and mid.
00804E AE 33 22         [ 2]  125       ldw     x, #(pattern>>8)

                              126 ;     Load high (xh is set to 0).
008051 AE 00 33         [ 2]  127       ldw     x, #(pattern>>16)

                              128 ;     Load low.
008054 A6 11            [ 1]  129       ld      a, #pattern

                              130 ;     Load mid (2 methods).
008056 A6 22            [ 1]  131       ld      a, #(pattern>>8)
008058 A6 22            [ 1]  132       ld      a, #>pattern

                              133 ;     Load high.
00805A A6 33            [ 1]  134       ld      a, #(pattern>>16)

The operators manipulate the symbol value, and not the memory contents. So
ldw x, #pattern loads the lower 16 bits of the symbol value (and not the
first two bytes of the symbol if it were to be placed in memory). Seems to
make sense to me?

 Eric


> -----Oorspronkelijk bericht-----
> Van: Philipp Klaus Krause [mailto:p...@spth.de]
> Verzonden: vrijdag 6 april 2018 11:01
> Aan: sdcc-user@lists.sourceforge.net
> Onderwerp: Re: [Sdcc-user] How to deal bytewise with 24-bit symbols in
> asxxxx?
> 
> 
> Am 02.04.2018 um 14:35 schrieb Maarten Brock:
> > 
> > In the generated code I see that the lower 16 bits are 
> loaded into x, not
> > the upper. And the most significant byte is loaded into a 
> by using #<sym,
> > but that seems to fail. If you instead use #(sym>>16) it 
> seems alright to
> > me.
> > 
> > Maarten
> 
> void f(void)
> {
>       void (*p)(void) = &f;
>       (*p)();
> }
> 
> compiles to:
> 
>       ld      a, #<_f
>       ldw     x, #_f
> ;     test.c: 4: (*p)();
>       push    #(00103$)
>       push    #(00103$ >> 8)
>       push    #(00103$ >> 16)
>       push    a
>       ld      a, xl
>       push    a
>       ld      a, xh
>       push    a
>       retf
> 00103$:
> ;     test.c: 5: }
>       retf
> 
> The lower 16 bits are loaded into x (but it should be the upper 16
> bits). The lower 8 bits get loaded into a correctly.
> 
> I guess I'll implement some workaround that makes the 
> register allocator
> not want to use x for the upper 16 bits in such an assignment (but I
> don't like having code geneation need workarounds for 
> assembler issues).
> 
> Philipp
> 
> --------------------------------------------------------------
> ----------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Sdcc-user mailing list
> Sdcc-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sdcc-user
> 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to