Shop OBEX P1 Docs P2 Docs Learn Events
Writting to memory with assembly — Parallax Forums

Writting to memory with assembly

electric550electric550 Posts: 122
edited 2009-04-12 13:52 in Propeller 1
I have been using microcontrollers where there were assembly commands for the mov instruction that allow the user to write to a specific ram location like 40h, as well as read from the ram location, is that possible with the propeller in a single instruction?... or is the user limited to writing to variables without knowing the ram location? Sorry if this has been covered before I was not seeing it.

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2009-04-11 07:19
    mov $25,#$55 'sets cog ram location $25 to the immediate value of $55 (immediate values limited to $1FF, otherwise they have to be in a cog ram location)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBladeProp, SixBladeProp, website (Multiple propeller pcbs)
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: Micros eg Altair, and Terminals eg VT100 (Index)
    · Search the Propeller forums (via Google)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2009-04-11 07:21
    Do you mean like wrbyte, wrword, and wrlong? See the Propeller Manual for details on these commands. These particular commands thought are for writing to the HUB RAM and not the ram inside a COG.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-11 13:56
    The Propeller is a memory to memory processor. There are no separate registers as in some processors. Every instruction has a source field address and a destination field address and operations are done using a source memory location (or immediate source operand) and a destination memory location. As Timothy mentioned, there's separate memory that's shared among the cogs and is treated like an I/O device with special instructions to access it (RDxxxx/WRxxxx).
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-04-11 14:02
    Maybe it's worth to mention:

    whereas in all other instructions you have the order 'destination', 'source' this is different in the wrlong/word/byte

    wrlong someregister, HUB-RAM-Adress

    this will write content of someregister into HUB-RAM-adress, which can be given by immediate when in range $-$1ff or has to be stored
    inside a register.
  • electric550electric550 Posts: 122
    edited 2009-04-11 15:01
    Thanks that 2nd post is what I was thinking about (inside one cog), I wasn't even thinking about the central memory, that should be interesting. I will have to look more into the source field address and destination field address. Is the $0-$1ff limit due to the source and destination addresses only being 9 bits? And if so I assume that this implies that that i could store a maximum of 512 32 bit numbers with that ram addressing scheme?
  • electric550electric550 Posts: 122
    edited 2009-04-11 15:24
    ....but if I want to write a number that is larger than 9 bits, that value must be already stored somewhere in the ram then moved to the desired ram location? this meaning it is not possible to write a 32bit number to the address directly? For example if I wanted to write $FFFF to memory address $1ff it is not possible

    mov $1FF, #$FFFF

    1. So am I limited to 512 9 bit numbers with the ram address scheme in each cog. I apologize I am a little confused, so.

    mov $1FF, #$1FF would be moving 512 into the to ram address 512 and this would be move the largest possible value to the highest ram location?

    2. Also is there an assembly command to move a value from one ram address to another ram address like mov $1FF, @$02F...which would move the value at ram address 02F to the ram address location 1FF?

    3. And this shared RAM between the cogs, does this require a hub operation or do the special commands write to the memory in 4 cycles like an assembly command/

    Thanks for the help
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-11 15:25
    Yes, 9 bits will hold a value (or address) from 0 to 511. Of that, the last 16 locations have special functions (described in the Manual) leaving 496. Your cog program and its data have to fit in there.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-11 15:34
    1) The entire 496 locations are loaded initially from the shared RAM using the COGNEW/COGINIT instruction. All 32 bits of all 496 locations are copied, so you can initialize locations to anything you want. MOV $1FF,#$1FF will do what you said ... set location $1FF to the value $1FF. Remember that this is the largest immediate value. All calculations are done with 32 bits and shifts are done as a single operation in one 4 cycle instruction time regardless of the shift count.

    2) MOV $1FF,$02F will move the contents of location $02F to location $1FF.

    3) The shared memory is part of the "hub" so each cog gets one memory cycle every 16 system clock cycles to transfer one long word, word, or byte in either direction (read or write) using RDxxxx or WRxxxx where xxxx is LONG, WORD, or BYTE.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-04-11 15:39
    And where do you want to store your program, if you want to store 512 32 bit numbers?

    COG RAM holds program and data and some special registers. The 16? special registers are placed at the end of RAM. So you only have 496 longs for program and data.
    One PASM instruction has 32bit and looks always the same. Some bits for the command, some for conditional execution, some for flags, 9 for destination and 9 for source. If you set the immediate flag (or the compiler does it for you because of the #) then this does not change anything in the command structure. So you only have the 9 bit of source for the immediate.
  • electric550electric550 Posts: 122
    edited 2009-04-11 16:07
    1.So is there any trick to writing all 32 bits of a ram location in a single cog?...So when I do a
    MOV $000, #$1FF
    I would be writting ???????? ???????? ???????1 111111 to ram location 0? is there a way to address those ??? bits or are they not accessible due to the source and destination addressing, unless I go through the main hub?

    2.So I looked at the SFR's and it looks like $1F2 is the address of the input pins and $1F4 is the address of the output pins...so there is no way I could write/read a 32bit number in the cog to the pins without going through the HUB???That is going to drive me crazy[noparse]:([/noparse] I was hoping to have quick 4 instruction access to the pins using the mov command.

    3. So after thinking about it the only pins that I could read/write with a mov instruction from the cog without going though the hub are the bottom 0 through 8? or is there some way to treat the source and destination as regular bits or something funny like that?

    for example this command reads the bottom 8 pins and puts them at ram address $000
    mov $000, $1f2
    this example writes to the bottom 8 pins.
    mov $01F4, $1FF
    ?????

    4. I guess this makes bit addressable cog ram out of the question?

    Thanks for the info
  • AleAle Posts: 2,363
    edited 2009-04-11 21:24
    electric550:

    1. The immediate value is zero extended to 32 bits so it will write 00_00_01_ff to th position 0. If you only want to modify the first 9 bits of a long, use the movs instruction instead. A movd and movi also exist for different fields. RTFM on propeller assembler instructions for clarifications. Be sure to read at least three times or till it makes sense, it can take a while, believe me smile.gif.

    2. Ports do not have anything to do with the HUB. You write and read using any instruction you want. Some can be used as destination and some others not. Reading from INA or writing to OUTA takes the normal 4 cycles. There is a diagram in the manual where a simple circuit for the wiring is shown.

    3. To read a literal that is larger than 9 bits and write it some whenre do the following:


       mov OUTA, my_long_literal
     ...
    
    my_long_literal
       long  %11000011_0000000_00001111_01010101
    
    



    That way my_long_literal points to a long that contains a literal that is larger than 9 bits. Note the lack of a '#' indicating to use the contents of the memory position instead of the value itself!


    I hope this clarifies your doubts. Did I recommend reading DeSilva's assembler manual ?, n ? I do now smile.gif
  • electric550electric550 Posts: 122
    edited 2009-04-12 03:41
    Email Address Not AvailablePersonal Homepage Not AvailableSend a Private Message to electric550AIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
    Date Joined Aug 2008
    Total Posts : 20
    Posted Today 8:39 PM (GMT -7) Edit post Delete post
    Thanks for all the help. I am trying to mirror 9 input pins to 9 output pins with as little error as possible(IE as fast as possible). I was hoping i could just read the value of the inputs and do a single mov to put the values on the ouput pins. For example if I used pins 0-8 as the inputs, and I want to write those values to pins 9-16 I was hoping for the code to be something like

    PUB TransparentPINS
    DIRA := %00000000_00000001_11111110_00000000
    cognew(@Transparent,0)

    DAT

    '*********************
    '* Assembly language *
    '*********************
    org
    '
    Transparent
    MOVD $1F4,$1F2
    jmp #Transparent

    I tried it and it does not work but I am trying to figure out something along these line, move the values from the input pins ($1F2) to the output pins ($1F4)
  • kuronekokuroneko Posts: 3,623
    edited 2009-04-12 03:45
    You start your program with cognew(), i.e. it runs in a different cog then your SPIN code. Which means your DIRA setup is void. Meaning you have to setup said register in the very same cog you are using it in. Each cog has its own set of special registers. They are not shared.

    Transparent
            mov     dira, mask
    loop    movd    outa, ina
            jmp     #loop
    
    mask    long    $1FF << 9
    

    Post Edited (kuroneko) : 4/12/2009 3:55:32 AM GMT
  • electric550electric550 Posts: 122
    edited 2009-04-12 13:52
    Thanks that works great
Sign In or Register to comment.