Assembly example
crcordill
Posts: 29
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
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
For example, in PASM, your "repeat while ina == 0" could be implemented in a number of ways including ...
The best course of action is to start simple, and build up an understanding and familiarity with Propeller Assembler.
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
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
Craig