Shop OBEX P1 Docs P2 Docs Learn Events
Learning ASM - Please help — Parallax Forums

Learning ASM - Please help

computer guycomputer guy Posts: 1,113
edited 2008-03-08 21:39 in General Discussion
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

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker

Comments

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-08 04:19
    computer guy said...
    Is there an easy way to learn?
    Find a good instructor. That is a bit hard for the propeller in Australia at the moment.
    said...
    How long did it take you to learn?
    A couple of months for the AVR that I started on but I started using C pretty quickly on that and dropped assembly. The assembly on the propeller is actually a lot easier as there no interrupts and other things that can be a pain in the neck.
    said...
    How did you learn?
    At a class in tafesmile.gif

    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
    x:=x+3
    


    would translate to
    add x,#3
    


    However if you had
    x:=x+3+4+y
    


    than you would need
    add x,#3
    add x,#4
    add x,y
    


    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.
  • computer guycomputer guy Posts: 1,113
    edited 2008-03-08 04:24
    Thanks Steven,

    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. smile.gif

    How much faster is assembly compared to spin (in execution time)?
    Several people have said that it runs faster than spin.

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-08 04:44
    As far as I know there is nowhere that offers a course on propeller assembly programming.

    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.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2008-03-08 04:45
    If you want to work with the SX-28 chip, Guenther's text is quite complete and you will get a lot of support from the Forum. The advantages of of learning with the Propeller is that the memory is flat [noparse][[/noparse]contiguious] and does not require learning how to move across page boundaries; also, you can put variable anywhere within the cog's available memory unlike the SXes that have seperate registers for variables and program memory.

    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?······
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-08 04:46
    Use a simulator like GEAR to try out the various instructions to see what they do.

    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.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-08 04:56
    Next instruction would be mov. Suppose you wanted to do this in spin
    x:=y
    


    you would use
    mov x,y
    



    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
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-08 05:02
    Kramer, Yeah, the AVRs are complicated 32 registers and some of them can't be accessed with all instructions. Then you have seperate SRAM and then all the periphals and their control registers. Then to actually access the SRAM you have to learn about the indirect addressing using the X,Y,and Z registers and interrupts and the list goes on and on. I haven't had much to do with other devices but the PIC chips look they are a bit easier. The SX chips don't look too bad but the addressing and paging could be a pain.

    The propeller assembly is really nice and easy compared to other things.
  • computer guycomputer guy Posts: 1,113
    edited 2008-03-08 05:09
    Thank you Steven. smile.gif
    I understand what you are saying.

    Ah so
    call    #receive
    
    


    would call the function "receive" and then return to what it was doing.

    jmp     #update
    
    


    would go to the function "update" and not return to the previous location.

    cmp     data,#$FA       wz
    
    


    is basically an if statement saying "If data == $FA"


    Is this all correct?

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-08 05:21
    Thats all right. On the last one the equivalent spin is more like
    if data ==$FA
      z=1
    


    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
    sub data,#$FA wz nr
    


    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
    if_z add x,y
    


    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-08 05:21
    Basically you're correct. There are some details should you actually write a program with these instructions, but they're details.

    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.
  • computer guycomputer guy Posts: 1,113
    edited 2008-03-08 05:25
    Mike,

    So the line
    if_nz           jmp     #reset
    
    


    Is where it says "The comparison is 'true' so jump to 'reset'"

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-08 05:33
    Thats right, but depending on how much code there is at reset and if it gets used by other things you could just put the code there instead of a jump to the code. For example, if all you had at reset was
    reset mov x,0
    


    Than you may as well do
    cmp     data,#$FA       wz
    if_nz mov x,0
    


    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.
  • computer guycomputer guy Posts: 1,113
    edited 2008-03-08 05:36
    Thanks Steven I think I am starting to get the idea now. smile.gif
    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 smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-03-08 05:54
    computer guy,

    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.
  • computer guycomputer guy Posts: 1,113
    edited 2008-03-08 05:56
    Thanks Beau,

    I will definitely take those suggestions into consideration as I find ways of learning.

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-08 06:00
    Beau, thats a nice idea but unfortunately there is nothing that does this for the propeller. Maybe the proposed spin compiler can have an option to do this.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-03-08 06:17
    stevenmess2004,

    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
  • computer guycomputer guy Posts: 1,113
    edited 2008-03-08 06:20
    Steven,

    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 smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-08 06:32
    computer guy, I'm sure you can, but you will also learn a lot of stuff that you don't need with the propeller. Its probably a bit late to start this semester but I don't know if you could do anything by self paced learning (CIT (canberra institute of technology, a fancy way of saying tafe that fools nobody and confusing everybody) has some but I don't think they do assembler like this) or an adult education class(again, it may be hard to find something in assembler). So, unfortunately you may have to wait until next semester. But do go and ask. In the meantime learn as much as you can from the manuals and the forumssmile.gif

    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.
  • computer guycomputer guy Posts: 1,113
    edited 2008-03-08 06:34
    Thanks Steven smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-03-08 06:38
    computer guy,

    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.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-08 06:44
    What is x86 like compared to the propeller? From what I have seen it can be pretty ugly. Maybe on the earlier computers it wasn't so bad but with all the extensions and different modes now it must be horrendous.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-03-08 06:48
    stevenmess2004,

    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
  • MikeKMikeK Posts: 118
    edited 2008-03-08 12:42
    x86 assembly on the early computers was ugly. The address space is segmented, you could only work with 8 bits at a time, and certain instructions only worked with certain registers. Personally, I wouldn't suggest that as an intro to assembly, especially if the Prop has a flat address space. On the other hand, there are a zillion tutorials on the 'net, and emulators as well.
  • GadgetmanGadgetman Posts: 2,436
    edited 2008-03-08 13:14
    Why not get hold of an old 8bit computer and mess around with?

    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...
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2008-03-08 14:28
    The beauty of the SXes and the Propeller are they have left all that uglyness of the x86 behind. As speed of the processors began to increase and everybody started to learn computers a lot of early stuff that was done in hardware [noparse][[/noparse]and the hardway] evolved into being feasible in software.

    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?······
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • computer guycomputer guy Posts: 1,113
    edited 2008-03-08 21:39
    Thank you all smile.gif

    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
Sign In or Register to comment.