Shop OBEX P1 Docs P2 Docs Learn Events
Assembly language for a beginner — Parallax Forums

Assembly language for a beginner

RavenkallenRavenkallen Posts: 1,057
edited 2010-05-26 02:33 in Propeller 1
Hey, guys.·I have wanted to learn how to program in assembly for a long time. The only problem i had was not finding a proper micro. Now the propeller is capable of pretty much everything, including assembly. So would any of you know a good starter book/ pdf file/ tutorial, to read over. I know PASM is a little different from regular ASM, but it is the same principle, right. I do have experience in programing(C++, Basic and spin), i just thought it would be nice to put one more under my belt......Thanks again for all the previous help.
«13

Comments

  • DynamoBenDynamoBen Posts: 366
    edited 2010-05-19 16:01
    There are a couple of resources in a sticky at the top of this forum, but I will link to them here:

    Beginners Tutorial:
    http://forums.parallax.com/showthread.php?p=601870

    Advanced:
    http://forums.parallax.com/showthread.php?p=668559

    At UPEC there was a mention that there is a forth coming PASM tutorial from Parallax...no idea on timeline.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-19 16:09
    While I don't teach Assembly per se, I do use it and explain what I'm doing in many of my Nuts & Volts columns. You can find them here:

    www.parallax.com/Resources/NutsVoltsColumns/TheSpinZone/tabid/781/Default.aspx

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • beazleybubbeazleybub Posts: 102
    edited 2010-05-19 16:39
    Hi·Ravenkallen,

    If you don't mind me jumping on your train. [noparse]:)[/noparse]

    I'm experimenting with dot matrix displays and will have to learn assembly as well.

    Maybe we could·learn together and··share what we learn with each other.
    There might be something you or I don't understand along the way that the other does.

    Feel free to PM me if you would like.

    Cheers

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    How can there be·nothing? Nothing is something!
  • rjo_rjo_ Posts: 1,825
    edited 2010-05-19 16:53
    PASM is pretty simple to learn... the reason most people... such as me... have any trouble with it is that the difference between ASM and PASM is at the level of machine logic... how it works is easy to figure out... what do with it and how it relates to the outside world is far more interesting.

    Spend an afternoon sending various kinds of stuff back and forth between Spin and Pasm and you have learned everything that is necessary to get started. There are some tutorials... (that go a little overboard and make it look more complicated than it needs to look) in the sticky threads. After that... don't worry about PASM until you actually need it. When you find that you actually need it... then you can spend another afternoon figuring out exactly what you want it to do and it is all down hill from there.

    I am not a PASM wizard... I learned just enough to know that if a problem pops up that requires PASM... it is there... it is pretty simple and there are hundreds of examples available.

    Rich
  • DynamoBenDynamoBen Posts: 366
    edited 2010-05-19 17:14
    rjo_ is correct learning the commands is simple part, thinking in PASM is the hard part. It very tedious compared to spin, you have to explicitly do things that are just handled for you in spin. Converting something from spin to PASM is a good idea then you can compare apples to apples.
  • rjo_rjo_ Posts: 1,825
    edited 2010-05-19 17:19
    DynamoBen

    On the other hand... there is a thrill to rotating bits that is hard to explain. For most people, PASM might seem like a grind... I find it an absolute ball. I just don't know enough about everything else to actually need to use it as often as I would actually like to use it... task oriented and all that stuff[noparse]:)[/noparse]


    Rich
  • bill190bill190 Posts: 769
    edited 2010-05-19 18:41
    Assembly is closer to the hardware and circuits. The 1's and 0's.

    Helpful to know a bit about logic gates like...

    AND gate, OR gate, NOT gate, XOR gate, NAND gate, etc.

    Here is a bit on that...

    http://en.wikipedia.org/wiki/Logic_gate

    For example, an OR gate has two inputs and one output (we're talking 1's and 0's here).

    If either input is a 1, you get an output of a 1.

    If both inputs are 0, the output is 0.

    If both inputs are 1, then you would also get an output of 1.

    In assembly,·you might "OR" something to turn it on. Like this...

    ······· or dira, Pin0
    ······· or outa, Pin0

    But below that you also have to say what Pin0 is...

    Like this...

    Pin0 long %0000_0000_0000_0000__0000_0000_0000_0001

    Or like this...

    Pin0 long |< 0


    And what exactly are we "OR'ing"?

    0000_0000_0000_0000__0000_0000_0000_0001 (Your setting)
    0000_0000_0000_0000__0000_0000_0000_0000 (Existing settings)
    OR'ed =...
    0000_0000_0000_0000__0000_0000_0000_0001 (Turns on pin 0 for dira/outa)

    Where the 1 is at the far right is pin 0, next to the left of that is pin 1, and on up.

    Basically you do a lot of "ANDing", "ORing", etc. And moving bits around with commands like "MOV".

    I would suggest just turning on an LED for starters. You also need to load the assembly program into a cog, that should be explained in the above documents listed.
    ·
  • beazleybubbeazleybub Posts: 102
    edited 2010-05-19 18:59
    Thanks for the suggestions and links.

    Is assembly language unniversal per say or is it chip specfifc?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    How can there be·nothing? Nothing is something!
  • LeonLeon Posts: 7,620
    edited 2010-05-19 19:19
    Manufacturers usually make families of devices with similar architectures and instruction sets.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • bill190bill190 Posts: 769
    edited 2010-05-19 21:26
    beazleybub said...
    Thanks for the suggestions and links.

    Is assembly language unniversal per say or is it chip specfifc?

    You pretty much need to know the architecture (building blocks) of the chip and how it is put together.

    I suppose you could say this would be like·going·to the grocery store in different cities. The vehicle you take being like the "language" and the cities being like different "chips".

    A higher level language would be like a taxi.
    Assembly language would be like driving yourself.

    So with a higher level language (taxi), you can go to any city (chip) and tell the driver to take you to the grocery store. That's all you need to do. You get to the store.

    With assembly (drive yourself), you need to know the·specific directions on how to get to the store. And this would be different for each different city (chip).

    So with the highest level things like Microsoft software running on anything, you can say File/Print and your file gets printed on the printer.

    If doing the same thing in assembly, you would need to know the exact instructions to use, the design of the chip, what is connected to what, configuration settings, and so forth.

    This is quite easy on the Propeller because there is a lot of stuff taken care of for you.

    But on other chips the configuration settings - say to use a certain pin for printing - can be quite complex! For example, here is a blurb from a 400 page Pic 18f4550 microcontroller data sheet for how to configure some pins...

    "The PBADEN bit in Configuration Register 3H configures PORTB pins to reset as analog or digital pins by controlling how the PCFG0 bits in ADCON1 are reset. Note: On a Power-on Reset, RB4:RB0 are configured as analog inputs by default and read as ‘0’; RB7:RB5 are configured as digital inputs. By programming the Configuration bit, PBADEN (CONFIG3H<1>), RB4:RB0 will alternatively be configured as digital inputs on POR."

    And that is only one of about 34 different configuration settings. If you don't have those configuration settings right for the pins you are using, you're not going to print anything!

    But again you don't need to worry about that stuff with the Propeller, which is nice!
    ·
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-19 22:35
    Sounds good beazleybub. And thanks to everybody else for the suggestions.
  • HollyMinkowskiHollyMinkowski Posts: 1,398
    edited 2010-05-19 23:21
    I highly recommend PropBASIC as a PASM learning tool!

    You can look over the assembly language code that the compiler
    generates. Bean made both a great compiler and a PASM learning
    tool smile.gif
  • DynamoBenDynamoBen Posts: 366
    edited 2010-05-19 23:22
    bill190, taxi vs driving yourself is a great analogy!!!
  • DynamoBenDynamoBen Posts: 366
    edited 2010-05-19 23:25
    HollyMinkowski said...
    I highly recommend PropBASIC as a PASM learning tool!

    You can look over the assembly language code that the compiler
    generates. Bean made both a great compiler and a PASM learning
    tool smile.gif

    I tried this method when PropBASIC came out and it didn't work for me. Largely because the code produced is fatter than I would like and can be difficult to follow/read.

    Call me old fashioned but starting from scratch and learning how to blink an LED is a better way to start. [noparse]:)[/noparse]
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-20 01:30
    Well, i successfully ran the demo assembly program that was included in the propeller manual. it is now blinking a led on and off.....YES. Hey beazleybub, it is on page number 239 if you want to give it a go.
  • kuronekokuroneko Posts: 3,623
    edited 2010-05-20 01:42
    Ravenkallen said...
    Well, i successfully ran the demo assembly program that was included in the propeller manual. it is now blinking a led on and off.....YES. Hey beazleybub, it is on page number 239 if you want to give it a go.
    Good. As the next exercise get rid of the hardcoded delay and make it a function of the actual clock frequency (i.e. make the LED flash 4 times a second for RCSLOW..80MHz).
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-20 01:47
    @Kuroneko....Say what? This is just my first assembly program and i have no idea what you are talking about....please, forgive my stupidity and elaborate a little.
  • beazleybubbeazleybub Posts: 102
    edited 2010-05-20 01:49
    I,m at work right now. I promise I'll get to it by this weekend. cool.gif

    I work from 4PM till 2AM.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    How can there be·nothing? Nothing is something!
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-20 01:53
    @beazleybub..... Wow, 4pm to 2am. Tough job.
  • beazleybubbeazleybub Posts: 102
    edited 2010-05-20 01:59
    Yes, a very tough job. I am a truck driver. Gotta hit the road actually right now.
    Sent this through my Moto Droid. smurf.gif

    Good luck on your study. Write to you tomorrow.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    How can there be·nothing? Nothing is something!
  • localrogerlocalroger Posts: 3,452
    edited 2010-05-20 02:04
    Ravenkallen, kuroneko's challenge is actually a bit harsher than he might realize; he wants you to read the system _CLKFREQ and use that to generate the constant for the WAITCNT so that the LED blinks the same rate no matter what speed the Prop is running. It would be easy in Spin, but that's actually kind of hard in PASM, for starters because the Prop has no multiply or divide instructions so you need routines to do those things, plus you need to know how to read _CLKFREQ (which IIRC you have to RDWORD from one of the header locations in Hub RAM).

    A better exercise would be to learn how to communicate between your PASM program and the Spin program that starts it up, by using PAR to pass a location where you tell it something -- for example, from the Spin parent to change the LED blink rate or pin or something like that.

    I think someone should mention that Propeller assembly isn't like assembly on any other comparable CPU, because just about all other CPU's allow for running "inline" assembly -- that is, you can make an assembly routine and "call" it, where it does its much faster thing while the parent code waits. On the Prop, when you spawn assembly code it inherits its own all-to-itself 80 MHz cog, and runs off to do its own thing regardless of what the mother code wants or thinks. So later synchronization requires the assembly code and the Spin that spawned it to "hook up" by dropping values into vars that each knows to read. It's a little more complicated, sometimes weirdly wasteful, but also far more powerful than the usual method.

    The reason the Prop can't run inline assembly is that the Spin interpreter that runs Spin code takes up a whole cog with not a long to spare, so there's no way for that cog to add code in its own memory space and run it. All it can do is start another cog -- a much more complicated deal than what happens when a processor can hold its interpreter or compiled code and some extra stuff in the same memory. It's weird at first if you're not used to it, but like everything about the Prop what at first seems like a weirdness or weakness turns out to also be, at least in certain situations, a surprising strength.
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-20 02:04
    Will do.
  • kuronekokuroneko Posts: 3,623
    edited 2010-05-20 02:24
    localroger said...
    Ravenkallen, kuroneko's challenge is actually a bit harsher than he might realize; he wants you to read the system _CLKFREQ and use that to generate the constant for the WAITCNT so that the LED blinks the same rate no matter what speed the Prop is running. It would be easy in Spin, but that's actually kind of hard in PASM, for starters because the Prop has no multiply or divide instructions so you need routines to do those things, plus you need to know how to read _CLKFREQ (which IIRC you have to RDWORD from one of the header locations in Hub RAM).
    Fair enough. Yes, it implies general knowledge as to how it's done (using clkfreq) but from there it's just a question of figuring out where the value is stored and just read it. Also, I picked 4 for a reason [noparse]:)[/noparse] What it boils down to is this:

    rdlong  Delay, #0      ' hub location holding the system frequency
    shr     Delay, #3      ' equivalent to clkfreq/8, LED on 4 times, LED off 4 times
    


    Keep asking questions!

    Post Edited (kuroneko) : 5/20/2010 2:38:56 AM GMT
  • localrogerlocalroger Posts: 3,452
    edited 2010-05-20 02:43
    kuroneko, you cannot expect a self-professed n00b to find a solution like that. In fact, given the number of tricks like that hidden up the Prop's sleeve, you can probably find quite a few Prop vets who'd do some head scratching over it. (I don't consider myself a prop vet yet, but give me another year.)

    My father was a really excellent teacher (of college physics, among other things) and I owe much of what I have become to him. One thing I picked up from him is that while it's true you must challenge the n00bs to find their own solutions, you really must also calibrate the problem to their level of expertise, because giving the n00b a problem yo ucan solve but he can't isn't a good thing, it's just showing off.

    If someone has just learned to blink an LED but you don't know their mixed-sign finite math skillz it's a much better idea to go next into moving information around, particularly in an environment like the Prop where the mother program in the higher level language keeps going. There's really no reason at all for a PASM program to ever try to figure out its blink rate constant; if that's an issue, Mom should do that and probably stuff it into the PASM image before the coginit.
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-20 02:56
    Uh, wow. Yeah, doing that in spin would be kinda easy, but, as stated above, i have no experience in assembly at all. The reason i choose the propeller to learn assembler, is because parallax always has excellent documentation for their products. So like any other programming language to master, it only takes time and the willingness to learn...
  • kuronekokuroneko Posts: 3,623
    edited 2010-05-20 02:58
    localroger said...
    kuroneko, you cannot expect a self-professed n00b to find a solution like that.
    I apologise. I admit having trouble scaling down (which works much better in a face-to-face environment).
  • potatoheadpotatohead Posts: 10,261
    edited 2010-05-20 03:06
    My next moves on the LED program would be:

    Blink the pin in a repeatable, short pattern. (create program loops and delays) Your initials in morse code, for example.

    Blink it in a longer pattern (use data in loop) Some cool phrase, or maybe fade the LED on a duty cycle)

    Blink more than one pin. (masking / I/O)

    Blink more than one pin in a different pattern. (either use more than one COG, or interleave the loops and fetch data)

    etc...

    The model for this kind of thing I like best is like the book, "Learning Perl", where you expand some silly simple thing into something quite complex, always adding a bit at a time, and always free to tinker a bit along the way.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    8x8 color 80 Column NTSC Text Object
    Safety Tip: Life is as good as YOU think it is!
  • bill190bill190 Posts: 769
    edited 2010-05-20 05:29
    Ravenkallen said...
    Well, i successfully ran the demo assembly program that was included in the propeller manual. it is now blinking a led on and off.....YES. Hey beazleybub, it is on page number 239 if you want to give it a go.
    You guys are quick around here! Good work!

    It took me two years of reading (and saving money to buy a pc) to get my first assembly program working...
    ·
  • RavenkallenRavenkallen Posts: 1,057
    edited 2010-05-20 13:37
    @potatohead. I wouldn't mind trying all of the things stated above, but i still can't find a tutorial that is easy to understand and yet still presents the important information...


    @bill190.... Wow, two years. I am guessing you didn't use a propeller?

    @kuroneko... Don't worry about it. No harm done. Sometimes when teaching one can forget that he/she is smarter than the class and then attempts to jump right over some important concepts. It is kind of like teaching a kid to add two numbers and then expect them to multiply a 6 digit number... WE all have to take baby steps
  • bill190bill190 Posts: 769
    edited 2010-05-20 14:42
    Ravenkallen said...

    @bill190.... Wow, two years. I am guessing you didn't use a propeller?
    That was a Zilog Z80 using the CP/M operating system. And you could only get printed documentation or books, no internet!

    ·
Sign In or Register to comment.