Shop OBEX P1 Docs P2 Docs Learn Events
A lil help glueing to bytes to make a word — Parallax Forums

A lil help glueing to bytes to make a word

grasshoppergrasshopper Posts: 438
edited 2008-11-13 16:34 in Propeller 1
I am trying to "glue" to bytes to make a word. Here is some pseudo code.


Var
  Word Glued
  Byte X, Y

Main
  X = $20
  Y = $4B

  Glued = X << 4 
  Glued = Y




This is not working as I would expect. I wanted Glued to = $204B. Perhaps some of you seasoned programmers could guide me in the right direction.

Comments

  • pgbpsupgbpsu Posts: 460
    edited 2008-11-13 15:24
    @grasshopper-

    Your last assignment statement "Glued = Y" blows away what you've already assigned to Glued. I think you need to do something like this:

    x:=$20
    y:=$4B
    
    Glued := X << 4              ' put X in upper byte of glued
    Glued := Glued | y           ' put y in lower byte of glued
    
    
    



    I think you could also use the long/word/byte addressing in spin to do the same thing like this:
      Glued.byte[noparse][[/noparse]0]:=y          ' set lowest 8 bits of Glued to what's in Y
      Glued.byte:=x          ' set upper 8 bits of Glued to what's in X
    
    



    For some reason the one of the lines above gets munched when I post mad.gif. Here's my second suggestion again but not as code:
    Glued.byte[noparse][[/noparse]0]:=y
    Glued.byte [noparse][[/noparse] 1 ] :=x

    This is explained pretty well in the manual pg 168.

    pgb

    Post Edited (pgbpsu) : 11/13/2008 3:31:05 PM GMT
  • John AbshierJohn Abshier Posts: 1,116
    edited 2008-11-13 15:34
    Glued := x << 4 | y works

    John Abshier
  • T ChapT Chap Posts: 4,223
    edited 2008-11-13 15:39
    If you want to put a byte into the upper 8 bytes of a word you should bitshift left 8, not 4, then OR the lower byte.
  • grasshoppergrasshopper Posts: 438
    edited 2008-11-13 15:41
    Thanks got it to work.
  • Beau SchwabeBeau Schwabe Posts: 6,562
    edited 2008-11-13 16:34
    grasshopper,

    You could save a couple of variables and code space doing something like this...

    Var
      Word Glued
    Main
      Glued.BYTE[noparse][[/noparse]1] := $20  'X     'HIGH BYTE  
      Glued.BYTE[noparse][[/noparse]0] := $4B  'Y     'LOW BYTE
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
Sign In or Register to comment.