Shop OBEX P1 Docs P2 Docs Learn Events
Spin questions — Parallax Forums

Spin questions

John AbshierJohn Abshier Posts: 1,116
edited 2006-07-06 15:07 in Propeller 1
I don't understand part of sign-extend.· Given the following code fragement:

CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
var
· word·· x, z
· long·· y
PUB Start
· x := -300
· y := ~~x + 50
I understand the part of sign extending to make y equal -250.· I don't understand the sing-extend being an assignment operator.· x is declared a 16 bit variable.· Where is the 32 bit sign-extended result stored? Is x a long after execution of the last line?

What does "Param|RValue|LocalValue must be globally unique, but other methods may also use the same symbol name." mean?· Does it mean that the symbol cannot be the same as a global variable, but the names can be reused from method to method?

Comments

  • SSteveSSteve Posts: 808
    edited 2006-07-05 23:54
    John Abshier said...
    I don't understand part of sign-extend. Given the following code fragement:


    CON

    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000

    var
    word x, z
    long y

    PUB Start

    x := -300
    y := ~~x + 50


    I understand the part of sign extending to make y equal -250. I don't understand the sing-extend being an assignment operator. x is declared a 16 bit variable. Where is the 32 bit sign-extended result stored? Is x a long after execution of the last line?

    Edit: Wrong, wrong wrong! (see Chip's post)redface.gif Only when the ~~ operator is used on a line by itself is it an assignment operator. So in your example, the value of x isn't changed. The 32-bit sign-extended result is stored in a temporary location during the evaluation of the expression.

    I'm not sure what the answer is to the second half of your message. It does sound self-contradictory. But that's something the compiler should catch for you, so you can probably figure it out by experimenting a little.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store

    Post Edited (SSteve) : 7/6/2006 3:04:00 PM GMT
  • cgraceycgracey Posts: 14,206
    edited 2006-07-06 06:42
    The sign-extend operators (~variable and ~~variable) are variable modifiers, just like ++variable·and variable--. They work on variables only and they always write back. The ~variable extends bit 7 while the ~~variable extends bit 15.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • SSteveSSteve Posts: 808
    edited 2006-07-06 14:58
    But if x is a Word, ~~ can't do anything to its value, right? (Other than making a 32-bit intermediate value for the expression.)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store

    Post Edited (SSteve) : 7/6/2006 3:05:33 PM GMT
  • SSteveSSteve Posts: 808
    edited 2006-07-06 15:07
    Sorry about the bad info a couple posts ago. I was thinking of the bitwise not operator, "!". It is the one that's an assignment operator when used on a line by itself.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
Sign In or Register to comment.