Shop OBEX P1 Docs P2 Docs Learn Events
How to use pointer in assembly? — Parallax Forums

How to use pointer in assembly?

Daniel NagyDaniel Nagy Posts: 26
edited 2010-01-06 00:12 in Propeller 1
Hello everybody!

I must miss something, or left a piece of my brain, but I can't figure out how to use a register as a pointer.
In x86 assembly (if I remember correctly):

1.
mov ax, bx   //means move the value stored in BX to AX.

2.
mov [noparse][[/noparse]ax],bx  //means write the value of BX to the addresse that AX stores.





How to do it in propeller assembly?
I've something like this:

mov pointer, #pin0

mov pointer, something    //want to write to the address that pointer stores, not to pointer itself, since i'd like to increase the value of pointer to reach the other pinx-es.


pointer res 1
pin0 res 1
pin1 res 1
pin2 res 1
.
.
.




How?

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2010-01-04 12:50
    Daniel, welcome to the forum. You will find a lot of help here.

    We use self modifying code to do this...
     
             movd  pointer, #pin0     'set the pointer into the instructions' destination
             nop                      '1 instruction delay to handle the pipeline - could be a useful instruction
    pointer  mov   0-0, something     'we use 0-0 to signify that we are modifying the operand (instruction)
    
             add   pointer, x200      'increment the pointer (destination) by 1
             ...
    
    
    x200     long  $200               ' %1_000000000 = adds 1 to the destination field = 1 << 9
    pin0 res 1
    pin1 res 1
    pin2 res 1
    .
    .
    
    




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

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
    · Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
  • Daniel NagyDaniel Nagy Posts: 26
    edited 2010-01-04 13:08
    Oh, my... [noparse]:)[/noparse]

    Can you explain why is it better or necessary over the "good old" x86 [noparse][[/noparse]pointer] syntax? Seems very complicated for the first blink to me.

    Thanks for the answer, anyway!
  • Daniel NagyDaniel Nagy Posts: 26
    edited 2010-01-04 14:15
    Is this means, that every time I need to use a pointer I need to use this three line block with different labels? shocked.gif

    
    .
    .
                    movd   label1, addresse1           'replaces the destination field at label1 with addresse1
                    nop                                'waits 4 clocks
    label1          mov    0-0, value                  '0-0 is replaced with addresse1 at runtime, so it will be correct 
    .
    .
    .
                    movd   label2, addresse2
                    nop
    label2          mov    0-0, another value 
    .
    .
    
    

    Post Edited (Daniel Nagy) : 1/4/2010 2:22:05 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-04 14:43
    It might be possible to allow something like the x86 syntax, but the assembler would have to translate that into the instructions that Cluso99 indicated because that's the way the hardware works. Assembly language usually provides an exact 1-1 relationship between what's written and the actual hardware instructions.

    For an interesting and informative alternative, have a look at PropBASIC which takes a simple subset of Basic and translates it into assembly language (http://forums.parallax.com/showthread.php?p=867134).
  • Daniel NagyDaniel Nagy Posts: 26
    edited 2010-01-04 18:23
    Thanks for the help and the suggestion!
  • ericballericball Posts: 774
    edited 2010-01-05 01:00
    Just remember address1/address2 (in your example) point to COG RAM, so any arrays etc, have to share the 496 longs with your PASM code. This also means each array element is 32 bits.

    The alternative is to store the data in HUB RAM. This avoids self modifying code, allows for (unsigned) byte and word access and is almost as fast when synchronized.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
  • Daniel NagyDaniel Nagy Posts: 26
    edited 2010-01-05 09:20
    Thanks ericball! Since my first post I solved what I wanted. I have the basic background for asm programming (if I may say so). I've some faded memory of C64 assembly back in the good old days, and some more recent memory of x86 assembly, only the Propeller is the first microcontroller in my life. But I'm really, really enjoying it. And amazed how well designed, and innovative chip it is in many aspects.
    And thanks for all the help again!
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-01-05 22:15
    You asked about the advantage of self modifying code. Short answer: it allows to have 8 processors on one die.

    Long answer:
    You might have noticed that a lot of details are different from usual microprocessors/microcontrollers:
    No set of registers - or let's better say: no difference between COG-RAM and registers
    No stack
    No indirect addressing
    No interrupts

    All this is due to one simple goal : keep the things simple to allow max. speed and min. size.
    Indirect adressing mode problems start with the instructions machine code itself. Where do you want to put the additional parameter for the instruction? You need the source, the destination and additionaly an offset. All 32 bits are used! Other micros simply add a byte or a word or whatever - having variable lenght instructions. Makes things more complex.
    Next problem is the execution. You need an additional step to calculate the resulting address. How you wanna do that? Add another stage in the execution pipeline? In general or conditional? Makes execution slower or you have instructions with different execution speed. 5 cycles instead of 4 for example.
    And what's the advantage? Of course one stage in the pipeline is executed faster than one instruction for self-modifying code. But usually you do such things in a loop and it's no difference in adding 1 to the source address from increasing the offset.

    It would be really interesting to see how much memory a SPIN interpreter would need on a different architecture!



    PS: guess I mixed up indirect addressing with indirect addressing with offset. Of course you don't have to calculate something·for indirect addressing. But you need an additional fetch. So, the indirect addressing itself has no problem with instruction-size as stated above. That's only true for indirect addressing with offset. ... it's late ... maybe to late to post something useful ;o)

    Post Edited (MagIO2) : 1/5/2010 10:22:46 PM GMT
  • CannibalRoboticsCannibalRobotics Posts: 535
    edited 2010-01-06 00:12
    Welcome to the Prop learning curve! It's truly an amazing little beast. The other thing you need to look at is the mechanics of Calls and Jumps or you'll find yourself wondering why there is no PUSH or POP.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Signature space for rent!
    Send $1 to CannibalRobotics.com.
Sign In or Register to comment.