Getting the High-Address Part in HLI

You can use the MSB syntax to get the high-address part of an object. Consider the following example.

Listing: Getting the High-Address Part of an Object
int i, *p_i;
void main(void) {

  /* p_i = &i */

  __asm {

          LDA @i

          STA p_i:1

          LDA @i:MSB

          STA p_i

}

The following examples illustrate the usage with the original code and the generated one.

Listing: Four Examples of HLI Usage and the Generated Assembly Code
char f(void);             char f(void);
char asm1(int a) {        char asm1(int a) {

  int b;                    int b;

  __asm {                   __asm {

    LDA   a:1               TSX

    STA   b:1               LDA 5,X  ; H:X is used

    JSR   f ! {}, {}        STA 1,X  ; to access all locals

    STA   a:0               JSR f

    LDA   b:1               STA 4,X

    RTS   ! {}, {A}         LDA 1,X

  }                         RTS

}                         }

                          }

char asm2(int a) {        char asm2(int a) {

  int b;                    int b;

  __asm {                   __asm {

    LDA   a:1               LDA 6,SP ; X is input register

    STA   b:1               STA 2,SP ; for f. SP must be used

    JSR   f ! {X}, {}       JSR f

    STA   a:0               TSX      ; f does not set X.

    LDA   b:1               STA 4,X  ; now X is free

    RTS   ! {}, {A}         LDA 1,X

  }                           RTS

}                           }

                          }

char asm3(int a) {        char asm3(int a) {

  int b;                    int b;

  __asm {                   __asm {

    LDA   a:1                 TSX

    STA   b:1                 LDA 5,X   ; H:X is used

    JSR   f ! {}, {X}         STA 1,X   ; to access locals

    STA   a:0                 JSR f     ; f destroys X

    LDA   b:1                 TSX       ; X is restored

    RTS   ! {}, {A}           STA 4,X   ; to access locals

  }                           LDA 1,X

}                             RTS

                            }

                          }

char asm4(int a) {        char asm4(int a) {

  int b;                    int b;

  __asm {                   __asm {

    LDA   a:1               LDA 6,SP

    STA   b:1               STA 2,SP

    JSR   f ! {}, {}        JSR f

    STA   a:0               STA 5,SP

    LDA   b:1               LDA 2,SP

    RTS   ! {X}, {A}        RTS ; X must not be used

                                ; in this function!

  }                        }

}                          }