PASM code question
New at PASM. Need some help. I would like to pass 4 ascii characters (numbers) to a pasm obj and have them converted to binary and added together . So I thought I would start simple and just try to add some numbers and have the pasm obj return a value. See attached code.
Something is not quite right .
adder_test.spinadder.spin
Something is not quite right .
adder_test.spinadder.spin

Comments
I think it's not so much a problem of the PASM but of the SPIN-part
The first method of SPIN-program starts after booting the propeller.
If this first method is executed the cog is shutdown
this means
PUB summit is executed with zeros and thats all
method "start" and method "what" never execute
{{ this is adder July 29 2011 accepts 2 32 bit words and adds them }} CON VAR long cog long total long num1 long num2 Pub Main summit (10,5) start 'need some kind of feedback here to tell if the result is stored in total 'or a call of what to give back the sum PUB summit(no1,no2) num1 := no1 num2 := no2 PUB start cog := cognew(@init_asm, @total) +1 PUB what : cow cow := total DAT {{ Assembly language }} org 0 init_asm gohere mov p, par 'save the start address in p mov t1, par add t1, #4 'get the starting address of the params rdlong v1, t1 ' v1 is now first number add t1, #4 ' get second numbers address rdlong v2, t1 'v2 is added to first number add v1, v2 wrlong v1, p 'write v1 to p v1 res 1 v2 res 1 t1 res 1 p res 1So I would add Debug-output to PST.EXE with using FullDUplexSerial
to see what the program flow does
keep the questions coming
best regards
Stefan
If you just swap the submit() and start() method calls, then add a wait between the start and the what() call, it should work.
Could I change PUB summit(no1,no2,no3,no4) to PUB summit(no1,no2,no3,no4):cow
So then I would only make one call?
Billadder4.spinadder_test.spin
I have spent many long hours to get this far. If it weren't for you guys helping out I don't think
I could have found all the answers in the two propeller books I have. I will attach my latest.
Thank you for your support
Billadder5_test.spinadder5.spin
As you are working with PASM do you know PASD?
keep the questions coming
best regards
Stefan
1) The :loop label can be moved down a line to remove an unneeded instruction.
2) You don't need both the init_asm and gohere label, they are both the same address.
3) As your submit method executes, your PASM cog it already adding the existing values. A more appropriate way to do this might be to have the PASM code wait for a "submit" variable to be set, or the fourth variable to be a non-zero or non-negative-one.
4) In the same idea as the previous tip, returning a "done" flag would be worthwhile because, all you do it grab the total, as soon as you have set the values to add. I am surprised the timing works correctly. It seems the first run through of the submit method might actually return an incorrect result. This will be absolutely a necesity when you create longer PASM algorithms.
Something like this:
VAR long cog long total long done long num1 long num2 long num3 long num4 PUB start done := -1 ' mark as not ready cog := cognew(@init_asm, @done) +1 PUB summit(no1,no2,no3,no4): cow num1 := no1 num2 := no2 num3 := no3 num4 := no4 done := 0 repeat until (done) ' stay here until PASM completes its code. cow := total DAT {{ Assembly language }} ORG init_asm mov doneP, par 'save the start address in doen pointer mov p, doneP sub p, #4 ' get total location :loop rdlong nothing, doneP WZ ' read done pointer (use a nothing address because we don't care about the value) ' you could add a wait in here to save some power, but it will slow down the initiation IF_NZ jmp #:loop ' if not ready, keep waiting mov t1, par add t1, #4 'get the starting address of the params rdlong v1, t1 ' v1 is now first number add t1, #4 ' get second numbers address rdlong v2, t1 ' v2 is added to first number add v1, v2 add t1, #4 rdlong v2, t1 'get 3rd number add v1, v2 add t1, #4 rdlong v2, t1 'get 4th number add v1, v2 wrlong v1, p 'write v1 to p wrlong negone, doneP ' flag as done jmp #:loop negone LONG -1 v1 res v2 res t1 res p res doneP res nothing res FITyou are right. I have added more code, as my original goal was to have a PASM object to convert
4 octal digits to binary. and it does return a wrong answer the first time. I will try to make your
recommended changes and will post it here a little later... thanks again... this is all a great educational
adventure.
Bill
I'm think the octal to binary convert code is OK it was returning the right answer (on second call) before.
something not quite in the right place...?
Billadder8_test.spinadder8.spin edit... 10minutes later... I think I got it, have to add 4 to par since we stuck in "done"
and add 4 to the first number fetch.. now is working...