cant compile simple function for z80, int declaration? help please

Help
Tony
2014-01-19
2014-01-21
  • Tony
    Tony
    2014-01-19

    Hi All,

    im having trouble trying to get a simple program to compile (just to test out sdcc) for a Z80 and output in intel hex format, i keep getting error: "?ASLink-Warning-Undefined Global 'addr' referenced by model 't1'" note t1.c is the name of my source, i cant figure out if the error is in line: "unsigned int addr;" or in line: "ld bc,(addr)"

    any help would be much appreciated.

    unsigned int addr;
    
    void io_write() {
        __asm
        push af
        push bc
        ld bc,(addr)
        out (c),a
        pop bc
        pop af
        __endasm;
    }
    int main(){
    }
    
     
    Last edit: Maarten Brock 2014-01-20
  • C variables are prefixed by an underscore in asm, So you would use ld bc, (_addr).
    
    Philipp
    
     
  • Maarten Brock
    Maarten Brock
    2014-01-20

    Tony, I took the liberty to indent your code with 4 spaces so it is displayed correctly.

     
  • Tony
    Tony
    2014-01-20

    Thanks Philipp! i could not find reference to this anywhere.. or maby im going blind!?

    Thanks Maarten.. i did notice it didnt display properly, i will remember this for next time.

    another question: i have declared addr as an unsigned int, this will compile to 16 or 32 bit length and then in sdcc under z80 asm will cut off the high bytes (if 32) to be left with the lower 16 for the ld bc (_addr)? or would it be better to declare addr as an int of 16 bit length (if possible)? if so, which directive do i use for this? im just a little confused how sdcc will work out the conversion from a 32 bit int to the 16 bit length needed for the asm load instruction?

    thanks guys!

     
    Last edit: Tony 2014-01-20
  • Maarten Brock
    Maarten Brock
    2014-01-21

    In C an int has unspecified bit width. It must be at least 16 bits wide and is recommended to reflect the native width of the underlying system. Since SDCC targets small devices it always uses 16 bits.

    If you want to specify the width, use

    #include <stdint.h>
    int8_t a;
    uint16_t b;
    int32_t c;
    

    Maarten

     
    Last edit: Maarten Brock 2014-01-21