Learning ASM - Please help
Hi there,
I want to learn assembly so that I can use it in my propeller projects.
However whenever I look at other peoples code on the forums or in the object exchange all I see is random characters and such.
If people could answer the following questions that would be great.
Is there an easy way to learn?
How long did it take you to learn?
How did you learn?
Thank you![smile.gif](http://forums.parallax.com/images/smilies/smile.gif)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
I want to learn assembly so that I can use it in my propeller projects.
However whenever I look at other peoples code on the forums or in the object exchange all I see is random characters and such.
If people could answer the following questions that would be great.
Is there an easy way to learn?
How long did it take you to learn?
How did you learn?
Thank you
![smile.gif](http://forums.parallax.com/images/smilies/smile.gif)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Comments
I think that a lot of people think that assembly is a lot harder than it actually is. You just have to do everything yourself and do things one step at a time. For example in Spin
would translate to
However if you had
than you would need
So, in someways there is not a lot to learn if you can already program in spin. You just have to break everything down another level.
So if I do a Tafe course for assembly will I know enough to be able to program the propeller?
The Add command looks simple now that you have explained it so the rest will hopefully be just as simple.
How much faster is assembly compared to spin (in execution time)?
Several people have said that it runs faster than spin.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Most of the other commands are really just as simple.
Assembly is generally between 80 to 200 times faster than spin. There are some cases though. I think that there will be hardly any difference between doing a byte, word, or long fill in spin or assembly.
Maybe we should start a thread to try to get people started with assembler.
At the end of the day, fully commit to only one device as a beginner will pay off handsomely as you really need to learn the details of the chip to fully use assembly language. A simpler device, like the SX28 is easier than the AVRs or 8051s.
The Propeller is 32bit, not 8bit. So you will have to learn chip specific methods to exploit 8- bit devices attached to i/o.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PLEASE CONSIDER the following:
Do you want a quickly operational black box solution or the knowledge included therein?······
One nice thing about the Propeller is that almost all the instructions are identical in how they function up to the point where they compute something. The conditional execution bits are interpreted. If the condition is false, the whole instruction is otherwise ignored. The source operand and the destination operand are fetched. The operation code is interpreted to see what the hardware will do with the data. The result is optionally copied back to the destination and the flag bits (zero and carry). That's pretty much it.
Most instructions execute in 50ns. There are a few exceptions like the HUB instructions and unsuccessful conditional jumps. Depending on the particular Spin code involved, assembly is maybe 40 times faster.
you would use
You can probably start to see a pattern. The structure of all assembly instructions is
condition instruction destination,source effects
Condition-This specifies the conditions under which the instruction will be run. If you leave it blank than it will always run
Instruction-The actual instruction such as add or mov
Destination-For most instructions the position where the result is stored and one of the operands
Source-The other operand
Effects-Whether to write the z and c flags and whether to write the results. We can talk about these later
The propeller assembly is really nice and easy compared to other things.
I understand what you are saying.
Ah so
would call the function "receive" and then return to what it was doing.
would go to the function "update" and not return to the previous location.
is basically an if statement saying "If data == $FA"
Is this all correct?
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
There are two special flags in each cog called the z and c flag.
z stands for zero and is generally set when you get a zero result. This happens for instance when you do the cmp above. The cmp really is just
So, when this is done the result is not written but if the result comes out to be zero than the z flag will be set.
It can be used later like this
There are a whole heap of combinations like if_z, if_z_nz etc. that can be used. It is very handy and avoids jmps that are necessary in most other micros.
The details are (to be ignored if you wish):
1) The CALL actually is an instruction known as JMPRET (jump return) which stores the return address in the destination word's source field, then jumps to the source value (by copying the source to the program counter). CALL is a macro that adds the characters "_ret" to the instruction operand and uses that for the destination field.
2) CMP just sets the flags. You'd need a jump instruction too in order to make the equivalent of an IF statement.
So the line
Is where it says "The comparison is 'true' so jump to 'reset'"
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Than you may as well do
and you have save a couple of longs.
This is where assembler starts getting harder. Actually writing it is often not that hard. Coming back later and figuring out what it does can be more difficult. It is really important to make sure that anything you write in assembler is really well commented. Especially on the propeller where we often use self modifying code.
I will start reading up on some of the functions and looking at other code and seeing if I can understand what it is doing.
I will post if I have any problems.
Thank you all
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
IMO the easiest way to learn assembly is to find a compiler that produces assembly from a language that is easier to understand. That way, you can compare the Assembly result to what you already know and are familiar with. In time, it will eventually "click" and make sense. It also helps to read, and re-read the Assembly Operation codes. When I do this, I sometimes will find a way to use an instruction in a way that I might not of previously thought of.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I will definitely take those suggestions into consideration as I find ways of learning.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
General concepts of Assembly programming can be applied over several different programming platforms.· Once you grasp·basic Assembly concepts, excluding proprietary language features that can be picked up later by reading the provided documentation, other platforms are relatively easy to migrate toward.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 3/8/2008 6:22:19 AM GMT
That is also what I meant when I asked about a Tafe course.
What I was asking was could I do any assembly language Tafe course and then know enough to start programming the propeller.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Beau, I agree but from what I have seen the propeller has just about the easiest assembly compared to anything else. Anything else that I have seen (I haven't seen a lot though) is harder than the propeller.
I have almost converted the Clemens font to be used in the graphics driver. I'll post the code for that here as it has the original spin code and the assembly conversion.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
I used to do a lot of programming in plain x86 ... at times with nothing more than the MSDOS debug editor. I taught myself, for the most part, and visited the library a lot looking for books on the subject (<- before internet even existed.)
One book in particular that I still reference sometimes.... "PC Assembly language Step by Step" ...covers 8086, 8088, 80286, 80386, and 80486 instructions. ISBN 1-55755-096-4
One thing to keep in mind... you won't know how to program in assembly overnight. It took me several years, but I did it the hard way. Nowadays, the internet is available, and you could probably just Google the Assembly operation code you were trying to discover.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Your right it is tough, but it makes almost everything else (especially the Propeller) like cutting butter with a chainsaw.·· ...There are also other books out there that help make things easier... "The PC Programmer's Bible" written by Peter Norton was another must have in the early days·when I was learning Assembly.· (ISBN 1-55615-55-7)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 3/8/2008 7:00:53 AM GMT
I started to lern assembly on my brother's Sinclair ZX Spectrum('Speccy' to enthusiasts, Timex Sinclair something in the USA).
All you need with one of those is a manual, a TV, a notepad and a pot of tea...
A 6502-based computer may be easier to start with than a Z80-based one, though.
Or you may be able to track down a 'microprocessor trainer' on eBay.
(These are simple computers with a display - often just a few 7-segment LEDs - HEX keypad, possibly a few bits of I/O or interfaces, and a prototype area. )
Usually they have some sort of 'monitor' program in ROM, and sometimes they have single-step functions.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't visit my new website...
X86 could be one of the toughest to learn because of so much history and evolution. There are huge amounts of information available and you are likely to buried in all that stuff before you begin to get started. It is easy to get stuff for the distant cousin, the 8051, but even that has a lot of baggage to sort through - though if you want 4mb of RAM, some intances of it can support it.
But then you are going to have to learn a UNIX like files systems and so on and so on.
In sum, the PIC and the slicker speedier cousin, the SXes really often a solid entry. Take a look and www.sxlist.com and www.piclist.com for resources and examples. PICs can be a bit harder to sort through as there are dozens of varieties with different coding quirks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PLEASE CONSIDER the following:
Do you want a quickly operational black box solution or the knowledge included therein?······
With all the information provided I think I can get a start with Assembly.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker