Assembly language for a beginner
Ravenkallen
Posts: 1,057
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.
Comments
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.
www.parallax.com/Resources/NutsVoltsColumns/TheSpinZone/tabid/781/Default.aspx
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
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!
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
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
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.
·
Is assembly language unniversal per say or is it chip specfifc?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
How can there be·nothing? Nothing is something!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Leon Heller
Amateur radio callsign: G1HSM
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!
·
You can look over the assembly language code that the compiler
generates. Bean made both a great compiler and a PASM learning
tool
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]
I work from 4PM till 2AM.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
How can there be·nothing? Nothing is something!
Sent this through my Moto Droid.
Good luck on your study. Write to you tomorrow.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
How can there be·nothing? Nothing is something!
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.
Keep asking questions!
Post Edited (kuroneko) : 5/20/2010 2:38:56 AM GMT
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.
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!
It took me two years of reading (and saving money to buy a pc) to get my first assembly program working...
·
@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
·