Basic <-> Asm help required
magnet
Posts: 13
Hi from a total newbie.
I took the plunge and bought a DIP chip education pack to play around with. After draining several 9v batteries I found a regulated 7.5v 0.86VA mains adaptor in my "bits box" to use and am assuming this will be suitable to power my projects without damage for the future?
The first program I wrote, a port of a C program I have running on my main computer, failed despite "looking fine" to me... Lesson #1 learnt! Forget old habits.
Now to my request:
As there is no screen output from the chip circuit, I am using known data input values and results that trigger a row of LEDs to signal the code has performed correctly and has found the correct solution. However, as with all interpreted languages, speed is slower than this chip can deliver if coded using assembler, so to get me started can someone tell me if the following 2 bits of code do exactly the same thing please so I can start to get a grip on the syntax...
Some pointers to working assembler code would be appreciated.
Happy New Year
magnet
I took the plunge and bought a DIP chip education pack to play around with. After draining several 9v batteries I found a regulated 7.5v 0.86VA mains adaptor in my "bits box" to use and am assuming this will be suitable to power my projects without damage for the future?
The first program I wrote, a port of a C program I have running on my main computer, failed despite "looking fine" to me... Lesson #1 learnt! Forget old habits.
Now to my request:
As there is no screen output from the chip circuit, I am using known data input values and results that trigger a row of LEDs to signal the code has performed correctly and has found the correct solution. However, as with all interpreted languages, speed is slower than this chip can deliver if coded using assembler, so to get me started can someone tell me if the following 2 bits of code do exactly the same thing please so I can start to get a grip on the syntax...
{{spin code}} r001 += f101 carry := 0 if r001 > 999 carry := 0 r001 -= 1000
{{assembler ??}} DAT org 0 add_f adds r101,f101 movs carry,#0 cmps r101,#v999 wc if_a movs carry,#0 subs r101,#v1000 r101 long 1234 f101 long 5678 carry long 0 v999 long 999 v1000 long 1000
Some pointers to working assembler code would be appreciated.
Happy New Year
magnet
Comments
The labels referenced in assembler do not need the # (excet when they are destination of jm or call).
# is only used when the value you want is going to be used as literal.
Example:
add v1,v2
v1 long 3
v2 long 4
is the right form to add the contents of memory position v2 to v1
add v1,#123
is the right to add the constant 123 (decimal) to the contents of memory position v1.
This is extensively explained both in the propeller manual and in deSilva's assembler tutorial.
There is a wiki at propeller.wikispaces.com with loads of examples and useful information.
The sticky propeller programming tutorials is very well recommended too.
Rewrite your code removing the #s from where they are not needed and try again.
you can test assembler code with my propeller simulator at sourceforge.net/projects/pPropellerSim
Post Edited (Ale) : 1/1/2008 8:08:59 PM GMT
there is much more to say...
Don't use the opcodes with "S" until you understand what they do. In nearly all cases in your example it has to be
MOV
ADD
SUB
CMPS is o.k. however
But the last SUBS must be guarded by IF_A as well!
Your SPIN code is also unclear: Why do you set flag to zero twice? r001 could be set to zero, rather...
I should also recommend to read through my tutorial.... of course
---
Edit:
Wait, there is more:
(a) Of course you can operate your TV monitor using three resistors
(b) or you use one of the serial PC objects (Recommendation: PropTerm) to communicate with PC screen, keyboard and mouse
(c) or you use Ariba's PASD for debugging and steping through your machine code
Post Edited (deSilva) : 1/1/2008 9:43:38 PM GMT
I always assumed you have to use the S when signed variable values are important, especially as some of my values can go negative, but I see your point with just clearing the carry variable, it could just be a MOV used in that case.
Will read through the tutorial as any literature is most welcome. I have managed to get a small snippet of asm code to compile so this is a good step in the right direction.
Many thanks
magnet
deSilva: I have checked my input data over a wide range and can find no instant where adding any 2 numbers together will result in a value exceeding the 32bit max.value so in that case a simple MOV will be sufficient.
Thanks
Tried this code and it turns on the led fine but does not switch if off again after my delay. What have I done wrong this time please?
Many thanks
magnet.
(1) There is no loop, the activity after the last mux is undefined; in best case the COG will stop (but why?) and all I/O will idle as well.
(2) Why do you touch DIRA so often? Once per COG should be enough.
(3) There is rarely a need to use MUX, especially not as a beginner. It will not make you happy...
(4) But after the wait it will not change anything.. Do you wanted to use MUXZ ?
(5) The WAITCNT will stop any activity for 50 seconds, as it will wait for a tick just over. Read the description of WAITCNT please. What you want to do is:
There is a more advanced technique that uses also the src parameter of WAITCNT..
Post Edited (deSilva) : 1/3/2008 3:46:28 PM GMT