Shop OBEX P1 Docs P2 Docs Learn Events
Question about constants — Parallax Forums

Question about constants

GC4130GC4130 Posts: 13
edited 2007-11-30 13:24 in General Discussion
I have a program in which I have defined constants which are larger than 8 bits such as


A con 4000



I am wondering how I can access the LSB and MSB of these constants using the following convention doesn't seem to work

X=A_LSB



Any help is much appreciated

thanks

GC

Comments

  • ZootZoot Posts: 2,227
    edited 2007-11-30 08:17
    SX/B:
    X = A >> 8 ' use high byte, consumes code space (A>>8 will be computed runtime, not compile time)
    X = A ' low byte (high byte thrown away) or more clearly:
    X = A & $00FF ' consumes code space

    Alternatively, you could define the derived constants...

    A CON $F0F0
    A_LSB CON A & $00FF
    A_HSB CON A >> 8 ' no code space

    In ASM you can use constructions like this that do not consume code...

    ASM
    MOV X, #A & $FF ' low byte
    MOV X, #A >> 8 ' high byte -- literal manipulations do not consume code space
    ENDASM

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • GC4130GC4130 Posts: 13
    edited 2007-11-30 13:24
    zoot,

    that worked perfectly thank you

    GC
Sign In or Register to comment.