Shop OBEX P1 Docs P2 Docs Learn Events
Reading a Variable in Assembly — Parallax Forums

Reading a Variable in Assembly

JomsJoms Posts: 279
edited 2009-10-01 17:31 in Propeller 1
I am not very good at Assembly and have been trying to figure out the command to read a variable in assembly. Basically what I am trying to do is run Terry Hitt's original video overlay 4 times, each in its own cog. I am attempting to save the object only once, but when I call upon it each time, specifiy the pin numbers used for the video.

This is how the current version works:
DAT
              ORG
OverlayAsm    MOV _screenAddr,par      ' Get address of screen memory
              MOV _syncPinMask,#1      ' Sync is on pin P0
              MOV _videoPinMask,#2     ' Output is on pin P1
              MOV _genPinMask,#4       ' Output is on pin P2




This is what I am attempting to do, but every method I try, it does not like. I assume I just have a formatter wrong.
DAT
              ORG
OverlayAsm    MOV _screenAddr,par      ' Get address of screen memory
              MOV _syncPinMask,pin1      ' Sync is on pin P0
              MOV _videoPinMask,pin2     ' Output is on pin P1
              MOV _genPinMask,pin3       ' Output is on pin P2




The pin1,pin2,pin3 are variables I declared earlier in the program up in the spin. Is this possible to do? What am I doing wrong?

Thanks in advance...

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-01 04:16
    It's not possible to do it the way you've written. The Spin variables can only be accessed using RDLONG / RDWORD / RDBYTE. If _syncPinMask, _videoPinMask, and _genPinMask are defined as LONGs, you can initialize them from Spin just before executing the COGNEW that starts up the cog you're using. The mask values will be copied to the cog's memory along with the code you've written.

    OverlayAsm  MOV  _screenAddr,par   'Get address of screen memory
    .....
    _syncPinMask  LONG   0
    _videoPinMask LONG   0
    _genPinMask   LONG   0
    ...
    PUB startUpCog
       _syncPinMask := pin1
       _videoPinMask := pin2
       _genPinMask := pin3
       COGNEW(@OverlayAsm,@screenMemory)
    
  • JomsJoms Posts: 279
    edited 2009-10-01 04:28
    Thanks Mike.

    I think I understand that too. Thanks for the explanation so that I know what is going on for next time.

    I am going to give this a try...
  • JomsJoms Posts: 279
    edited 2009-10-01 07:04
    ok, that appears to work. However it brought me to a side note question. When in assembly, do you have to count by 1,2,4,8,16,32,64,etc. as you go up on the pins?

    I have made one channel work by switching the pins to numbers 1,2,8 (P0,P1,P3), to access pins P3,P4,P5, would I just use numbers 8,16,32? Or am I missing something here?
  • AleAle Posts: 2,363
    edited 2009-10-01 07:29
    Well yes and no.

    the pins can be accessed in three registers OUTA, INA and PINA. Each bit from 0 to 31 corresponds to one pin. When writing a constant to access one of the pins you can use several notations, binary, hexadecimal or an algebraic expression:

    For the 10th PIN it means bit 9 (it starts counting at 0) :

    Decimal : 512
    Binary %00000000_00000000_00000010_00000000
    Hex : $00_00_02_00
    Algebraic (it means 1 shifted left to the 10th place or 2^9) : 1<<9

    But that is true for every constant.
    The powers of 2 are: 1, 2, 4, 8, 16, 32,64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288 and so on smile.gif, so 8 corresponds to P4 (2^4)

    Edit: Always the same the 10th pin is bit 9. What was I thinking again ? sorry

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit some of my articles at Propeller Wiki:
    MATH on the propeller propeller.wikispaces.com/MATH
    pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL020
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU

    Post Edited (Ale) : 10/1/2009 5:05:51 PM GMT
  • nohabnohab Posts: 96
    edited 2009-10-01 09:40
    Ale, I'm a little bit confused, why do you write that "for pin 10, means bit 9" ?
    Both the pins and the bits start counting at 0 (the first pin is not P1, it is P0) so P10 means bit 10.
    With a calculator you can see that 1024 is not $200, it's··$400

    This gives:

    P0 - bit 0
    Decimal: 1
    Binary: %00000000_00000000_00000000_00000001
    Hex: $00_00_00_01
    Algebraic : 1 (no shift at all)
    Bitwise decode: |< 0

    P1 - bit 1
    Decimal: 2
    Binary: %00000000_00000000_00000000_00000010
    Hex: $00_00_00_02
    Algebraic : 1 << 1 (shift one to the left)
    Bitwise decode: |< 1

    P2 - bit 2
    Decimal: 4
    Binary: %00000000_00000000_00000000_00000100
    Hex: $00_00_00_04
    Algebraic : 1 << 2
    Bitwise decode: |< 1

    P3 - bit 3
    Decimal: 8
    Binary: %00000000_00000000_00000000_00001000
    Hex: $00_00_00_08
    Algebraic : 1 << 3
    Bitwise decode: |< 3

    P4 - bit 4
    Decimal: 16
    Binary: %00000000_00000000_00000000_00010000
    Hex: $00_00_00_10
    Algebraic : 1 << 4
    Bitwise decode: |< 4

    P5 - bit 5
    Decimal: 32
    Binary: %00000000_00000000_00000000_00100000
    Hex: $00_00_00_20
    Algebraic : 1 << 5
    Bitwise decode: |< 5

    P6 - bit 6
    Decimal: 64
    Binary: %00000000_00000000_00000000_01000000
    Hex: $00_00_00_40
    Algebraic : 1 << 6
    Bitwise decode: |< 6

    P7 - bit 7
    Decimal: 128
    Binary: %00000000_00000000_00000000_10000000
    Hex: $00_00_00_80
    Algebraic : 1 << 7
    Bitwise decode: |< 7

    P8 - bit 8
    Decimal: 256
    Binary: %00000000_00000000_00000001_00000000
    Hex: $00_00_01_00
    Algebraic : 1 << 8
    Bitwise decode: |< 8

    P9 - bit 9
    Decimal: 512
    Binary: %00000000_00000000_00000010_00000000
    Hex: $00_00_02_00
    Algebraic : 1 << 9
    Bitwise decode: |< 9

    P10 - bit 10
    Decimal: 1024
    Binary: %00000000_00000000_00000100_00000000
    Hex: $00_00_04_00
    Algebraic : 1 << 10
    Bitwise decode: |< 10

    and so on

    Post Edited (nohab) : 10/1/2009 9:50:09 AM GMT
  • JomsJoms Posts: 279
    edited 2009-10-01 16:43
    OK, I think I am understanding this. The reason I count up like that is because I am actually using the decimal form to direct it to which pin to use.

    If that is true, then I must have something else wrong. I am attempting to get the video overlay object to run 4 times, each time using the next 3 consecutive pins.

    Video overlay 1 - P0,P1,P2 (1,2,4)
    Video overlay 2 - P3,P4,P5 (8,16,32)
    Video overlay 3 - P6,P7,P8 (64,128,256)
    Video overlay 4 - P9,P10,P11 (512,1024,2048)

    I have also tried subtracting one from each of those numbers, (0,1,3,7,15...etc). I have also tried just using overlay 1 on pins 3,4,5 and had no luck. Because of this, I am thinking that I have a pin number problem and not a variable address problem...Does that sound right?

    Can someone look at my program I have attached and see if I am making an obviouse mistake?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-01 16:57
    Remember that I/O pin 0 has a mask value of 1, I/O pin 1 has a mask value of 2, and I/O pin 2 has a mask value of 4. In general, pin numbers 0 to 31 have mask values that are the power of 2 of the pin number.

    I don't see an obvious problem with your attached program. I've only looked at it cursorily, particularly at the changes you made in the overlay module. You won't be able to get it to run with 4 overlays because you need two cogs for the main program and the serial I/O routine, one cog for the heartbeat, and one for the timer. That's 4. Each overlay will need one or two cogs. That should work for up to 3 overlays as long as you don't try to draw lines in two or more overlays at a time.

    Post Edited (Mike Green) : 10/1/2009 5:03:47 PM GMT
  • JomsJoms Posts: 279
    edited 2009-10-01 17:07
    I went through the overlay program and I can only see where it starts one new cog? Apperently I am missing where it starts the second cog.

    Even with the second new video overlays disable (commented out), i can not make the second one function. When I move my wires from P0,P1,P2 to P3,P4,P5 I can see that the video gets a little darker which shows me it is working, just no test displayed.

    I must have a variable wrong somewhere, or a variable address which is preventing me from storing or displaying any overlay for the second channel.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-01 17:25
    The LineTo routine starts up a 2nd cog whenever you draw a line. The cog quits when it's done with its work after signalling that it's done.
  • JomsJoms Posts: 279
    edited 2009-10-01 17:31
    OK. I don't think I am using the LineTo routine. The only thing I am going to be doing is putting some text in the corner. I am trying to hook four cameras to it and overlay text from the serial input on the video.


    ---EDIT---

    I did actually get it to work up to the three channels like Mike said would work.· I am not going to argue with you Mike, but could you explain why I need the LineTo routine if i am not drawing?· For simple text I don't see why I need more then one cog...· Am I wrong on that?

    Thanks for clarifying, I am just trying to actually get a full grasp on this...

    Post Edited (Joms) : 10/1/2009 6:28:08 PM GMT
Sign In or Register to comment.