Shop OBEX P1 Docs P2 Docs Learn Events
Propeller SPIN language question on FullDuplexSerial Object — Parallax Forums

Propeller SPIN language question on FullDuplexSerial Object

nasayunasayu Posts: 3
edited 2011-07-14 16:03 in Propeller 1
Hi everyone, I am a newbie with the propeller, just having done a few things with the Basic Stamp and learned that those were not powerful enough for what I want to do.
I am trying to understand what this part of the FullDuplexSerial object code does.
In the object, the variables declared at the begining are longs, and the memory addresses in the propeller are in 32 bit long as well. So, when I came across the following 2 lines, I got confused, hope someone can get me out of my mental jam here (I am stuck).
(in the DAT section for the assembly serial driver)
entry mov t1, par 'this line I get
add t1, #4 << 2 'skip pass heads and tails, this is the part I don't get,
'this line is supposed to skip pass the next 4 long variables and get
'to the rx_pin variable, so why the extra "<< 2"?
rdlong t2, t1

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-14 10:15
    The hub is addressed in bytes, so to skip past the four longs that hold the heads and tails pointers you need to add 16 to par (which holds the hub address of rx_head). After that line t1 will hold the hub address of rx_pin. The rdlong line that follows reads the pin number into t2.
  • nasayunasayu Posts: 3
    edited 2011-07-14 10:20
    OK, I made a rookie mistake here, the Main RAM in the Propeller is organized in bytes, not longs. The reason why I got confused is because of Figure 1-5 in the Propeller manual where it mentions that it has 8192 longs and listed the memory addresses from $0000 to $7FFF, well, $7FFF is 32767 (or rather 32768), which is 8192 times 4. I think the figure needs to say 32768 Bytes instead of 8192 longs.
  • nasayunasayu Posts: 3
    edited 2011-07-14 10:23
    Thanks! JonnyMac!
  • localrogerlocalroger Posts: 3,452
    edited 2011-07-14 16:03
    Hub RAM is specified in longs because that's what it is at the hardware level. This is the reason words and longs have to be aligned; when you do a PASM RDLONG it is directly performing a single 32-bit fetch. When you do a RDBYTE it does the same 32-bit fetch but shifts the right byte into position and masks it for you. For memory efficiency Spin is more byte than long oriented, though, and the byte code compiler and interpreter abstract this out for you so it looks more like 32K bytes.
Sign In or Register to comment.