Machine Language Tutorial!

13»

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2007-09-07 - 22:34:03
    @mcstar
    (1) I am doing my best to write a sequel smile.gif
    (2) It is best NEVER to think of bytes when inside a COG. It is of little importance how many "bytes" there are - there are 512 cells (I call them "words" out of habit, but that somtimes confuses people)
    (3) All cells in the COG (upto #495) can of course be used! But they are not neccessarily zero; it depends on what had been allocated in the HUB. This can also be changeable variables.

    In fact this is a convenient way to "parametrize" a COG
  • rjo_rjo_ Posts: 1,825
    edited 2007-09-07 - 23:51:36
    stepped away for moment

    Thanks

    Rich
  • hinvhinv Posts: 854
    edited 2007-10-27 - 21:24:03
    Hi Mr Potatoehead,

    It is quite a cooincidence that 2 guys named Doug who really like SGI's end up on an unrelated forum '^)

    Anyway, I like your assembly pdf. It starts low enough that it will help tech my 10yearold boy after he gets through the boebot kit.

    I have a couple of corrections for you. Page 8, it should read "(15 x 4096)", top of page 10, "1024 bytes = 2^10"

    Take Care,
    Doug
  • potatoheadpotatohead Posts: 9,820
    edited 2007-10-27 - 23:46:59
    Thanks!

    I'll fold those in, and have another coupla examples to add very soon.

    SGI machines (the older IRIX models) are the best computers ever made. Saw your user name, and just knew ..another IRIX head. Sweet!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    Do not taunt Happy Fun Ball! @opengeekorg ---> Be Excellent To One Another SKYPE = acuity_doug
    Parallax colors simplified: https://forums.parallax.com/discussion/123709/commented-graphics-demo-spin<br>
  • mosquito56mosquito56 Posts: 387
    edited 2007-12-06 - 18:23:10
    I just read the assemblers for idiots, Thanx much for getting me started Silva. Then I read that another person understands pops and pushes. I didn't see that in your assembly06.pdf. Are there more instructions that I have missed? Where do I go now?
    Don

    P.S. I have been trying to learn this for 20yrs now. If I had known it was this easy I would have done it along time ago. Thank God for the internet.
    New User 2nd Day
  • potatoheadpotatohead Posts: 9,820
    edited 2007-12-07 - 13:46:12
    Hi Don.

    Assembly06 is the very beginner one I wrote. It's here on Desilva's thread because we both thought his intermediate tutorial and this one belonged in the same place. In the very near future, I've got some more example programs to incorporate into the beginner document. (Real Life is taking it's toll right now!!)

    I would collect the Propeller Assembly referrence, found in the Propeller Manual, DeSilva's Intermediate document, and the Propeller Data Sheet together and start working on your own small programs.

    ---and it's assembler for BEGINNERS, not idiots! [noparse]:)[/noparse]

    Do keep that in mind as you have a great time telling your prop what you want it to do!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    Do not taunt Happy Fun Ball! @opengeekorg ---> Be Excellent To One Another SKYPE = acuity_doug
    Parallax colors simplified: https://forums.parallax.com/discussion/123709/commented-graphics-demo-spin<br>
  • obrienmobrienm Posts: 65
    edited 2011-03-13 - 08:07:24
    deSilva,
    Your tutorial on propeller assembly language has been extremely useful. It took me 2 years to stop the evasion of PASM in my Spin code, I have some experience in 80386, 68000 from univ and 8085, 809 from when I was a kid - however your tutorial got me running within 2 hours by reading to page 12. My first P8X32A machine language is attached.
    I especially like your analogy of the "cell" for the 512 32-bit registers that aids in understanding self modifying code, and also the fact that MAX is really MIN.
    thank you very much
    / Michael O'Brien
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    VAR
      ' shared display RAM for the 4 display cogs
      long  buffer[32]                                         
      long  Stack0[64]                                         ' Stack Space
      byte  Cog[7]                                             ' Cog ID
      long  range
      long  aCounter
    OBJ
      SER  : "Parallax Serial Terminal.spin"                   ' part of the IDE library  
      STR  : "STREngine.spin"                                  ' in the current directory
    PUB main | milestone,start,number,index, lRec,x,i, mIndex, mValue, path,height, maxPath, maxHeight
      ' wait for user to switch to terminal
      waitcnt((clkfreq * 5) + cnt)
      maxPath := 0
      maxHeight := 0
      milestone := 0 ' track whether we got a path or max height hit
      range := 1 << 17
      ser.Start(115_200)'31,30,0,38400)
      ser.Home
      ser.Clear
      ser.Str(string("Collatz Conjecture", ser#NL))
      aCounter := 27
      _nextVal := @aCounter ' pass word to assembly via hub ram
      ser.Str(string("Max Value for "))
      ser.Str(STR.numberToDecimal(aCounter,8))
      ser.Str(string(" is "))
      Cog[1] := cognew(@entry, @aCounter) + 1
      waitcnt((clkfreq * 2) + cnt)  ' it takes 100ms to load a core
      ser.Str(STR.numberToDecimal(aCounter,8))
        
    DAT
                  org    0
    entry         ' iterate the collatz sequence for _nextVal
                  RDLONG    _nextVal, PAR       ' read from shared ram (7-22 cycles)
    :iterate
                  ADD       _path, #1           ' increment path
                  MOV       _bit0, #1           ' create mask
                  AND       _bit0, _nextVal WZ  ' check bit 0 - affect zero flag
                  IF_NE JMP #:mul3x1
    :div2         ' if even we divide by 2
                  SHR       _nextVal, #1        ' divide by 2
                  CMP       _nextVal, #1 WZ     ' check for 1 value == finished
                  IF_E JMP  #:finish              
                  JMP       #:iterate           ' return to top of loop
    :mul3x1       ' if odd we transform by 3n + 1
                  MOV       _3rdVal, _nextVal
                  SHL       _nextVal, #1        ' multiply by 2
                  ADD       _nextVal, _3rdVal   ' add to multiply by 3
                  ADD       _nextVal, #1        ' add 1
    :maxValue     ' check for maximum value
                  MIN       _maxVal, _nextVal   ' VERY ODD (max is actually min)
                  JMP       #:iterate           ' return to top of loop
    :finish
                  SUB       _path, #1           ' we discount the first path count
                  'MOV       _nextVal, _path     ' copy path to return val
                  MOV       _nextVal, _maxVal   ' copy maxVal to return value
                  WRLONG    _nextVal, PAR       ' write back to hub ram (thank you deSilva for reverse flow explanation)
    '              WRLONG    _path, PAR 
                  
    :endlessLoop
                  JMP       #:endlessLoop       ' keep the cog running
    _3rdVal       long   $00000000
    _nextVal      long   $00000000      
    _maxVal       long   $00000000
    _path         long   $00000000
    _bit0         long   $00000000
                  FIT    496                    ' deSilva (16 I/O registers in 496-511)
    
    '' http://forums.parallax.com/showthread.php?96594-Machine-Language-Tutorial!&p=668559              
    
  • HollyMinkowskiHollyMinkowski Posts: 1,398
    edited 2011-03-13 - 13:02:55
    obrienm, sadly deSilva is no longer a participating member of the forum.

    I concur that his short PASM tutorial is excellent.

    32 bit asm instructions, especially as well thought out as the Propeller's, are
    very powerful and you can do a lot in the 2kb of cog space.
    [The Bug Stops Here]
Sign In or Register to comment.