How to compare two pin inputs in PASM ???
Bean
Posts: 8,129
I'm experiencing brain fade...
I'm working on the PropBASIC compiler and here is what I have for "DO...LOOP WHILE P0 = P1".
P0 and P1 are LONGs that contain the bitmask of the pins (so P0 = 1, and P1 = 2).
It seems like a bunch of code to do something seemingly so simple.
Can anyone suggest some more effiecient code ?
Thanks,
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
Post Edited (Bean) : 3/30/2010 8:55:30 PM GMT
I'm working on the PropBASIC compiler and here is what I have for "DO...LOOP WHILE P0 = P1".
__DO_1 ' DO
or outa,P16 ' P16 = 1
mov __temp1,#0 ' LOOP WHILE P0 = P1
and P0,ina WZ, NR
IF_NZ adds __temp1,#1
and P1,ina WZ, NR
IF_NZ adds __temp1,#1
subs __temp1,#1
IF_NZ jmp #__DO_1
P0 and P1 are LONGs that contain the bitmask of the pins (so P0 = 1, and P1 = 2).
It seems like a bunch of code to do something seemingly so simple.
Can anyone suggest some more effiecient code ?
Thanks,
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
Post Edited (Bean) : 3/30/2010 8:55:30 PM GMT

Comments
I know this feeling...
mov temp1, ina mov temp2, temp1 shr temp2, #1 xor temp1, temp2 and temp1, #1Then you have 1 in temp1 if P0 <> P1 and 0 if P0 == P1.
Or another way, also 5 instructions:
test ina, #1 WZ test ina, #2 WC mov result, #0 if_nc_and_z mov result, #1 if_c_and_nz mov result, #1Hmm... there has to be a shorter way:
mov result, ina shr result, #1 WC if_c xor result, #1 and result, #1Aha! 4 instructions. I think this is the shortest.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
He died at the console of hunger and thirst.
Next day he was buried. Face down, nine edge first.
Post Edited (pullmoll) : 3/30/2010 3:10:13 PM GMT
__DO_1 ' DO or outa,P16 ' P16 = 1 and P0,ina WZ, NR and P1,ina WC, NR IF_C_EQ_Z jmp #__DO_1Nice... That's what I was looking for.
Thank you very much for posting it.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
·
Are P0 - P31 built in as predefinitions in PropBASIC? I know this has become a "standard" of sorts for naming the port pins, but Parallax has made a grave and regrettable mistake in promoting it at the expense of the original (and much better) A0 - A31. (It is port A, after all.) Could the latter be included, as well, as an alternate (or even the preferred) nomenclature?
-Phil
Pins are NOT predefined. I didn't include all the code (I know bad form).
They are define like:
So I guess you can use P0 or A0 whichever you like, but you DO need to explicitly define them.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
Post Edited (Bean) : 3/30/2010 8:55:06 PM GMT
?
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
Your method makes sense for hand-coding, but the PropBASIC compiler only generates masked for declared pins. To create a combined mask with what the compiler generates would eliminate the code savings of your method.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
Am I wrong, or shouldn't the last instruction be IF_C_NE_Z? When P0 is high (1) the Z flag will get zero; when P1 is high the C flag will be set. Likewise, when P0 is low the Z flag will be set; when P1 is low the C flag will be clear.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
· That is a good idea, but I don't have both pin masks available as a single value.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
Post Edited (Bean) : 3/30/2010 8:51:50 PM GMT
It's a single-pass compiler so it wouldn't know until it reached the code that it needed a compbined mask. Of course, Bean could adopt your strategy using internal variables:
__DO_1 or outa, P16 mov __temp1, P0 or __temp1, P1 test __temp1, ina wc if_nc jmp #__DO_1▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
Thanks. That makes sense: users can name them however they want. Looking forward, though, since there could be a port B or higher someday (esp. Prop II), I wonder if a single digit provides enough specificity to define which pin you're using. Might something like the following encompass future options better, or are you not concerned with that possibility right now?
-Phil
I figured I would handle the port "B" pins as 32 thru 63.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
Post Edited (Bean) : 3/30/2010 8:51:34 PM GMT
You're right, the Z flag is inverse to the bit. But my version can be used for LOOP UNTIL [noparse];)[/noparse]
Andy