Shop OBEX P1 Docs P2 Docs Learn Events
Machine Language Tutorial? — Parallax Forums

Machine Language Tutorial?

deSilvadeSilva Posts: 2,967
edited 2007-08-18 22:51 in Propeller 1
Propeller Assembly: Intermediate Level Tutorial by deSilva (c) 2007

You always wanted to „learn microprocessors"? Now you have discovered the Prop and think: “Gee, this is a high-end device: 32 bits and 8 cores! I shall not start with anything less powerful.”

Although I appreciate your attitude, this tutorial is not the right one for you at the moment. You have to master 2 levels before:
- Become fluent with SPIN and discover its possibilities and its limits
- Know some of its I/O features and understand the general architecture of COGS and the HUB


You will profit most from this tutorial when you have already mastered both steps mentioned above and have some general idea how machine languages work. You will also profit, when you are fluent in another processor’s machine language and now have a hard time to apply this pre-knowledge to the Prop.


Edit:
This Tutorial has now got some stability and I have prepared a PDF of a reasonable size (300 k) so it can easily be downloaded http://forums.parallax.com/showthread.php?p=668559

As the postings here have become obsolete over the time I shall (or already have) remove(d) them.

Post Edited (deSilva) : 8/19/2007 12:17:00 PM GMT
«1

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2007-08-12 19:18
    I've got quite a ways to go before I master Spin. When I do, this type of tutorial will be greatly appreciated. Much of it is over my head yet it is still easy to read.
  • potatoheadpotatohead Posts: 10,260
    edited 2007-08-12 19:22
    Like where you are headed deSilva.

    I just got done working through a very fundemental computer math and basic concept primer. rjo_ sparked some creative juices. It's way beneath this, but might apply. Looking for a review and commentary.

    I'm thinking at building this up, at about this level of detail. Too simple, too tough, too wordy, what? I'm curious to hear feedback. This is a topic I would enjoy writing about.

    deSilva, do you mind if I post that here? I didn't want to start just a thread on this, but you did, so maybe it makes sense?

    (I'll toss it, or move it if this is not warranted!)

    EDIT: WIP efforts removed. See Assembly Language Tutorial! Thread. Thanks for reading.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Post Edited (potatohead) : 8/20/2007 1:27:53 AM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-12 19:38
    potatohead said...
    I didn't want to start just a thread on this, but you did, so maybe it makes sense?
    Yes, I think this makes absolute sense! What you did is exactly what I tried to avoid, to "start at the beginnng" smile.gif
    It seems both our efforts will be perfectly complementary and will support one another.
  • hippyhippy Posts: 1,981
    edited 2007-08-12 20:12
    Maybe it's because I am familiar with microcontrollers and Assembler programming but I don't really see much of a problem with understanding the COG Processor, its operation or programming in Assembler. While the way the Propeller is put together as a whole is novel / interesting / whatever, from the perspective of a single COG it's much like any other Von-Neuman processor.

    I would completely disagree that one has to be fluent in and have mastered Spin to understand the COGs. Apart from knowing that there are read and write commands to the hub memory, and a few lines of Spin code are needed to get code into a COG and running to start with, everything else 'Spin' from a COG's perspective is irrelevant. One can write usable COG code without having to know any Spin at all beyond the one line needed to get the COG running.

    Likewise I don't think that knowing about timing or intricacies of hub accesses and their timing is at all important until one comes to wanting to do timing based control of I/O or internal COG timing.

    From the COG's perspective looking out, it's a very simple world, and I get the feeling that people may be having problems because they are trying to think of COGs in terms of Spin and that's wrong IMHO.

    There are three parts to a Propeller -

    COGs - eight of them, all the same from their programming perspective.

    Spin - Of which up to eight concurrent Spin programs can be running at any time.

    Data Structures - Through which Spin programs and COG programs interact with each other.

    A COG program will do one or two things, and often both - Interact with I/O pins and control registers and/or interact with data structures held in the hub memory. I believe there would be good mileage to be had in ripping potential COG programmers away from Spin entirely to start with, then re-introduce how a COG and Spin program interacts through the shared hub memory later.

    Initially I had problems understanding how the Propeller worked as a whole, but once I realised it was just eight processors and some shared memory on a single chip it all became crystal clear.

    The only thing I can see which might require explanation for anyone new to COG programming is the mechanism of CALL which puts the return address at the RET instruction, but they wouldn't need to know how it works when starting off, just that it does.

    Perhaps the real questions is, what difficulties are Propeller users having when it comes to Assembler programming ? Is it just that there are a lot of high level language ( Spin ) programmers who are quite simply unfamiliar with low-level Assembler programming ?
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-12 22:43
    @hippy: I fully appreciate your posting; I read through the manual 6 weeks ago, thus learning it by heart, startet writing my first larger programs and voil
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-08-12 22:54
    deSilva, looks very good but makes me feel bad I don't know spin that well [noparse]:)[/noparse]

    If you want any of your translations proof read let me know, I spotted a few bits that did not read so well. I think that might be better done within a word document or similar rather than from forum posts however.

    Potatohead, I really like your document a lot excellent stuff, it reminds me of what I always say about mathematics, "its just adding up".

    All of this might be compiled into an ebook with chapters written by different people.

    Cheers,

    Graham
  • BTXBTX Posts: 674
    edited 2007-08-12 23:02
    deSilva.
    Could be great !!. if you put all togheter in pdf's. [noparse]:)[/noparse]
    Well done.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-12 23:02
    @Graham: Thank you for your offer! I think there are more than ".. a few bits that do not read so well.." smile.gif
    But let me first have the other 5 chapters, as I might restructure things...Hippy made some remarks I have to think about.. It is tricky to find your audience...
  • potatoheadpotatohead Posts: 10,260
    edited 2007-08-12 23:42
    @Graham All adding up indeed. Thanks. "everything adding up" and complementing really changed my view of math. All thanks to a grumpy middle school teacher, board one day...

    @deSilva No kidding. I find it very helpful to write to someone. In this case, it just happened to be rjo_ who struck a chord on that other thread a while back. His comments triggered a lot of early learning memories. He wants to write some stuff too, and that got me in the mood.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Post Edited (potatohead) : 8/13/2007 6:52:16 AM GMT
  • potatoheadpotatohead Posts: 10,260
    edited 2007-08-13 15:15
    I need a bare minimum example. Enough spin to get the Prop started, assembly to add a coupla numbers, blink an LED.

    Want to make sure it's solid, with no best practice errors. (My code has a batch of this stuff that will get fixed while completing the pdf work I started.

    Anyone have a pointer, or care to just knock one or two out?

    I want to explain it, and that's easier coming from someone else.


    Is it a big deal to nip examples and commentary from this forum?

    The PDF will be left here for people to use. I'll also likely put it up on some publishing on demand site (lulu?), for those who want to get hard copy to be able to do so.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Post Edited (potatohead) : 8/13/2007 3:20:27 PM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-13 15:35
    potatohead said...
    I need a bare minimum example. Enough spin to get the Prop started, assembly to add a coupla numbers, blink an LED.
    It is a pity you have not looked at my example "ex01" near the beginning of my first posting :-(
  • ErNaErNa Posts: 1,749
    edited 2007-08-13 17:01
    REV a, n
    Clears upper n Bits und reverses the sequence of the (32-n) lower bits of register “a”.

    Reverse means what? Just invert (0->1, 1->=9) or bit0 -> bit n, bit1 -> bit n-1 ... ?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-13 17:15
    Reverse the sequence of the lower 32-n bits, bit0 <-> bit n, bit1 <-> bit n-1, etc.
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-13 17:21
    I see this is tricky: Thought I explained it by the word "sequence" - but I failed...

    Post Edited (deSilva) : 8/13/2007 5:35:03 PM GMT
  • potatoheadpotatohead Posts: 10,260
    edited 2007-08-13 17:45
    @desilva:

    Yep. That will serve nicely!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-13 18:12
    Added Sidetrack E: "Why the HUB is called the HUB.." in chapter 2
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-08-15 18:19
    Chapter five support item for your pedagogical delight:

    Post Edited (Fred Hawkins) : 8/15/2007 9:53:46 PM GMT
    768 x 1024 - 24K
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-08-15 18:24
    deSilva,

    "notabene"??
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-08-15 18:32
    nb. lol, sharpshooters abound. Two words usually, literal meaning 'note well'. Used, says Webster's, to call attention to something important.
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-15 18:44
    @Fred: Yes, I like part of it... But I think the information given is too ... diluted. It will take hundreds of pages to continue in that style...
    I think it is a simple fact that immediate addressing is restricted to 9 bits and no need for any sarcasm. Maybe I have lived too long with much stronger constraints...

    @Graham: O dear! I THINK I consulted www.leo.org a most reliable source of translation in and from many languages and used nearly as heavily as the wikipedia (in Germany i.e.) Nevertheless, I NOW consulted it, and is says this should be an English word smile.gif

    Basically it's Latin "nota bene" (which is nearly Italian) meaning: "mind you".

    Post Edited (deSilva) : 8/15/2007 6:51:11 PM GMT
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-08-15 19:11
    deSilva said...
    ·It will take hundreds of pages to continue in that style...
    I have simple tastes and smaller ambitions; it's just a 768x1024 gif. And·their doing is strictly related to the slow speed of my 'aha' processes. That's why I stuck it in your thread and not one of my own.
  • mparkmpark Posts: 1,305
    edited 2007-08-15 19:26
    Fred,
    MOV·affects all 32 bits of its destination.
    If you need a 32-bit source, you can always use a cog register; you don't have to use RDLONG.

    ·
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-08-15 19:46
    Oh well as long as latin speakers understand it [noparse];)[/noparse]
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-08-15 19:49
    re. my last comment:

    I just realized I use it myself only I would write nb.

    I also don't know what ie. stands for though I know it means that is

    Graham
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-15 20:04
    Well, mpark points to a flaw in Fred's poster, in that MOV # sets bits 31..9 to zero, rather than leave them unchanged. That should be fixed...

    I made no systematic examples, as MOV and it's derivates are used in all examples in many ways.. I gave an example how to utilze NEG to enter -1 to -512.

    Using some preset longs is a trade-off against a shift instruction following a MOV. It takes slightly longer but can be easier to understand
    MOV a, #1
    SHL a, #31
    


    Microprocessor programmers are not used to shifts >1 smile.gif
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-15 20:34
    Graham Stabler said...
    I also don't know what ie. stands for though I know it means that is

    It couldn't be easier: ID EST
    which means - surprise, surprise! - that is smile.gif
    Sorry, it's not my fault I know such things: I had it in school for 6 years...
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-08-15 21:44
    deSilva said...
    Well, mpark points to a flaw in Fred's poster, in that MOV # sets bits 31..9 to zero, rather than leave them unchanged. That should be fixed...

    I made no systematic examples, as MOV and it's derivates are used in all examples in many ways.. I gave an example how to utilze NEG to enter -1 to -512.

    Using some preset longs is a trade-off against a shift instruction following a MOV. It takes slightly longer but can be easier to understand
    MOV a, #1
    SHL a, #31
    


    Microprocessor programmers are not used to shifts >1 smile.gif
    Arrrrgggghhhh!!! The manual does mention that sort of thing for ABS and ABSNEG. (and others? yes: RDBYTE, RDWORD)

    But my point that the maximum significance of an immediate value is limited to 9bits still stands.

    This shows up often in the setting of output bits, where one line set ups a bit, another shifts it into position and finally a third mux's it.

    ps. poster fixed

    Post Edited (Fred Hawkins) : 8/15/2007 9:49:00 PM GMT
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-08-15 22:37
    Fred, what you are requesting is impossible for Von Numen SW-RISC architectures. Von Numen architectures have equal size data and instruction busses because these busses are one in the same. Single width RISC architectures have by design exactly 1 instruction per fetch/execution, and according to the research of Andrew S. Tanenbaum (one of the most respected individuals in computational theory) SW-RISC is the most efficent means of computing both in terms of reduced ALU complexity and program execution.

    Beyond the debatable nature of efficency, and the merits and demerits of CPU architecture, what you want to do is absolutely possible as is. In essence what you are asking for is a MOV R1, #32 bit constant. You are thinking that this has to be done as two consecutive 32 bit locations in cog memory (MOV instruction followed by a 32 bit constant). But·these two locations dont·have to be consecutive. The following bit of code accomplishes the same thing with no loss of function or space:

             MOV R1, Constant 
    ... 
    Constant LONG $0123_4567
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 8/16/2007 4:22:53 AM GMT
  • potatoheadpotatohead Posts: 10,260
    edited 2007-08-15 23:04
    Nicely said!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-16 00:01
    Paul Baker (Parallax) said...
    ...with no loss of function or space
    And with no loss of time, I should add smile.gif
Sign In or Register to comment.