Menu

#206 How can I get the upper bytes of a 32-bit z80 address?

open
nobody
None
5
2025-08-21
2025-07-06
No

The .rel files generated by SDCC use 32-bit addresses for z80 (and related), 24 bits for stm8.

For stm8, #(_i >> 16) gives me the topmost byte of the 24-bit address. But for z80 I apparently get the least-significant byte of the address that way, i.e. as if the >> 16 wasn't even there. It looks to me like that when comparing the stm8 and z80 .rel files, though my understnading of hte asxxxx .rel format is limited; and I definitely see it in the final .ihx after linking.

Discussion

  • Janko Stamenović

    I don't know what's going on with Z80 "long" addresses. I've tried this code to get some idea:

    long __at 0x12345678 hello;
    unsigned f( void ) {
        return ( (unsigned long)&hello ) >> 16;
    }
    

    and I see the following generated for -mz80:

        .area _DATA
    _hello  =   0x12345678
    ...
    ;hello.c:3: return ( (unsigned long)&hello ) >> 16;
        ld  de, #_hello + 2
    

    which gives in the .lst:

                                         50 ;hello.c:3: return ( (unsigned long)&hello ) >> 16;
        00000000 11 7A 56         [10]   51     ld  de, #_hello + 2
    

    567A value hex, which is 5678 + 2.

    We should be careful when we change the behavior, however. AFAIK there is various existing SDCC code already somehow using banks on z80 platforms.

     
    • Philipp Klaus Krause

      I'll try to check on sdcc-user if anyone relies on the current behaviour. But I also found a bug report about it: [bugs:#2930].

       

      Related

      Bugs: #2930

      • Philipp Klaus Krause

        From the one reaction on sdcc-user, apparently no one relies on current >> 24 behavior. So I'd suggest to make it behave for ez80/rabbit/tlcs90 as it does for stm8; if we do it for all z80-related, that would fix [bugs:#2930].

         

        Related

        Bugs: #2930


Log in to post a comment.