Shop OBEX P1 Docs P2 Docs Learn Events
Assembly example — Parallax Forums

Assembly example

crcordillcrcordill Posts: 29
edited 2008-04-10 00:16 in Propeller 1
Hey guys. I'm trying to teach myself assembly, and I was having a problem finding examples that could help me. What I'm looking for is some code that uses an input from a button, and uses some if statements to figure something out, like time, or button etc... Does anybody have a piece of code like that, or know where I can get one thats done in ASM? I can do it in Spin no prob, but I need speed. THanks for your help guys.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-08 20:13
    There's a "sticky" thread called "Propeller Programming Tutorials, Object Exchange, Tricks and Traps " that should have what you want.
  • crcordillcrcordill Posts: 29
    edited 2008-04-08 20:26
    I've looked at those stickies extensively, and they're not quite what I want. Thanks though.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-08 21:07
    Those are pretty much what's available. If you want specific examples, you'll have to be equally specific about asking.
  • crcordillcrcordill Posts: 29
    edited 2008-04-08 21:23
    Ok, I'll write what I want in spin and then we'll see if we can make it in ASM. I understand how to make inputs and outputs, I'm kind of unclear on how to use the if statements in ASM. Also, I'm unclear on what the flags like wz and stuff do.

    dira[noparse][[/noparse]0..3]~~ 'Set pins 1-3 as outputs
    dira~ 'Set pin 4 as input

    repeat
    repeat while ina == 0 'do nothing until input is high
    t1 := cnt 'record time count
    repeat while ina == 1 'do nothing until input goes back to low
    t2 := cnt 'record time count to determine how long button was high
    if t2 - t1 <= 1000 'if button wasn't on for very long then leave LED's off
    outa[noparse][[/noparse]0..3] := %0000
    elseif t2-t1 <= 2000
    outa[noparse][[/noparse]0..3] := %1000
    else 'else the button was held for longer then 2000, then set all LED's to high
    outa[noparse][[/noparse]0..3] := %1111
  • hippyhippy Posts: 1,981
    edited 2008-04-09 00:36
    One doesn't have handy if-else or repeat constructs in assembler, they all have to be built from tests and jumps, or with conditional execution.

    For example, in PASM, your "repeat while ina == 0" could be implemented in a number of ways including ...

    :Loop     mov   tmp,INA
              cmp   tmp,#0 WZ
        IF_Z  jmp   #:Loop
    
    :Loop     mov   tmp,INA
              tjz   tmp,#:Loop
    
    :Loop     mov   tmp,INA WZ
        IF_Z  jmp   #:Loop
    
    :Loop     mov   INA,INA WZ, NR
        IF_Z  jmp   #:Loop
    
    
    



    The best course of action is to start simple, and build up an understanding and familiarity with Propeller Assembler.
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-04-09 09:11
    hello crcordill,

    the difference between SPIN and ASM is bigger than changing some details of the syntax.

    So if you look at the asm-examples with a focus "where is the little syntax-difference" ASM is hard to understand
    because there is NO little syntax-difference. Its a BIG difference.

    It will become much eaysier to start if you take simple ASM-examples and modify those examples
    WITHOUT having in mind "in SPIN it works this way"

    I want to add a little bit of explanation about the code above

    
    :Loop     [b]mov[/b]   tmp,[b]INA[/b]
              [b]cmp[/b]   tmp,#0 [b]WZ[/b]
        [b]IF_Z[/b]  [b]jmp[/b]   #:Loop
    
    
    



    command mov
    - copies the 32bitvalue of register INA to location tmp

    the command cmp
    - compares the value of tmp with zero
    - the additional WZ means: If the compare results in zero the Z-flag is set. If the compare results in something different then zero the Z-Flag is NOT set

    the jmp command jmp
    - has a condition IF_Z
    - ONLY if the Z-Flag is set the JMD-command is executed otherwise not


    So in assembler there is now DIRECT way of coding something IF variable == value execute the indented commands below

    And that's the main-difference between a highlevel language like SPIN and the low-level language assembler

    SPIN is called a high-level language because you can code really COMPLEX things with a few commands like a conditional loop repeat until ....

    Assembler is called low-level because the power of a single command is lower
    and more important:
    the commands are VERY close to the hardware

    the command MOV tmp,INA means copy value of source-RAM-adress INA to destination RAM-adress tmp
    set Z-Flag is a HARDWARE-FLAG inside the cog and therefore the lowest-level you can access

    the next level below is the complex circuitry of flip-flops built with transistors that were cerated by the manufacturing-process of the chip itself

    copying a value from one variable to another in SPIN means the SPIN-interpreter does all the details about RAM-adresses FOR YOU

    best regards

    Stefan
  • crcordillcrcordill Posts: 29
    edited 2008-04-10 00:16
    That last tidbit about the flag is very useful. I'll have to work on using them effectively. Thanks.
    Craig
Sign In or Register to comment.